Skip to content

Instantly share code, notes, and snippets.

@NickWoodhams
Created December 13, 2012 20:35
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 NickWoodhams/4279570 to your computer and use it in GitHub Desktop.
Save NickWoodhams/4279570 to your computer and use it in GitHub Desktop.
Activate the Select2 Library on any webpage with this Javascript Bookmarklet
function loadJSInclude(scriptPath, callback)
{
var scriptNode = document.createElement('SCRIPT');
scriptNode.type = 'text/javascript';
scriptNode.src = scriptPath;
var headNode = document.getElementsByTagName('HEAD');
if (headNode[0] !== null)
headNode[0].appendChild(scriptNode);
if (callback !== null)
{
scriptNode.onreadystagechange = callback;
scriptNode.onload = callback;
}
}
(function(){
var v = "1.8.3";
if (window.jQuery === undefined || window.jQuery.fn.jquery < v) {
var done = false;
var script = document.createElement("script");
script.src = "https://ajax.googleapis.com/ajax/libs/jquery/" + v + "/jquery.min.js";
script.onload = script.onreadystatechange = function(){
if (!done && (!this.readyState || this.readyState == "loaded" || this.readyState == "complete")) {
done = true;
initiateSelect2();
}
};
document.getElementsByTagName("head")[0].appendChild(script);
} else {
initiateSelect2();
}
function initiateSelect2() {
$('<link rel="stylesheet" type="text/css" href="https://m3dia.us/public/select2ify/select2.css" >').appendTo("head");
loadJSInclude('https://m3dia.us/public/select2ify/select2.min.js', select2itToIt);
}
function select2itToIt() {
$('select').each(function(){
if ($(this).find('*').length > 10) {
//initiate select2 sequence
console.log($(this).attr('name'));
$(this).select2({
width: "element"
});
}
});
}
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment