From b5c203aa152b0d50c2777cd75317e36fc88b730d Mon Sep 17 00:00:00 2001 From: Timothy Warren Date: Thu, 23 Feb 2012 12:42:33 -0500 Subject: [PATCH] Miscellaneous cleanup / fixes --- docs/symbols/src/kis-js_src_core.js.html | 2 +- .../src/kis-js_src_modules_DOM.js.html | 568 +++++++++--------- .../src/kis-js_src_modules_event.js.html | 6 +- .../src/kis-js_src_modules_indexedDB.js.html | 118 ++-- kis-all.js | 32 +- kis-lite-dom-min.js | 26 +- kis-lite-dom.js | 26 +- kis-lite-min.js | 4 +- kis-lite.js | 14 +- kis-min.js | 8 +- src/core.js | 2 +- src/modules/DOM.js | 12 +- src/modules/event.js | 6 +- src/modules/indexedDB.js | 6 + src/polyfill.js | 6 +- tests/qunit/qunit.js | 59 +- tests/tests/dom.js | 6 +- 17 files changed, 478 insertions(+), 423 deletions(-) diff --git a/docs/symbols/src/kis-js_src_core.js.html b/docs/symbols/src/kis-js_src_core.js.html index 8a3ead3..d09107d 100755 --- a/docs/symbols/src/kis-js_src_core.js.html +++ b/docs/symbols/src/kis-js_src_core.js.html @@ -9,7 +9,7 @@ 2 Kis JS Keep It Simple JS Library 3 Copyright Timothy J. Warren 4 License Public Domain - 5 Version 0.5.0-pre + 5 Version 0.5.0 6 */ 7 (function (){ 8 diff --git a/docs/symbols/src/kis-js_src_modules_DOM.js.html b/docs/symbols/src/kis-js_src_modules_DOM.js.html index f3191b3..746887b 100755 --- a/docs/symbols/src/kis-js_src_modules_DOM.js.html +++ b/docs/symbols/src/kis-js_src_modules_DOM.js.html @@ -252,293 +252,297 @@ 245 return (typeof value !== "undefined") ? value : oldVal; 246 } 247 -248 function _toCamel(s) -249 { -250 return s.replace(/(\-[a-z])/g, function($1){ -251 return $1.toUpperCase().replace('-',''); -252 }); -253 } -254 -255 function _css(sel, prop, val) -256 { -257 var equi; -258 -259 //Camel-case -260 prop = _toCamel(prop); -261 -262 //Equivalent properties for 'special' browsers -263 equi = { -264 outerHeight: "offsetHeight", -265 outerWidth: "offsetWidth", -266 top: "posTop" -267 }; -268 -269 -270 //If you don't define a value, try returning the existing value -271 if(typeof val === "undefined" && sel.style[prop] !== "undefined") -272 { -273 return sel.style[prop]; -274 } -275 else if(typeof val === "undefined" && sel.style[equi[prop]] !== "undefined") +248 /** +249 * Change css property name to it's +250 * javascript camel case equivalent +251 */ +252 function _toCamel(s) +253 { +254 return s.replace(/(\-[a-z])/g, function($1){ +255 return $1.toUpperCase().replace('-',''); +256 }); +257 } +258 +259 function _css(sel, prop, val) +260 { +261 var equi; +262 +263 //Camel-case +264 prop = _toCamel(prop); +265 +266 //Equivalent properties for 'special' browsers +267 equi = { +268 outerHeight: "offsetHeight", +269 outerWidth: "offsetWidth", +270 top: "posTop" +271 }; +272 +273 +274 //If you don't define a value, try returning the existing value +275 if(typeof val === "undefined" && sel.style[prop] !== "undefined") 276 { -277 return sel.style[equi[prop]]; +277 return sel.style[prop]; 278 } -279 -280 //Let's try the easy way first -281 if(typeof sel.style[prop] !== "undefined") -282 { -283 sel.style[prop] = val; -284 -285 //Short circuit -286 return; -287 } -288 else if(sel.style[equi[prop]]) -289 { -290 sel.style[equi[prop]] = val; -291 return; -292 } -293 -294 //No matches? Well, lets log it for now -295 console.log("Property " + prop + " nor an equivalent seems to exist"); -296 } -297 -298 // -------------------------------------------------------------------------- -299 -300 /** -301 * DOM -302 * -303 * Dom manipulation module -304 * @namespace -305 * @memberOf $_ -306 * @name dom -307 */ -308 d = { -309 /** -310 * Adds a class to the element(s) specified by the current -311 * selector -312 * -313 * @name addClass -314 * @memberOf $_.dom -315 * @function -316 * @param string class -317 */ -318 addClass: function (c) -319 { -320 $_.each(function (e){ -321 e.classList.add(c); -322 }); -323 }, -324 /** -325 * Removes a class from the element(s) specified by the current -326 * selector -327 * -328 * @name removeClass -329 * @memberOf $_.dom -330 * @function -331 * @param string class -332 */ -333 removeClass: function (c) -334 { -335 $_.each(function (e){ -336 e.classList.remove(c); -337 }); -338 }, -339 /** -340 * Hides the element(s) specified by the current selector -341 * -342 * @name hide -343 * @memberOf $_.dom -344 * @function -345 */ -346 hide: function () -347 { -348 this.css('display', 'none'); -349 }, -350 /** -351 * Shows the element(s) specified by the current selector. -352 * if type is specified, the element will have it's style -353 * property set to "display:[your type]". If type is not -354 * specified, the element is set to "display:block". -355 * -356 * @name show -357 * @memberOf $_.dom -358 * @function -359 * @param [string] type -360 */ -361 show: function (type) -362 { -363 if (typeof type === "undefined") -364 { -365 type = "block"; -366 } -367 -368 this.css("display", type); -369 }, -370 /** -371 * Sets attributes on element(s) specified by the current -372 * selector, or, if name is not specified, returns the -373 * value of the attribute of the element specified by the -374 * current selector. -375 * -376 * @name attr -377 * @memberOf $_.dom -378 * @function -379 * @param string name -380 * @param [string] value -381 * @return string -382 * @type string -383 */ -384 attr: function (name, value) -385 { -386 var sel = this.el; -387 -388 //Make sure you don't try to get a bunch of elements -389 if (sel.length > 1 && typeof value === "undefined") -390 { -391 console.log(sel); -392 console.log("Must be a singular element"); -393 return; -394 } -395 else if (sel.length > 1 && typeof value !== "undefined") //You can set a bunch, though -396 { -397 $_.each(function (e){ -398 return _attr(e, name, value); -399 }); -400 } -401 else //Normal behavior -402 { -403 return _attr(sel, name, value); +279 else if(typeof val === "undefined" && sel.style[equi[prop]] !== "undefined") +280 { +281 return sel.style[equi[prop]]; +282 } +283 +284 //Let's try the easy way first +285 if(typeof sel.style[prop] !== "undefined") +286 { +287 sel.style[prop] = val; +288 +289 //Short circuit +290 return; +291 } +292 else if(sel.style[equi[prop]]) +293 { +294 sel.style[equi[prop]] = val; +295 return; +296 } +297 +298 //No matches? Well, lets log it for now +299 console.log("Property " + prop + " nor an equivalent seems to exist"); +300 } +301 +302 // -------------------------------------------------------------------------- +303 +304 /** +305 * DOM +306 * +307 * Dom manipulation module +308 * @namespace +309 * @memberOf $_ +310 * @name dom +311 */ +312 d = { +313 /** +314 * Adds a class to the element(s) specified by the current +315 * selector +316 * +317 * @name addClass +318 * @memberOf $_.dom +319 * @function +320 * @param string class +321 */ +322 addClass: function (c) +323 { +324 $_.each(function (e){ +325 e.classList.add(c); +326 }); +327 }, +328 /** +329 * Removes a class from the element(s) specified by the current +330 * selector +331 * +332 * @name removeClass +333 * @memberOf $_.dom +334 * @function +335 * @param string class +336 */ +337 removeClass: function (c) +338 { +339 $_.each(function (e){ +340 e.classList.remove(c); +341 }); +342 }, +343 /** +344 * Hides the element(s) specified by the current selector +345 * +346 * @name hide +347 * @memberOf $_.dom +348 * @function +349 */ +350 hide: function () +351 { +352 this.css('display', 'none'); +353 }, +354 /** +355 * Shows the element(s) specified by the current selector. +356 * if type is specified, the element will have it's style +357 * property set to "display:[your type]". If type is not +358 * specified, the element is set to "display:block". +359 * +360 * @name show +361 * @memberOf $_.dom +362 * @function +363 * @param [string] type +364 */ +365 show: function (type) +366 { +367 if (typeof type === "undefined") +368 { +369 type = "block"; +370 } +371 +372 this.css("display", type); +373 }, +374 /** +375 * Sets attributes on element(s) specified by the current +376 * selector, or, if name is not specified, returns the +377 * value of the attribute of the element specified by the +378 * current selector. +379 * +380 * @name attr +381 * @memberOf $_.dom +382 * @function +383 * @param string name +384 * @param [string] value +385 * @return string +386 * @type string +387 */ +388 attr: function (name, value) +389 { +390 var sel = this.el; +391 +392 //Make sure you don't try to get a bunch of elements +393 if (sel.length > 1 && typeof value === "undefined") +394 { +395 console.log(sel); +396 console.log("Must be a singular element"); +397 return; +398 } +399 else if (sel.length > 1 && typeof value !== "undefined") //You can set a bunch, though +400 { +401 $_.each(function (e){ +402 return _attr(e, name, value); +403 }); 404 } -405 }, -406 /** -407 * Sets or retrieves the text content of the element -408 * specified by the current selector. If a value is -409 * passed, it will set that value on the current element, -410 * otherwise it will return the value of the current element -411 * -412 * @name text -413 * @memberOf $_.dom -414 * @function -415 * @param [string] value -416 * @return string -417 * @type string -418 */ -419 text: function (value) -420 { -421 var oldValue, set, type, sel; -422 -423 sel = this.el; -424 -425 set = (typeof value !== "undefined") ? true : false; -426 -427 type = (typeof sel.innerText !== "undefined") -428 ? "innerText" -429 : (typeof sel.textContent !== "undefined") -430 ? "textContent" -431 : "innerHTML"; -432 -433 oldValue = sel[type]; -434 -435 if(set) -436 { -437 sel[type] = value; -438 return value; -439 } -440 else -441 { -442 return oldValue; +405 else //Normal behavior +406 { +407 return _attr(sel, name, value); +408 } +409 }, +410 /** +411 * Sets or retrieves the text content of the element +412 * specified by the current selector. If a value is +413 * passed, it will set that value on the current element, +414 * otherwise it will return the value of the current element +415 * +416 * @name text +417 * @memberOf $_.dom +418 * @function +419 * @param [string] value +420 * @return string +421 * @type string +422 */ +423 text: function (value) +424 { +425 var oldValue, set, type, sel; +426 +427 sel = this.el; +428 +429 set = (typeof value !== "undefined") ? true : false; +430 +431 type = (typeof sel.textContent !== "undefined") +432 ? "textContent" +433 : (typeof sel.innerText !== "undefined") +434 ? "innerText" +435 : "innerHTML"; +436 +437 oldValue = sel[type]; +438 +439 if(set) +440 { +441 sel[type] = value; +442 return value; 443 } -444 }, -445 /** -446 * Sets or retrieves a css property of the element -447 * specified by the current selector. If a value is -448 * passed, it will set that value on the current element, -449 * otherwise it will return the value of the css property -450 * on the current element -451 * -452 * @name css -453 * @memberOf $_.dom -454 * @function -455 * @param string property -456 * @param [string] value -457 * @return string -458 * @type string -459 */ -460 css: function (prop, val) -461 { -462 //Return the current value if a value is not set -463 if(typeof val === "undefined") -464 { -465 return _css(this.el, prop); -466 } -467 -468 $_.each(function (e){ -469 _css(e, prop, val); -470 }); -471 }, -472 /** -473 * Adds to the innerHTML of the current element, after the last child. -474 * -475 * @example $_("ul").dom.append("<li></li>") adds an li element to the end of the selected ul element -476 * @name append -477 * @memberOf $_.dom -478 * @function -479 * @param string htm -480 */ -481 append: function(htm) -482 { -483 if(typeof document.insertAdjacentHTML !== "undefined") -484 { -485 this.el.insertAdjacentHTML('beforeend', htm); -486 } -487 else +444 else +445 { +446 return oldValue; +447 } +448 }, +449 /** +450 * Sets or retrieves a css property of the element +451 * specified by the current selector. If a value is +452 * passed, it will set that value on the current element, +453 * otherwise it will return the value of the css property +454 * on the current element +455 * +456 * @name css +457 * @memberOf $_.dom +458 * @function +459 * @param string property +460 * @param [string] value +461 * @return string +462 * @type string +463 */ +464 css: function (prop, val) +465 { +466 //Return the current value if a value is not set +467 if(typeof val === "undefined") +468 { +469 return _css(this.el, prop); +470 } +471 +472 $_.each(function (e){ +473 _css(e, prop, val); +474 }); +475 }, +476 /** +477 * Adds to the innerHTML of the current element, after the last child. +478 * +479 * @example $_("ul").dom.append("<li></li>") adds an li element to the end of the selected ul element +480 * @name append +481 * @memberOf $_.dom +482 * @function +483 * @param string htm +484 */ +485 append: function(htm) +486 { +487 if(typeof document.insertAdjacentHTML !== "undefined") 488 { -489 this.el.innerHTML += htm; +489 this.el.insertAdjacentHTML('beforeend', htm); 490 } -491 }, -492 /** -493 * Adds to the innerHTML of the selected element, before the current children -494 * -495 * @name prepend -496 * @memberOf $_.dom -497 * @function -498 * @param string htm -499 */ -500 prepend: function(htm) -501 { -502 if(typeof document.insertAdjacentHTML !== "undefined") -503 { -504 this.el.insertAdjacentHTML('afterbegin', htm); -505 } -506 else +491 else +492 { +493 this.el.innerHTML += htm; +494 } +495 }, +496 /** +497 * Adds to the innerHTML of the selected element, before the current children +498 * +499 * @name prepend +500 * @memberOf $_.dom +501 * @function +502 * @param string htm +503 */ +504 prepend: function(htm) +505 { +506 if(typeof document.insertAdjacentHTML !== "undefined") 507 { -508 this.el.innerHTML = htm + this.el.innerHTML; +508 this.el.insertAdjacentHTML('afterbegin', htm); 509 } -510 }, -511 /** -512 * Sets or gets the innerHTML propery of the element(s) passed -513 * -514 * @name html -515 * @memberOf $_.dom -516 * @function -517 * @param [string] htm -518 * @return string -519 * @type string -520 */ -521 html: function(htm) -522 { -523 -524 if(typeof htm !== "undefined") -525 { -526 this.el.innerHTML = htm; -527 } -528 -529 //If the parameter is undefined, just return the current value -530 return this.el.innerHTML; -531 } -532 }; -533 -534 $_.ext('dom', d); -535 -536 }()); -537 \ No newline at end of file +510 else +511 { +512 this.el.innerHTML = htm + this.el.innerHTML; +513 } +514 }, +515 /** +516 * Sets or gets the innerHTML propery of the element(s) passed +517 * +518 * @name html +519 * @memberOf $_.dom +520 * @function +521 * @param [string] htm +522 * @return string +523 * @type string +524 */ +525 html: function(htm) +526 { +527 +528 if(typeof htm !== "undefined") +529 { +530 this.el.innerHTML = htm; +531 } +532 +533 //If the parameter is undefined, just return the current value +534 return this.el.innerHTML; +535 } +536 }; +537 +538 $_.ext('dom', d); +539 +540 }()); +541 \ No newline at end of file diff --git a/docs/symbols/src/kis-js_src_modules_event.js.html b/docs/symbols/src/kis-js_src_modules_event.js.html index bb47c5f..8b7dc90 100755 --- a/docs/symbols/src/kis-js_src_modules_event.js.html +++ b/docs/symbols/src/kis-js_src_modules_event.js.html @@ -64,7 +64,7 @@ 57 _remove(event, callback); // Make sure we don't have duplicate listeners 58 59 sel.attachEvent("on" + event, _listener); - 60 // Store our _listener so we can remove it later + 60 // Store our listener so we can remove it later 61 var expando = sel[kis_expando] = sel[kis_expando] || {}; 62 expando.listeners = expando.listeners || {}; 63 expando.listeners[event] = expando.listeners[event] || []; @@ -121,7 +121,7 @@ 114 } 115 116 // Multiple events? Run recursively! -117 if (!event.match(/^([\w\-]+)$/)) +117 if ( ! event.match(/^([\w\-]+)$/)) 118 { 119 event = event.split(" "); 120 @@ -157,7 +157,7 @@ 150 e = e || window.event; 151 152 // Get the live version of the target selector -153 t = $_.$(target); +153 t = $_.$(target, sel); 154 155 // Check each element to see if it matches the target 156 for(elem in t) diff --git a/docs/symbols/src/kis-js_src_modules_indexedDB.js.html b/docs/symbols/src/kis-js_src_modules_indexedDB.js.html index a92da9e..6a24d8d 100644 --- a/docs/symbols/src/kis-js_src_modules_indexedDB.js.html +++ b/docs/symbols/src/kis-js_src_modules_indexedDB.js.html @@ -13,60 +13,66 @@ 6 7 var db = window.indexedDB || window.webkitIndexedDB || window.mozIndexedDB || window.msIndexedDB, 8 indexedDB = {}; - 9 - 10 /** - 11 * Module for simplifying Indexed DB access - 12 * - 13 * @namespace - 14 * @name indexedDB - 15 * @memberOf $_ - 16 */ - 17 indexedDB = { - 18 current_db: null, - 19 /** - 20 * Connects to an indexedDB database - 21 * - 22 * @memberOf $_.indexedDB - 23 * @name connect - 24 * @function - 25 * @param string dbname - 26 * @param [int] version - 27 * @param [function] onupgradeneeded - 28 */ - 29 connect: function(dbname, version, onupgradeneeded) - 30 { - 31 var request = {}; - 32 - 33 version = version || 0; - 34 - 35 // Ask for permission to use db - 36 request = db.open(dbname, version); - 37 - 38 // Assign onupgradeneeded callback - 39 if(typeof onupgradeneeded !== "undefined") - 40 { - 41 request.onupgradeneeded = onupgradeneeded; - 42 } + 9 + 10 //Well, some browsers don't support it yet + 11 if(typeof db === "undefined") + 12 { + 13 return; + 14 } + 15 + 16 /** + 17 * Module for simplifying Indexed DB access + 18 * + 19 * @namespace + 20 * @name indexedDB + 21 * @memberOf $_ + 22 */ + 23 indexedDB = { + 24 current_db: null, + 25 /** + 26 * Connects to an indexedDB database + 27 * + 28 * @memberOf $_.indexedDB + 29 * @name connect + 30 * @function + 31 * @param string dbname + 32 * @param [int] version + 33 * @param [function] onupgradeneeded + 34 */ + 35 connect: function(dbname, version, onupgradeneeded) + 36 { + 37 var request = {}; + 38 + 39 version = version || 0; + 40 + 41 // Ask for permission to use db + 42 request = db.open(dbname, version); 43 - 44 /** - 45 * @private - 46 */ - 47 request.onerror = function(event) - 48 { - 49 console.log("IndexedDB disallowed."); - 50 }; - 51 - 52 /** - 53 * @private - 54 */ - 55 request.onsuccess = function(event) - 56 { - 57 // Connect to the specified db - 58 indexedDB.current_db = request.result; - 59 }; - 60 } - 61 }; - 62 - 63 $_.ext('indexedDB', indexedDB); - 64 - 65 }()); \ No newline at end of file + 44 // Assign onupgradeneeded callback + 45 if(typeof onupgradeneeded !== "undefined") + 46 { + 47 request.onupgradeneeded = onupgradeneeded; + 48 } + 49 + 50 /** + 51 * @private + 52 */ + 53 request.onerror = function(event) + 54 { + 55 console.log("IndexedDB disallowed."); + 56 }; + 57 + 58 /** + 59 * @private + 60 */ + 61 request.onsuccess = function(event) + 62 { + 63 // Connect to the specified db + 64 indexedDB.current_db = request.result; + 65 }; + 66 } + 67 }; + 68 + 69 $_.ext('indexedDB', indexedDB); + 70 + 71 }()); \ No newline at end of file diff --git a/kis-all.js b/kis-all.js index d03be6e..55dc98b 100755 --- a/kis-all.js +++ b/kis-all.js @@ -2,7 +2,7 @@ Kis JS Keep It Simple JS Library Copyright Timothy J. Warren License Public Domain - Version 0.5.0-pre + Version 0.5.0 */ (function (){ @@ -253,12 +253,12 @@ { Event.prototype.preventDefault = function() { - window.event.stop(); + window.event.returnValue = false; }, Event.prototype.stopPropagation = function() { - window.event.returnValue = false; - } + window.event.cancelBubble = true; + } } }()); @@ -512,6 +512,10 @@ if (typeof document !== "undefined" && !("classList" in document.createElement(" return (typeof value !== "undefined") ? value : oldVal; } + /** + * Change css property name to it's + * javascript camel case equivalent + */ function _toCamel(s) { return s.replace(/(\-[a-z])/g, function($1){ @@ -691,10 +695,10 @@ if (typeof document !== "undefined" && !("classList" in document.createElement(" set = (typeof value !== "undefined") ? true : false; - type = (typeof sel.innerText !== "undefined") - ? "innerText" - : (typeof sel.textContent !== "undefined") - ? "textContent" + type = (typeof sel.textContent !== "undefined") + ? "textContent" + : (typeof sel.innerText !== "undefined") + ? "innerText" : "innerHTML"; oldValue = sel[type]; @@ -976,7 +980,7 @@ if (typeof document !== "undefined" && !("classList" in document.createElement(" _remove(event, callback); // Make sure we don't have duplicate listeners sel.attachEvent("on" + event, _listener); - // Store our _listener so we can remove it later + // Store our listener so we can remove it later var expando = sel[kis_expando] = sel[kis_expando] || {}; expando.listeners = expando.listeners || {}; expando.listeners[event] = expando.listeners[event] || []; @@ -1033,7 +1037,7 @@ if (typeof document !== "undefined" && !("classList" in document.createElement(" } // Multiple events? Run recursively! - if (!event.match(/^([\w\-]+)$/)) + if ( ! event.match(/^([\w\-]+)$/)) { event = event.split(" "); @@ -1069,7 +1073,7 @@ if (typeof document !== "undefined" && !("classList" in document.createElement(" e = e || window.event; // Get the live version of the target selector - t = $_.$(target); + t = $_.$(target, sel); // Check each element to see if it matches the target for(elem in t) @@ -1184,6 +1188,12 @@ if (typeof document !== "undefined" && !("classList" in document.createElement(" var db = window.indexedDB || window.webkitIndexedDB || window.mozIndexedDB || window.msIndexedDB, indexedDB = {}; + + //Well, some browsers don't support it yet + if(typeof db === "undefined") + { + return; + } /** * Module for simplifying Indexed DB access diff --git a/kis-lite-dom-min.js b/kis-lite-dom-min.js index 61a16d5..301a396 100755 --- a/kis-lite-dom-min.js +++ b/kis-lite-dom-min.js @@ -2,7 +2,7 @@ Kis JS Keep It Simple JS Library Copyright Timothy J. Warren License Public Domain - Version 0.5.0-pre + Version 0.5.0 */ (function (){ @@ -253,12 +253,12 @@ { Event.prototype.preventDefault = function() { - window.event.stop(); + window.event.returnValue = false; }, Event.prototype.stopPropagation = function() { - window.event.returnValue = false; - } + window.event.cancelBubble = true; + } } }()); @@ -437,7 +437,7 @@ _remove(event, callback); // Make sure we don't have duplicate listeners sel.attachEvent("on" + event, _listener); - // Store our _listener so we can remove it later + // Store our listener so we can remove it later var expando = sel[kis_expando] = sel[kis_expando] || {}; expando.listeners = expando.listeners || {}; expando.listeners[event] = expando.listeners[event] || []; @@ -494,7 +494,7 @@ } // Multiple events? Run recursively! - if (!event.match(/^([\w\-]+)$/)) + if ( ! event.match(/^([\w\-]+)$/)) { event = event.split(" "); @@ -530,7 +530,7 @@ e = e || window.event; // Get the live version of the target selector - t = $_.$(target); + t = $_.$(target, sel); // Check each element to see if it matches the target for(elem in t) @@ -884,6 +884,10 @@ if (typeof document !== "undefined" && !("classList" in document.createElement(" return (typeof value !== "undefined") ? value : oldVal; } + /** + * Change css property name to it's + * javascript camel case equivalent + */ function _toCamel(s) { return s.replace(/(\-[a-z])/g, function($1){ @@ -1063,10 +1067,10 @@ if (typeof document !== "undefined" && !("classList" in document.createElement(" set = (typeof value !== "undefined") ? true : false; - type = (typeof sel.innerText !== "undefined") - ? "innerText" - : (typeof sel.textContent !== "undefined") - ? "textContent" + type = (typeof sel.textContent !== "undefined") + ? "textContent" + : (typeof sel.innerText !== "undefined") + ? "innerText" : "innerHTML"; oldValue = sel[type]; diff --git a/kis-lite-dom.js b/kis-lite-dom.js index 61a16d5..301a396 100755 --- a/kis-lite-dom.js +++ b/kis-lite-dom.js @@ -2,7 +2,7 @@ Kis JS Keep It Simple JS Library Copyright Timothy J. Warren License Public Domain - Version 0.5.0-pre + Version 0.5.0 */ (function (){ @@ -253,12 +253,12 @@ { Event.prototype.preventDefault = function() { - window.event.stop(); + window.event.returnValue = false; }, Event.prototype.stopPropagation = function() { - window.event.returnValue = false; - } + window.event.cancelBubble = true; + } } }()); @@ -437,7 +437,7 @@ _remove(event, callback); // Make sure we don't have duplicate listeners sel.attachEvent("on" + event, _listener); - // Store our _listener so we can remove it later + // Store our listener so we can remove it later var expando = sel[kis_expando] = sel[kis_expando] || {}; expando.listeners = expando.listeners || {}; expando.listeners[event] = expando.listeners[event] || []; @@ -494,7 +494,7 @@ } // Multiple events? Run recursively! - if (!event.match(/^([\w\-]+)$/)) + if ( ! event.match(/^([\w\-]+)$/)) { event = event.split(" "); @@ -530,7 +530,7 @@ e = e || window.event; // Get the live version of the target selector - t = $_.$(target); + t = $_.$(target, sel); // Check each element to see if it matches the target for(elem in t) @@ -884,6 +884,10 @@ if (typeof document !== "undefined" && !("classList" in document.createElement(" return (typeof value !== "undefined") ? value : oldVal; } + /** + * Change css property name to it's + * javascript camel case equivalent + */ function _toCamel(s) { return s.replace(/(\-[a-z])/g, function($1){ @@ -1063,10 +1067,10 @@ if (typeof document !== "undefined" && !("classList" in document.createElement(" set = (typeof value !== "undefined") ? true : false; - type = (typeof sel.innerText !== "undefined") - ? "innerText" - : (typeof sel.textContent !== "undefined") - ? "textContent" + type = (typeof sel.textContent !== "undefined") + ? "textContent" + : (typeof sel.innerText !== "undefined") + ? "innerText" : "innerHTML"; oldValue = sel[type]; diff --git a/kis-lite-min.js b/kis-lite-min.js index 3dddcaf..00ee746 100755 --- a/kis-lite-min.js +++ b/kis-lite-min.js @@ -1,9 +1,9 @@ (function(){if("undefined"!==typeof document.querySelector){var e,f,d,c;e=function(a){c="undefined"===typeof a?"undefined"!==typeof e.el?e.el:document.documentElement:"object"!==typeof a?f(a):a;e.prototype.el=c;var a=d(e),b;for(b in a)"object"===typeof a[b]&&(a[b].el=c);a.el=c;return a};f=function(a,b){var g;if("string"!=typeof a||"undefined"===typeof a)return a;g=null!=b&&1===b.nodeType?b:document;if(a.match(/^#([\w\-]+$)/))return document.getElementById(a.split("#")[1]);g=g.querySelectorAll(a); return 1===g.length?g[0]:g};d=function(a){var b;if("undefined"!==typeof a){if("undefined"!==typeof Object.create)return Object.create(a);b=typeof a;if(!("object"!==b&&"function"!==b))return b=function(){},b.prototype=a,new b}};e.ext=function(a,b){b.el=c;e[a]=b};e.ext("each",function(a){if("undefined"!==typeof c.length&&c!==window){var b=c.length;if(0!==b)for(var g,d=0;d\s+<"),a=a.replace(/>\s+\{/gim,">{"),a=a.replace(/\}\s+"; - expected = escapeInnerText(QUnit.jsDump.parse(expected)); - actual = escapeInnerText(QUnit.jsDump.parse(actual)); - var output = message + ''; - if (actual != expected) { - output += ''; - output += ''; - } + var output = message; if (!result) { + expected = escapeInnerText(QUnit.jsDump.parse(expected)); + actual = escapeInnerText(QUnit.jsDump.parse(actual)); + output += '
Expected:
' + expected + '
Result:
' + actual + '
Diff:
' + QUnit.diff(expected, actual) +'
'; + if (actual != expected) { + output += ''; + output += ''; + } var source = sourceFromStacktrace(); if (source) { details.source = source; output += ''; } + output += "
Expected:
' + expected + '
Result:
' + actual + '
Diff:
' + QUnit.diff(expected, actual) +'
Source:
' + escapeInnerText(source) + '
"; } - output += ""; runLoggingCallbacks( 'log', QUnit, details ); @@ -779,7 +792,7 @@ QUnit.load = function() { var main = id('qunit-fixture'); if ( main ) { - config.fixture = main.innerHTML; + config.fixture = main.cloneNode(true); } if (config.autostart) { @@ -890,7 +903,11 @@ function sourceFromStacktrace() { return e.stacktrace.split("\n")[6]; } else if (e.stack) { // Firefox, Chrome - return e.stack.split("\n")[4]; + var stack = e.stack.split("\n"); + if (/^error$/i.test(stack[0])) { + stack.shift(); + } + return stack[3]; } else if (e.sourceURL) { // Safari, PhantomJS // TODO sourceURL points at the 'throw new Error' line above, useless @@ -1369,9 +1386,9 @@ QUnit.jsDump = (function() { var ret = [ ]; QUnit.jsDump.up(); for ( var key in map ) { - var val = map[key]; + var val = map[key]; ret.push( QUnit.jsDump.parse(key,'key') + ': ' + QUnit.jsDump.parse(val, undefined, stack)); - } + } QUnit.jsDump.down(); return join( '{', ret, '}' ); }, @@ -1595,4 +1612,4 @@ QUnit.diff = (function() { }; })(); -})(this); +})(this); \ No newline at end of file diff --git a/tests/tests/dom.js b/tests/tests/dom.js index 9fadea8..55224b0 100755 --- a/tests/tests/dom.js +++ b/tests/tests/dom.js @@ -48,7 +48,7 @@ var text = (typeof ele.innerText !== "undefined") ? ele.innerText : ele.textContent; equal($test.el, $("article#r14"), "Selector property is correct"); - equal($test.dom.text(), text, "Getting text"); + equal($test.dom.text().trim(), text.trim(), "Getting text"); equal($test.dom.text(""), "", "Setting text"); }); @@ -100,7 +100,7 @@ $_("#r14 ul").dom.append('
  • This is a test item
  • '); - equal($('#r14').innerHTML, html, "Append adds a child to the end of the selected element"); + equal($('#r14').innerHTML.toLowerCase(), html.toLowerCase(), "Append adds a child to the end of the selected element"); }); test("prepend", function(){ @@ -111,7 +111,7 @@ $_("#r14 ul").dom.prepend('
  • Test2
  • '); - equal($('#r14').innerHTML, html, "Prepend adds a child to the beginning of the selected element"); + equal($('#r14').innerHTML.toLowerCase(), html.toLowerCase(), "Prepend adds a child to the beginning of the selected element"); //Clean up the html $_("#r14").dom.html("");