Created
April 8, 2016 19:36
-
-
Save AlexandreBonaventure/56444927ab43aed892711180bffd132d to your computer and use it in GitHub Desktop.
Hype loader component
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<script> | |
let $ = require('jquery') | |
module.exports= { | |
props: { | |
src: { | |
required: true, | |
}, | |
hypeDocument: { | |
twoWay: true | |
} | |
}, | |
methods: { | |
onLoad(hypeDocument) { | |
this.hypeDocument = hypeDocument | |
} | |
}, | |
directives: { | |
hype: { | |
params: ['loaded'], | |
update(value) { | |
let pattern = /.+\/(.+)_hype_generated_script\.js/gi | |
let exec = pattern.exec(value) | |
let id = exec && exec[1] | |
if(!id) { | |
console.warn('hype directive: id invalid') | |
return | |
} | |
$('<div/>').attr('id', `${id}_hype_container`).appendTo(this.el) | |
this.vm.$on('hook:attached', () => { | |
this._interval = setTimeout(() => { //HACK unexpected crashing from hype runtime | |
this._hype_script = $(`<script type='text/javascript', charset='utf-8', src='${value}'/>`).appendTo('body') | |
if (typeof this.params['loaded'] == 'function') this.params['loaded'].call(this.vm, HYPE.documents[id]) | |
}, 100) | |
}) | |
}, | |
unbind() { | |
clearTimeout(this._interval) | |
if(this._hype_script) this._hype_script.remove() | |
} | |
} | |
} | |
}; | |
</script> | |
<template lang="jade"> | |
div.hypedocument(style='margin:auto;position:relative;width:100%;height:100%;overflow:hidden;', v-hype="src", :loaded="onLoad", aria-live='polite') | |
//- script(type='text/javascript', charset='utf-8', src='/images/screenshot1/default_hype_generated_script.js?48280') | |
</template> | |
<style lang="scss"> | |
.hypedocument { | |
box-sizing: content-box!important; | |
* { | |
box-sizing: content-box!important; | |
} | |
} | |
</style> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment