Created
December 13, 2012 20:35
-
-
Save NickWoodhams/4279570 to your computer and use it in GitHub Desktop.
Activate the Select2 Library on any webpage with this Javascript Bookmarklet
This file contains 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
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