/*
ע\ع (Ayn\Ayn) Lookup -- a tools for transliteration of Arabic/Syriac text to Hebrew writing system and a convenience interface to on-line translation services/search engines. Copyright (C) 2009, 2010, 2011 Ze'ev (Zeev, Vladimir) Belkin This program is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details. You should have received a copy of the GNU Affero General Public License along with this program. If not, see http://www.gnu.org/licenses/.(this option should not be used while the Author is alive)
Developed by Ze'ev (Zeev, Vladimir) Belkin ( http://zeevbelkin.com ).
© 2009, 2010, 2011 Ze'ev (Zeev, Vladimir) Belkin. All rights reserved.
This file is a part of ע\ع (Ayn\Ayn) Lookup and should be used
under terms of the ע\ع (Ayn\Ayn) Lookup license only.
**/
if (!String.fromCodePoint) {
(function() {
var defineProperty = (function() {
// IE 8 only supports `Object.defineProperty` on DOM elements
try {
var object = {};
var $defineProperty = Object.defineProperty;
var result = $defineProperty(object, object, object) && $defineProperty;
} catch(error) {}
return result;
}());
var stringFromCharCode = String.fromCharCode;
var floor = Math.floor;
var fromCodePoint = function() {
var MAX_SIZE = 0x4000;
var codeUnits = [];
var highSurrogate;
var lowSurrogate;
var index = -1;
var length = arguments.length;
if (!length) {
return '';
}
var result = '';
while (++index < length) {
var codePoint = Number(arguments[index]);
if (
!isFinite(codePoint) || // `NaN`, `+Infinity`, or `-Infinity`
codePoint < 0 || // not a valid Unicode code point
codePoint > 0x10FFFF || // not a valid Unicode code point
floor(codePoint) != codePoint // not an integer
) {
throw RangeError('Invalid code point: ' + codePoint);
}
if (codePoint <= 0xFFFF) { // BMP code point
codeUnits.push(codePoint);
} else { // Astral code point; split in surrogate halves
// http://mathiasbynens.be/notes/javascript-encoding#surrogate-formulae
codePoint -= 0x10000;
highSurrogate = (codePoint >> 10) + 0xD800;
lowSurrogate = (codePoint % 0x400) + 0xDC00;
codeUnits.push(highSurrogate, lowSurrogate);
}
if (index + 1 == length || codeUnits.length > MAX_SIZE) {
result += stringFromCharCode.apply(null, codeUnits);
codeUnits.length = 0;
}
}
return result;
};
if (defineProperty) {
defineProperty(String, 'fromCodePoint', {
'value': fromCodePoint,
'configurable': true,
'writable': true
});
} else {
String.fromCodePoint = fromCodePoint;
}
}());
}
if (!window.com) window.com={};
if (!window.com.zeevbelkin) window.com.zeevbelkin={};
/*if (!window.com.zeevbelkin.utils)*/ window.com.zeevbelkin.utils={
defobject:function(objname,ns,init) {
if (!ns) ns=window;
var obj=ns[objname];
if (!obj) {
var i=objname.indexOf('.');
if (i<0) {
if (!init) init={};
return ns[objname]=init;
}
var nsn=objname.substr(0,i),ns1=ns[nsn];
if (!ns1) ns1=ns[nsn]={};
return this.defobject(objname.substr(i+1),ns1);
}
return obj;
},
findobject:function(objname,ns) {
if (!ns) ns=window;
var obj=ns[objname];
if (!obj) {
var i=objname.indexOf('.');
if (i<0) return false;
var nsn=objname.substr(0,i),ns1=ns[nsn];
if (!ns1) return false;
return this.findobject(objname.substr(i+1),ns1);
}
return obj;
},
extend:function(obj,extension,ns) {
obj=((typeof obj)=='string')?this.defobject(obj,ns):obj;
if (extension) for (var i in extension) obj[i]=extension[i];
return obj;
},
inheritFromInstance:function(prototypeUpdate,baseClass) {
var c=function() {
if (baseClass) baseClass.apply(this,arguments);
if (prototypeUpdate.init) prototypeUpdate.init.apply(this,arguments);
}
if (baseClass) c.prototype=new baseClass();
for (var i in prototypeUpdate) c.prototype[i]=prototypeUpdate[i];
return c;
},
defclass:function(classname,baseClass,prototypeUpdate) {
var classobject=function() {
if (baseClass) baseClass.apply(this,arguments);
if (prototypeUpdate.init) prototypeUpdate.init.apply(this,arguments);
};
var v;
if (baseClass) {
for (var i in baseClass.prototype) classobject.prototype[i]=baseClass.prototype[i];
//classobject.prototype=baseClass.prototype;
}
if (prototypeUpdate) {
for (v in prototypeUpdate) {
classobject.prototype[v]=prototypeUpdate[v];
}
}
if (classname) {
classobject.prototype._className=classname;
var j=classname.lastIndexOf('.');
if (j<0) { window[classname]=classobject; } else {
var env=this.defobject(classname.substring(0,j));
env[classname.substr(j+1)]=classobject;
}
}
return classobject;
},
isDefined:function(x) {
return typeof x!='undefined';
},
isObject:function(x) {
return (typeof x)=='object';
},
isValidObject:function(objToTest) {
if (null == objToTest) return false;
if ("undefined" == typeof(objToTest)) return false;
return true;
},
isUrlSane:function(s) {
return s.match(/^http(s)?:\/\/[a-zA-Z]+/)&&!(s.match(/<|>|\"|\'/g)||s.match(/^http(s)?:\/\/localhost/));
},
_rx_trim:/(^\s+)|(\s+$)/g,
trim:function(s) {
return s.replace(this._rx_trim,"");
},
_rx_dec:/^\d+$/,
isDecimalString:function(s) {
return s.match(this._rx_dec);
}
};
with (com.zeevbelkin.utils) {
extend(
"com.zeevbelkin.utils", {
isArray:function(obj) {
if (Array.isArray) return Array.isArray(obj);
return isObject(obj)&&(obj.constructor == Array);
},
isFunction:function(obj) {
return obj&&(typeof(obj)=='function');
},
isHtmlElement:function(obj) {
return isObject(obj)&&(obj instanceof HTMLElement);
},
containsAnyString:function(s,ss) {
if (s) if (isArray(ss)) for (var i=0;i
/gi,"\n")
.replace(/<[^>]+>/g,"");
}
return s;
},
decodeUnicode:function(str) {
var r = [], i = 0;
while(i < str.length) {
var chr = str.charCodeAt(i++);
if(chr >= 0xD800 && chr <= 0xDBFF) {
// surrogate pair
var low = str.charCodeAt(i++);
r.push(0x10000 + ((chr - 0xD800) << 10) | (low - 0xDC00));
} else {
// ordinary character
r.push(chr);
}
}
return r;
},
encodeUnicode:function(chr) {
if(chr >= 0x10000) {
// surrogate pair
chr&=0xffff;
var TEN_BITS = 0x3ff;
function u(codeUnit) {
return ''+codeUnit.toString(16).toUpperCase()+';';
}
//chr -= 0x10000;
// Shift right to get to most significant 10 bits
var leadSurrogate = 0xD800 + (chr >> 10);
// Mask to get least significant 10 bits
var tailSurrogate = 0xDC00 + (chr & TEN_BITS);
return u(leadSurrogate) + u(tailSurrogate);
//var low=(chr&0x3ff)|0xDC00, high=((chr>>10)&0x5ff)|0xD800;
//return String.fromCharCode(high)+String.fromCharCode(low);
/*
var low = str.charCodeAt(i++);
r.push(0x10000 + ((chr - 0xD800) << 10) | (low - 0xDC00));
*/
} else {
// ordinary character
return String.fromCharCode(chr);
}
},
charcode:function(c) {
if (c) return ((typeof c)=='string')?decodeUnicode(c)[0]:c;
return false;
},
valuesOf:function(obj) {
var res=[];
for (var i in obj) res.push(obj[i]);
return res;
},
HashSet:function(a) { // set class constuctor
var x;
this.or=function() {
var r={},key;
for (key in this) r[key]=this[key];
if (arguments) for (var i=0;i