Skip to content

Instantly share code, notes, and snippets.

@elijahmanor
Last active December 13, 2015 17:48
Show Gist options
  • Save elijahmanor/4950582 to your computer and use it in GitHub Desktop.
Save elijahmanor/4950582 to your computer and use it in GitHub Desktop.
jQuery QRify Plugin
// BEGIN jquery.qrify.js
(function( $ ) {
$.fn.qrify = function( options ) {
options = $.extend( {}, $.fn.qrify.defaultOptions, options );
return this.each( function() {
var $anchor = $( this ),
source = "//chart.googleapis.com/chart?chs=" +
options.width + "x" + options.height +
"&cht=qr&chld=|0&chl=";
$( "<img />", {
src: source + encodeURIComponent( $anchor.attr( "href" ) ),
click: function() { alert( "SCAN ME!" ); }
}).insertAfter( $anchor );
});
};
$.fn.qrify.defaultOptions = { width: 150, height: 150 };
}( jQuery ));
// END jquery.qrify.js
// BEGIN main.js
$( function() {
// override the global defaults
$.fn.qrify.defaultOptions.width = 300;
$.fn.qrify.defaultOptions.height = 300;
// specific options to override defaults
$( "a" ).qrify({ width: 200, height: 200 });
});
// END main.js
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment