Skip to content

Instantly share code, notes, and snippets.

@darkyen
Created September 22, 2012 11:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save darkyen/3765934 to your computer and use it in GitHub Desktop.
Save darkyen/3765934 to your computer and use it in GitHub Desktop.
Refactoring
/* css_editor.js */
module.exports = function(element,css){
for(var key in css){
element.style[key] = css[key];
}
}
/* Your file.css*/
var qrcode = require( 'qrcode' );
var setCSS = require('./css_editor.js');
module.exports = function( channel, engine ) {
// Create a wrapper
var wrapper = document.createElement( 'div' );
// Add some style
setCSS(wrapper,{
background:'#E0ECF8',
position:'absolute',
top:'1px',
right:'1px',
zIndex:9999,
borderRadius:'15px 0px 15px 15px',
fontSize:'20px',
fontFamily:'Arial',
color:'#2E2E2E',
// For impress.js, or the wrapper won't be clickable
pointerEvents:'auto'
});
// Remove it when you click on it
wrapper.addEventListener( 'click', function() {
this.parentNode.removeChild( this );
}, false );
// Store the url
var url = 'http://remoteprez.margaine.com/prez.html?c=' + channel +
'&e=' + engine;
// Create a DOM element to show
var link = document.createElement( 'a' );
// Add some style
setCSS(link,{
display :'block',
margin:'15px',
color:'#333',
});
link.href = url;
link.textContent = 'Click here to control your presentation';
link.target = '_blank';
// Add it to the wrapper
wrapper.appendChild( link );
// Add the "OR"
var or = document.createElement( 'div' );
or.textContent = 'or scan this QRcode';
setCSS(or,{ margin:'5px',
textAlign:'center'
});
wrapper.appendChild( or );
// Now create the QRCode
var qr = qrcode( 10, 'M' );
qr.addData( url );
qr.make();
wrapper.innerHTML += qr.createImgTag( 3 );
var img = wrapper.querySelector( 'img' );
setCSS(img,{
margin:'20px auto',
display:'block'
});
// And a close button
var close = document.createElement( 'div' );
close.textContent = 'Close';
setCSS(close,{
margin:'5px',
textAlign:'center',
cursor:'pointer',
fontSize:'10px',
textDecoration:'underline'
});
wrapper.appendChild( close );
// And append it to the body
document.body.appendChild( wrapper );
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment