Last active
December 21, 2015 02:59
-
-
Save devyfriend/6238968 to your computer and use it in GitHub Desktop.
misc js function
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 timestampFromSeconds( s ) { | |
| hours = parseInt( s / 3600 ) % 24; | |
| minutes = parseInt( s / 60 ) % 60; | |
| seconds = s % 60; | |
| result = minutes+":"+(seconds < 10 ? "0" + seconds : seconds); | |
| return result; | |
| } | |
| function getFormValues( form ) { | |
| var values = {}; | |
| $(form+" input").each( function() { | |
| var t = $(this).attr("type"); | |
| var n = $(this).attr("name"); | |
| var d = $(this).attr("default"); | |
| var v = $(this).val(); | |
| if( t == 'checkbox' ) { | |
| v = $(this).is(':checked'); | |
| }else{ | |
| if( v === d ) { | |
| v = ""; | |
| } | |
| values[n] = v; | |
| } | |
| } ); | |
| return values; | |
| } | |
| function openWindow(url, width, height) { | |
| var top = screen.height / 2 - height / 2; | |
| var left = screen.width / 2 - width / 2; | |
| window.open(url, "window", "width="+width+",height="+height+",top="+top+",left="+left+",scrollbars=yes,status=yes"); | |
| } | |
| /** | |
| * Creates a style sheet on the fly and adds it to the global | |
| * style sheet space. | |
| */ | |
| function createStyle( selector, rule ) { | |
| var stylesheet = document.styleSheets[0]; | |
| if (stylesheet.insertRule) { | |
| stylesheet.insertRule(selector + rule, stylesheet.cssRules.length); | |
| } | |
| else | |
| if (stylesheet.addRule) { | |
| stylesheet.addRule(selector, rule, -1); | |
| } | |
| } | |
| if(!window.location.query) | |
| window.location.query = function(a){ | |
| var c = {}, b; | |
| if ("" != a) | |
| for (b in a = a.substring(1).split("&")) | |
| c[(b = a[b].split("="))[0]] = b[1]; | |
| return c | |
| }(window.location.search); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment