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 testInputType = (function(GOOD, BAD) { | |
| 'button checkbox color date datetime datetime-local email month number password radio range reset search submit tel text time url week'.replace(/\S+/g, function(typeName) { | |
| var input = document.createElement('input'); | |
| input.setAttribute('type', typeName); | |
| (input.type.toLowerCase() == typeName ? GOOD : BAD).push(typeName); | |
| }); | |
| return function(value) { | |
| return 'boolean' == typeof value ? (value ? GOOD : BAD).slice() : GOOD.includes(value.toLowerCase()); | |
| }; | |
| })([], []); |
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
| function fitInto(desiredWidth, desiredHeight, actualWidth, actualHeight) { | |
| var actualSlope = actualHeight / actualWidth; | |
| if (isFinite(actualSlope || '@')) { | |
| if (desiredHeight / desiredWidth > actualSlope) { | |
| desiredHeight = desiredWidth * actualSlope; | |
| } | |
| else { | |
| desiredWidth = desiredHeight / actualSlope; | |
| } | |
| } |
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
| function watermarkImage(elemImage, text) { | |
| // Create test image to get proper dimensions of the image. | |
| var testImage = new Image(); | |
| testImage.onload = function() { | |
| var h = testImage.height, w = testImage.width, img = new Image(); | |
| // Once the image with the SVG of the watermark is loaded... | |
| img.onload = function() { | |
| // Make canvas with image and watermark | |
| var canvas = Object.assign(document.createElement('canvas'), {width: w, height: h}); | |
| var ctx = canvas.getContext('2d'); |
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
| function sortFileNames(arr) { | |
| for (var a, t, b, v, result = [], l = arr.length, i = l; i--; ) { | |
| v = arr[i]; | |
| t = typeof v; | |
| result[i] = { b: b = t == 'number' || t == 'string', a: a = [], v: v }; | |
| if (b) { | |
| (v + '').replace(/(\d+)|\D+/g, function(m, isDigits) { | |
| a.push(isDigits ? parseInt(m, 10) : m); | |
| }); | |
| } |
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
| function selectText(e,r,s,d) { | |
| d = document; | |
| if (s = window.getSelection) { | |
| (r = d.createRange()).selectNode(e); | |
| (s = s()).removeAllRanges(); | |
| s.addRange(r); | |
| } | |
| else if (d.selection) { | |
| (r = d.body.createTextRange()).moveToElementText(e); | |
| r.select(); |
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
| img { | |
| filter: greyscale(100%); | |
| mix-blend-mode: multiply; | |
| } |
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 clonedWidget = (JSON.parse(JSON.stringify(originalWidget))); |
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
| function report() { | |
| document.getElementsByTagName('output')[0].innerHTML = 'screen.width:'+screen.width+'<br>screen.height:'+screen.height+'<br>window.innerWidth:'+window.innerWidth+'<br>window.innerHeight:'+window.innerHeight+'<br>window.outerWidth:'+window.outerWidth+'<br>window.outerHeight:'+window.outerHeight+'<br>document.documentElement.<br> clientWidth:'+document.documentElement.clientWidth+'<br>document.documentElement.<br> clientHeight:'+document.documentElement.clientHeight+'<br>window.devicePixelRatio:'+window.devicePixelRatio; } | |
| window.addEventListener('load', report, false); | |
| window.addEventListener('resize', report, false); | |
| window.addEventListener('orientationchange', report, false); | |
| window.addEventListener('deviceorientation', report, false); | |
| window.addEventListener('MozOrientation', report, false); |
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 system = navigator.appVersion; | |
| if (navigator.appVersion.indexOf("Mac") != -1 ) { | |
| OS = "Mac"; | |
| } else if (navigator.appVersion.indexOf("PowerPC") != -1 ) { | |
| OS = "Mac"; | |
| } else if (navigator.appVersion.indexOf("Win") != -1 ) { | |
| OS = "Win"; | |
| } else if (navigator.appVersion.indexOf("SunOS") != -1 ) { | |
| OS = "Solaris"; | |
| } else { |
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
| function checkBrowser() { // triggers on clicking the close button, Alt+F4 , File->Close | |
| if(window.event.clientX < 0 && window.event.clientY < 0) { | |
| window.open("somefile.html", "closewindow",'left=12000,top=1200,width=120,height=50'); | |
| } | |
| } |