Last active
December 17, 2024 17:46
-
-
Save hawkrives/ca662894ad7240194d80 to your computer and use it in GitHub Desktop.
Bookmarklet to turn <select>s into <select²>s
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
javascript:(function()%7Bvar%20select2%3D%7Bcss%3A%22https%3A%2F%2Fcdn.rawgit.com%2Fivaynberg%2Fselect2%2F8cc9d48d5881a5760178b5cd615c5174fbd98672%2Fselect2.css%22%2Cjs%3A%22https%3A%2F%2Fcdn.rawgit.com%2Fivaynberg%2Fselect2%2F8cc9d48d5881a5760178b5cd615c5174fbd98672%2Fselect2.min.js%22%7D%2CselectCssLoadedPromise%3Dnew%20Promise(function(a%2Cb)%7Bconsole.log(%22inside%20css%20promise%22)%2Cselect2.link%3Ddocument.createElement(%22link%22)%2Cselect2.link.onload%3Dfunction()%7Bconsole.log(%22select%20css%20loaded%22)%2Ca()%7D%2Cselect2.link.onerror%3Dfunction(a)%7Bconsole.log(%22select%20css%20errored%22%2Ca)%2Cb()%7D%2Cselect2.link.href%3Dselect2.css%2Cselect2.link.rel%3D%22stylesheet%22%2Cselect2.link.type%3D%22text%2Fcss%22%2Cdocument.body.appendChild(select2.link)%7D)%2CselectScriptLoadedPromise%3Dnew%20Promise(function(a%2Cb)%7Bconsole.log(%22inside%20js%20promise%22)%3Bvar%20c%3Ddocument.createElement(%22script%22)%3Bc.onload%3Dfunction()%7Bconsole.log(%22select%20js%20loaded%22)%2Ca()%7D%2Cc.onerror%3Dfunction(a)%7Bconsole.log(%22select%20js%20errored%22%2Ca)%2Cb()%7D%2Cc.src%3Dselect2.js%2Cdocument.body.appendChild(c)%7D)%3BPromise.all(%5BselectCssLoadedPromise%2CselectScriptLoadedPromise%5D).then(function()%7Bconsole.log(%22inside%20promise.all%22)%3Bvar%20a%3D%5B%5D.slice.call(document.querySelectorAll(%22select%22))%3Ba.forEach(function(a)%7BjQuery(a).select2(%7BdropdownAutoWidth%3A!0%7D)%7D)%7D)%7D)() |
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
var select2 = { | |
css: 'https://cdn.rawgit.com/ivaynberg/select2/8cc9d48d5881a5760178b5cd615c5174fbd98672/select2.css', | |
js: 'https://cdn.rawgit.com/ivaynberg/select2/8cc9d48d5881a5760178b5cd615c5174fbd98672/select2.min.js' | |
} | |
var selectCssLoadedPromise = new Promise(function(resolve, reject) { | |
console.log('inside css promise') | |
select2.link = document.createElement('link') | |
select2.link.onload = function() { | |
console.log('select css loaded') | |
resolve() | |
} | |
select2.link.onerror = function(err) { | |
console.log('select css errored', err) | |
reject() | |
} | |
select2.link.href = select2.css | |
select2.link.rel = 'stylesheet' | |
select2.link.type = 'text/css' | |
document.body.appendChild(select2.link) | |
}) | |
var selectScriptLoadedPromise = new Promise(function(resolve, reject) { | |
console.log('inside js promise') | |
var select2script = document.createElement('script') | |
select2script.onload = function() { | |
console.log('select js loaded') | |
resolve() | |
} | |
select2script.onerror = function(err) { | |
console.log('select js errored', err) | |
reject() | |
} | |
select2script.src = select2.js | |
document.body.appendChild(select2script) | |
}) | |
Promise.all([selectCssLoadedPromise, selectScriptLoadedPromise]).then(function() { | |
console.log('inside promise.all') | |
var selects = [].slice.call(document.querySelectorAll('select')) | |
selects.forEach(function(el) { | |
jQuery(el).select2({dropdownAutoWidth: true}) | |
}) | |
}) |
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
var select2={css:"https://cdn.rawgit.com/ivaynberg/select2/8cc9d48d5881a5760178b5cd615c5174fbd98672/select2.css",js:"https://cdn.rawgit.com/ivaynberg/select2/8cc9d48d5881a5760178b5cd615c5174fbd98672/select2.min.js"},selectCssLoadedPromise=new Promise(function(a,b){console.log("inside css promise"),select2.link=document.createElement("link"),select2.link.onload=function(){console.log("select css loaded"),a()},select2.link.onerror=function(a){console.log("select css errored",a),b()},select2.link.href=select2.css,select2.link.rel="stylesheet",select2.link.type="text/css",document.body.appendChild(select2.link)}),selectScriptLoadedPromise=new Promise(function(a,b){console.log("inside js promise");var c=document.createElement("script");c.onload=function(){console.log("select js loaded"),a()},c.onerror=function(a){console.log("select js errored",a),b()},c.src=select2.js,document.body.appendChild(c)});Promise.all([selectCssLoadedPromise,selectScriptLoadedPromise]).then(function(){console.log("inside promise.all");var a=[].slice.call(document.querySelectorAll("select"));a.forEach(function(a){jQuery(a).select2({dropdownAutoWidth:!0})})}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hello! I recently used http://hirepaperwriters.com/ and was satisfied with the service. The platform provides a variety of academic writing options, and the ordering process was simple and quick. The article is written on time and without plagiarism. The author quickly responded to my wishes and corrections, and the result turned out exactly as I wanted. The prices are reasonable, especially for students, and the customer service was responsive and helpful. In general, I recommend it to everyone, because you can make the learning process easier for yourself.