JQuery – Alternatives and Drop-In Replacement of jQuery JavaScript Library
The following small javascript libraries can be used instead of and as drop-in replacements ... Read more
1 2 3 4 5 6 |
public static String getStackTrace(Throwable e){ StringWriter sw = new StringWriter(); e.printStackTrace(new PrintWriter(sw)); String stacktrace = sw.toString(); return stacktrace; } |
1 2 3 4 5 6 7 8 9 |
function el(elementId){ var elementObject = null; try{ elementObject = document.all ? document.all[elementId] : document.getElementById(elementId); }catch(e){ // nothing to do } return elementObject; } |
1 2 3 4 |
function trim(str) { return str.replace(/^\s*|\s*$/g,""); } |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
<script language="JavaScript"> function isArray(a) { return isObject(a) && a.constructor == Array; } function isBoolean(a) { return typeof a == 'boolean'; } function isEmpty(o) { var i, v; if (isObject(o)) { for (i in o) { v = o[i]; if (isUndefined(v) && isFunction(v)) { return false; } } } return true; } function isFunction(a) { return typeof a == 'function'; } function isNull(a) { return typeof a == 'object' && !a; } function isNumber(a) { return typeof a == 'number' && isFinite(a); } function isObject(a) { return (a && typeof a == 'object') || isFunction(a); } function isString(a) { return typeof a == 'string'; } function isUndefined(a) { return typeof a == 'undefined'; } </script> |
1 2 3 4 5 6 7 8 9 10 11 |
<script language="JavaScript"> function file_extension(filepath){ try{ return filepath.slice(filepath.lastIndexOf(".")+1).toLowerCase(); }catch(e){ // log at will :) } } </script> |
1 2 3 4 5 6 7 8 9 10 |
<script type="text/javascript" src="hashtable.js"></script> <script language="JavaScript"> var hashmap = new Hashtable(); hashmap.setItem("key1","value1"); hashmap.setItem("key2","value2"); hashmap.removeItem("key1"); hashmap.hasItem("key1"); </script> |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 |
<script language="JavaScript"> /******************************************************************************************* * Object: Hashtable * Description: Implementation of hashtable * Author: Uzi Refaeli *******************************************************************************************/ //======================================= Properties ======================================== Hashtable.prototype.hash = null; Hashtable.prototype.keys = null; Hashtable.prototype.location = null; /** * Hashtable - Constructor * Create a new Hashtable object. */ function Hashtable(){ this.hash = new Array(); this.keys = new Array(); this.location = 0; } /** * put * Add new key * param: key - String, key name * param: value - Object, the object to insert */ Hashtable.prototype.put = function (key, value){ if (value == null) return; if (this.hash[key] == null) this.keys[this.keys.length] = key; this.hash[key] = value; } /** * get * Return an element * param: key - String, key name * Return: object - The requested object */ Hashtable.prototype.get = function (key){ return this.hash[key]; } /** * remove * Remove an element * param: key - String, key name */ Hashtable.prototype.remove = function (key){ for (var i = 0; i < this.keys.length; i++){ //did we found our key? if (key == this.keys[i]){ //remove it from the hash this.hash[this.keys[i]] = null; //and throw away the key... this.keys.splice(i ,1); return; } } } /** * size * Return: Number of elements in the hashtable */ Hashtable.prototype.size = function (){ return this.keys.length; } /** * populateItems * Deprecated */ Hashtable.prototype.populateItems = function (){} /** * next * Return: true if theres more items */ Hashtable.prototype.next = function (){ if (++this.location < this.keys.length) return true; else return false; } /** * moveFirst * Move to the first item. */ Hashtable.prototype.moveFirst = function (){ try { this.location = -1; } catch(e) {/*//do nothing here :-)*/} } /** * moveLast * Move to the last item. */ Hashtable.prototype.moveLast = function (){ try { this.location = this.keys.length - 1; } catch(e) {/*//do nothing here :-)*/} } /** * getKey * Return: The value of item in the hash */ Hashtable.prototype.getKey = function (){ try { return this.keys[this.location]; } catch(e) { return null; } } /** * getValue * Return: The value of item in the hash */ Hashtable.prototype.getValue = function (){ try { return this.hash[this.keys[this.location]]; } catch(e) { return null; } } /** * getKey * Return: The first key contains the given value, or null if not found */ Hashtable.prototype.getKeyOfValue = function (value){ for (var i = 0; i < this.keys.length; i++) if (this.hash[this.keys[i]] == value) return this.keys[i] return null; } /** * toString * Returns a string representation of this Hashtable object in the form of a set of entries, * enclosed in braces and separated by the ASCII characters ", " (comma and space). * Each entry is rendered as the key, an equals sign =, and the associated element, * where the toString method is used to convert the key and element to strings. * Return: a string representation of this hashtable. */ Hashtable.prototype.toString = function (){ try { var s = new Array(this.keys.length); s[s.length] = "{"; for (var i = 0; i < this.keys.length; i++){ s[s.length] = this.keys[i]; s[s.length] = "="; var v = this.hash[this.keys[i]]; if (v) s[s.length] = v.toString(); else s[s.length] = "null"; if (i != this.keys.length-1) s[s.length] = ", "; } } catch(e) { //do nothing here :-) }finally{ s[s.length] = "}"; } return s.join(""); } /** * add * Concatanates hashtable to another hashtable. */ Hashtable.prototype.add = function(ht){ try { ht.moveFirst(); while(ht.next()){ var key = ht.getKey(); //put the new value in both cases (exists or not). this.hash[key] = ht.getValue(); //but if it is a new key also increase the key set if (this.get(key) != null){ this.keys[this.keys.length] = key; } } } catch(e) { //do nothing here :-) } finally { return this; } }; </script> |
1 |
Link: <a href="http://www.google.com" style="text-decoration: none; color: red">This Link to Google is Red</a> |
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 |
<script language="javascript"> /* * (c)2006 Dean Edwards/Matthias Miller/John Resig * Special thanks to Dan Webb's domready.js Prototype extension * and Simon Willison's addLoadEvent * * For more info, see: * http://dean.edwards.name/weblog/2006/06/again/ * http://www.vivabit.com/bollocks/2006/06/21/a-dom-ready-extension-for-prototype * http://simon.incutio.com/archive/2004/05/26/addLoadEvent * * Thrown together by Jesse Skinner (http://www.thefutureoftheweb.com/) * * * To use: call addDOMLoadEvent one or more times with functions, ie: * * function something() { * // do something * } * addDOMLoadEvent(something); * * addDOMLoadEvent(function() { * // do other stuff * }); * */ function addDOMLoadEvent(func) { if (!window.__load_events) { var init = function () { // quit if this function has already been called if (arguments.callee.done) return; // flag this function so we don't do the same thing twice arguments.callee.done = true; // kill the timer if (window.__load_timer) { clearInterval(window.__load_timer); window.__load_timer = null; } // execute each function in the stack in the order they were added for (var i=0;i < window.__load_events.length;i++) { window.__load_events[i](); } window.__load_events = null; }; // for Mozilla/Opera9 if (document.addEventListener) { document.addEventListener("DOMContentLoaded", init, false); } // for Internet Explorer /*@cc_on @*/ /*@if (@_win32) document.write("<scr"+"ipt id=__ie_onload defer src=javascript:void(0)><\/scr"+"ipt>"); var script = document.getElementById("__ie_onload"); script.onreadystatechange = function() { if (this.readyState == "complete") { init(); // call the onload handler } }; /*@end @*/ // for Safari if (/WebKit/i.test(navigator.userAgent)) { // sniff window.__load_timer = setInterval(function() { if (/loaded|complete/.test(document.readyState)) { init(); // call the onload handler } }, 10); } // for other browsers window.onload = init; // create event function stack window.__load_events = []; } // add function to event stack window.__load_events.push(func); } </script> |
1 |
document.title |
1 |
<a href="#" onClick="document.title='New Page Title After Mouse Click'; return false;">Click Here To Change Page Title</a> |
Code:
1 2 3 4 5 6 7 8 9 |
<script language="javascript"> function import_js(filepath){ var str = "<script src='"+filepath+"'><\/script>"; // remove alert after testing alert("importing JavaScript file: '"+filepath+"', import string:'"+str+"'"); document.write(str); } </script> |
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 |
<script language="JavaScript" type="text/javascript"> function hideElement(elementId) { getElementById(elementId).style.display = "none"; } function showElement(elementId) { getElementById(elementId).style.display = ""; } function getElementById(elementName){ var myElement = document.all ? document.all[elementName] : document.getElementById(elementName); return myElement; } </script> |
1 2 3 4 5 6 |
<script type="text/javascript"> alert("Here are you screen settings! screen.width='"+screen.width+"', "+screen.height='"+screen.height+ "', screen.colorDepth='"+screen.colorDepth+"', screen.pixelDepth='"+screen.pixelDepth+"'. "); </script> |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
<script language="JavaScript"> function Hashtable() { this.length = 0; this.items = new Array(); for (var i = 0; i < arguments.length; i += 2) { if (typeof(arguments[i + 1]) != 'undefined') { this.items[arguments[i]] = arguments[i + 1]; this.length++; } } this.removeItem = function(in_key) { var tmp_value; if (typeof(this.items[in_key]) != 'undefined') { this.length--; var tmp_value = this.items[in_key]; delete this.items[in_key]; } return tmp_value; } this.getLength = function() { return this.length; } this.getItem = function(in_key) { return this.items[in_key]; } this.setItem = function(in_key, in_value) { if (typeof(in_value) != 'undefined') { if (typeof(this.items[in_key]) == 'undefined') { this.length++; } this.items[in_key] = in_value; } return in_value; } this.hasItem = function(in_key) { return typeof(this.items[in_key]) != 'undefined'; } } </script> |
1 2 3 4 5 6 7 8 9 |
<script language="JavaScript"> var hashmap = new Hashtable(); hashmap.setItem("key1","value1"); hashmap.setItem("key2","value2"); hashmap.removeItem("key1"); hashmap.hasItem("key1"); </script> |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
<script type="text/javascript"> /* ************************************************************************ * Source: http://simon.incutio.com/archive/2004/05/26/addLoadEvent * ************************************************************************ */ function addLoadEvent(func) { var old_onload = window.onload; if (typeof window.onload != 'function') { window.onload = func; } else { window.onload = function() { if (old_onload) { old_onload(); } func(); }; } } //************************************************************************ /**/ // Examples function hello1(){alert("hello 1");} function hello2(){ alert("hello 2");} addLoadEvent(hello2); addLoadEvent(hello1); </script> |