Skip to content

Commit

Permalink
bugfix
Browse files Browse the repository at this point in the history
  • Loading branch information
Bruno Paolillo committed Oct 7, 2020
1 parent 5c8eb12 commit c21f6a3
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ Import the file into your vue app entry point to register a global directive or
```
import Vue from 'vue';
import App from './App';
import Xframe from 'vue-xframe';
import { xframe } from 'vue-xframe';
//Global directive registration
Vue.directive('xframe', xframe);
Expand All @@ -24,7 +24,7 @@ new Vue({
//Local directive registration
directives: {
Xframe
xframe
}
```
Expand Down
8 changes: 5 additions & 3 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,14 @@
import Vue from 'vue';

export const xframe = {
bind(el, binding, vnode) {
let url = binding.value;
if( url && url.startsWith('https://www') ) {
update(el, binding, vnode) {
const url = binding.value;
const pattern = new RegExp(/(https?:\/\/)?[\w\-~]+(\.[\w\-~]+)+(\/[\w\-~]*)*(#[\w\-]*)?(\?.*)?/);
if( pattern.test(url) ) {
fetch(`https://cors-anywhere.herokuapp.com/${url}`)
.then( (res) => res.text() )
.then( (data) => {
console.log(data);
let iframeContent = data.replace(/<head([^>]*)>/i, `<head$1>
<base href="${url}">
<script>
Expand Down

0 comments on commit c21f6a3

Please sign in to comment.