2011-08-09 06:45:24 +02:00
|
|
|
/*
|
|
|
|
Function: $defined
|
|
|
|
Returns true if the passed in value/object is defined, that means is not null or undefined.
|
|
|
|
|
|
|
|
Arguments:
|
|
|
|
obj - object to inspect
|
|
|
|
*/
|
|
|
|
|
2012-08-15 04:55:13 +02:00
|
|
|
$defined = function (obj) {
|
2011-08-09 06:45:24 +02:00
|
|
|
return (obj != undefined);
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2012-08-15 04:55:13 +02:00
|
|
|
$assert = function (assert, message) {
|
2011-08-09 06:45:24 +02:00
|
|
|
if (!$defined(assert) || !assert) {
|
|
|
|
var stack;
|
|
|
|
try {
|
|
|
|
null.eval();
|
2012-08-15 04:55:13 +02:00
|
|
|
} catch (e) {
|
2011-08-09 06:45:24 +02:00
|
|
|
stack = e;
|
|
|
|
}
|
2011-08-23 19:25:49 +02:00
|
|
|
console.log(message + "," + stack);
|
2012-06-23 19:39:50 +02:00
|
|
|
window.errorStack = stackTrace();
|
2011-08-24 01:56:01 +02:00
|
|
|
throw message;
|
2011-08-09 06:45:24 +02:00
|
|
|
}
|
2012-05-27 23:15:46 +02:00
|
|
|
};
|
|
|
|
|
2012-08-15 04:55:13 +02:00
|
|
|
Math.sign = function (value) {
|
2012-05-27 23:15:46 +02:00
|
|
|
return (value >= 0) ? 1 : -1;
|
|
|
|
};
|
|
|
|
|
2012-06-23 19:39:50 +02:00
|
|
|
function stackTrace() {
|
|
|
|
var result = "";
|
|
|
|
var isCallstackPopulated = false;
|
|
|
|
try {
|
|
|
|
null.eval();
|
2012-08-15 04:55:13 +02:00
|
|
|
} catch (e) {
|
2012-06-23 19:39:50 +02:00
|
|
|
if (e.stack) { //Firefox and Chrome...
|
|
|
|
result = e.stack;
|
|
|
|
isCallstackPopulated = true;
|
|
|
|
}
|
|
|
|
else if (window.opera && e.message) { //Opera
|
|
|
|
result = e.message;
|
|
|
|
isCallstackPopulated = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-05-27 23:15:46 +02:00
|
|
|
/*
|
|
|
|
* DOMParser HTML extension
|
|
|
|
* 2012-02-02
|
|
|
|
*
|
|
|
|
* By Eli Grey, http://eligrey.com
|
|
|
|
* Public domain.
|
|
|
|
* NO WARRANTY EXPRESSED OR IMPLIED. USE AT YOUR OWN RISK.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*! @source https://gist.github.com/1129031 */
|
|
|
|
/*global document, DOMParser*/
|
|
|
|
|
2012-08-15 04:55:13 +02:00
|
|
|
(function (DOMParser) {
|
2012-05-27 23:15:46 +02:00
|
|
|
"use strict";
|
|
|
|
|
|
|
|
var DOMParser_proto = DOMParser.prototype , real_parseFromString = DOMParser_proto.parseFromString;
|
|
|
|
|
|
|
|
// Firefox/Opera/IE throw errors on unsupported types
|
|
|
|
try {
|
|
|
|
// WebKit returns null on unsupported types
|
|
|
|
if ((new DOMParser).parseFromString("", "text/html")) {
|
|
|
|
// text/html parsing is natively supported
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
} catch (ex) {
|
|
|
|
}
|
|
|
|
|
2012-08-15 04:55:13 +02:00
|
|
|
DOMParser_proto.parseFromString = function (markup, type) {
|
2012-05-27 23:15:46 +02:00
|
|
|
if (/^\s*text\/html\s*(?:;|$)/i.test(type)) {
|
|
|
|
var
|
|
|
|
doc = document.implementation.createHTMLDocument("")
|
|
|
|
, doc_elt = doc.documentElement
|
|
|
|
, first_elt
|
|
|
|
;
|
|
|
|
|
|
|
|
doc_elt.innerHTML = markup;
|
|
|
|
first_elt = doc_elt.firstElementChild;
|
|
|
|
|
|
|
|
if (// are we dealing with an entire document or a fragment?
|
|
|
|
doc_elt.childElementCount === 1
|
|
|
|
&& first_elt.localName.toLowerCase() === "html"
|
|
|
|
) {
|
|
|
|
doc.replaceChild(first_elt, doc_elt);
|
|
|
|
}
|
|
|
|
|
|
|
|
return doc;
|
|
|
|
} else {
|
|
|
|
return real_parseFromString.apply(this, arguments);
|
|
|
|
}
|
|
|
|
};
|
2012-07-21 14:46:21 +02:00
|
|
|
}(DOMParser));
|
|
|
|
|
|
|
|
// Support for Windows ...
|
2012-08-15 04:55:13 +02:00
|
|
|
if (!window.console) {
|
2012-07-21 14:46:21 +02:00
|
|
|
console = {
|
2012-08-15 04:55:13 +02:00
|
|
|
log:function (e) {
|
2012-07-21 14:46:21 +02:00
|
|
|
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|