/** * Alias for document.getElementById. * @param {Number} id * @return {*} DOMElement */ var $ = function(id){ return document.getElementById(id); }; /** * Debug function. */ function _debug(){ if (debug){ var text = ''; for (var i = 0; i < arguments.length; i++){ if (arguments[i] === null){ text += ' null'; }else if (typeof(arguments[i]) === "undefined"){ text += ' undefined'; }else if (arguments[i] instanceof Date){ text += ' '+arguments[i].toString(); }else if (arguments[i].message && arguments[i].name){ text += ' '+arguments[i].name+' '+arguments[i].message; }else{ text += ' '+arguments[i].toSource(); } } try{ gSTB.Debug(text); }catch(e){ console&&console.log&&console.log(text); } } } function _log(action, param, content_id){ param = param || ''; content_id = content_id || 0; if (typeof(param) == 'object'){ var add_data = param; }else{ param = encodeURIComponent(param); } var data = { "type" : "stb", "action" : "log", "real_action" : action, "param" : (typeof param == 'string' || param instanceof String) ? encodeURIComponent(param) : param, "content_id" : content_id, "tmp_type" : stb.get_current_place() }; if (_log.hasOwnProperty('last_data') && _log.last_data.type == data.type && _log.last_data.action == data.action && _log.last_data.real_action == data.real_action && _log.last_data.param == data.param && _log.last_data.tmp_type == data.tmp_type ){ return; } _log.last_data = data; for (var prop in add_data){ if (add_data.hasOwnProperty(prop)){ data[prop] = add_data[prop]; } } stb.load( data, function(result){ _debug('on log', result); } ) } /** * Module loader. */ /*function load_module(module){ _debug('load_module', module); try{ var head = document.getElementsByTagName("head")[0]; var _script = document.createElement('script'); _script.type = "text/javascript"; _script.src = module + ".js"; var _style = document.createElement('link'); _style.type = "text/css"; _style.rel = "stylesheet"; _style.href = module + ".css"; head.appendChild(_script); _debug('append', _script.src); head.appendChild(_style); _debug('append', _style.href); }catch(e){ _debug(e); } }*/ /** * DOM element creating functions */ function create_dom_element(type, class_name, parent){ var dom_element = document.createElement(type); if (class_name){ dom_element.addClass(class_name); } parent = parent || document.body; if (parent){ parent.appendChild(dom_element); } return dom_element; } function create_inline_element(class_name, parent){ return create_dom_element('span', class_name, parent); } function create_block_element(class_name, parent){ return create_dom_element('div', class_name, parent); } /** * Custom prototype metods. */ HTMLElement.prototype.show = function(){ try{ switch(this.tagName.toLowerCase()){ case "span": case "strong": case "b": case "em": case "i": this.style.display = 'inline'; break; default: this.style.display = 'block'; } }catch(e){ _debug(e); } return this; }; HTMLElement.prototype.hide = function(){ try{ this.style.display = 'none'; }catch(e){ _debug(e); } return this; }; HTMLElement.prototype.isHidden = function(){ try{ return this.style.display == 'none'; }catch(e){ _debug(e); } }; HTMLElement.prototype.moveX = function(to_x){ try{ this.style.left = parseInt(to_x)+'px'; }catch(e){ _debug(e); } }; HTMLElement.prototype.moveY = function(to_y){ try{ this.style.top = parseInt(to_y)+'px'; }catch(e){ _debug(e); } }; HTMLElement.prototype.offsetX = function(offset_x){ try{ this.style.left = parseInt(this.offsetLeft)+offset_x+'px'; }catch(e){ _debug(e); } }; HTMLElement.prototype.offsetY = function(offset_y){ try{ this.style.top = parseInt(this.offsetTop)+offset_y+'px'; }catch(e){ _debug(e); } }; HTMLElement.prototype.setClass = function(class_name){ try{ this.className = class_name; }catch(e){ _debug(e); } return this; }; HTMLElement.prototype.delClass = function(){ try{ this.className = ''; }catch(e){ _debug(e); } return this; }; HTMLElement.prototype.haveClass = function(class_name){ var classes = this.className.replace(/\s+/g, ' ').split(' '); return classes.indexOf(class_name) != -1; }; HTMLElement.prototype.addClass = function(class_name){ try{ if (!this.className){ this.setClass(class_name); }else{ var classes = this.className.replace(/\s+/g, ' ').split(' '); if (classes.indexOf(class_name) == -1){ classes.push(class_name); } this.setClass(classes.join(' ')); } }catch(e){ _debug(e); } return this; }; HTMLElement.prototype.removeClass = function(class_name){ try{ if (this.className.indexOf(class_name) >= 0){ this.className = this.className.replace(eval('/('+class_name+')/g'), '').replace(/((\s)+)/g, ' '); } }catch(e){ _debug(e); } return this; }; HTMLElement.prototype.replaceClass = function(from, to){ try{ if (this.className.indexOf(from) >= 0 ){ this.className = this.className.replace(eval('/('+from+')/g'), to); } }catch(e){ _debug(e); } return this; }; String.prototype.clearnl = function(){ return this.replace(/(\n(\r)?)/g, ''); }; if (typeof Object.prototype.toSource != 'function'){ Object.prototype.toSource = function(level) { var con = this.constructor; var l = level || 0; l++; //console.log('level', level); //console.log(l); //_debug('l', l); if (l > 4){ //console.log('[Max level exceeded]'); return ''; } if(con == String) { //return '"' + this + '"'; return this; } else if(con == Number) { return this; } else if(con == Array) { var res = '['; for(var i=0,len=this.length;i _b ? 1: 0); }); }; Math.__proto__.isEven = function(x){ return !(x % 2); }; Math.__proto__.isOdd = function(x){ return !Math.isEven(x); }; function empty(val){ var type = typeof(val); if (type == 'string' && val == ''){ return true; }else if (type == 'undefined'){ return true; }else{ if (!val){ return true; }else if (type == 'object'){ for(var p in val){ if (val.hasOwnProperty(p)){ return false; } } return true; } } return false; } function get_params(){ var get = new String(window.location); var x = get.indexOf('?'); if (x!=-1){ var l = get.length; get = get.substr(x+1, l-x); l = get.split('&'); x = 0; for(var i in l){ if (l.hasOwnProperty(i)){ get = l[i].split('='); _GET[get[0]] = get[1]; x++; } } } } function get_word(alias){ return word[alias] || alias; } String.prototype.format = function() { var args = arguments; return this.replace(/{(\d+)}/g, function(match, number) { return typeof args[number] != 'undefined' ? args[number]: '{' + number + '}'; }); }; String.prototype.toTranslit = function(){ var map = { 'а' : 'a', 'б' : 'b', 'в' : 'v', 'г' : 'g', 'д' : 'd', 'е' : 'e', 'ж' : 'g', 'з' : 'z', 'и' : 'i', 'й' : 'y', 'к' : 'k', 'л' : 'l', 'м' : 'm', 'н' : 'n', 'о' : 'o', 'п' : 'p', 'р' : 'r', 'с' : 's', 'т' : 't', 'у' : 'u', 'ф' : 'f', 'ы' : 'i', 'э' : 'e', 'А' : 'A', 'Б' : 'B', 'В' : 'V', 'Г' : 'G', 'Д' : 'D', 'Е' : 'E', 'Ж' : 'G', 'З' : 'Z', 'И' : 'I', 'Й' : 'Y', 'К' : 'K', 'Л' : 'L', 'М' : 'M', 'Н' : 'N', 'О' : 'O', 'П' : 'P', 'Р' : 'R', 'С' : 'S', 'Т' : 'T', 'У' : 'U', 'Ф' : 'F', 'Ы' : 'I', 'Э' : 'E', 'ё':"yo", 'х':"h", 'ц':"ts", 'ч':"ch", 'ш':"sh", 'щ':"shch", 'ъ':'', 'ь':'', 'ю':"yu", 'я':"ya", 'Ё':"Yo", 'Х':"H", 'Ц':"Ts", 'Ч':"Ch", 'Ш':"Sh", 'Щ':"Shch", 'Ъ':'', 'Ь':'', 'Ю':"Yu", 'Я':"Ya", ' ':"_", '!':"", '?':"", ',':"", '.':"", '"':"", '\'':"", '\\':"", '/':"", ';':"", ':':"", '«':"", '»':"", '`':"", '-' : "-", '—' : "-" }; var arr = this.split('').map(function(letter){ if (map.hasOwnProperty(letter)){ letter = map[letter]; } return letter; }); return arr.join('').replace(/[^a-z0-9_-]/ig, ''); }; /** * @example * var obj ={ * 'tag':'div', * 'attrs':{ * 'id':'id', * 'class': 'new_class', * 'style':'"width:50px' * }, * 'child':[ * { * 'tag':'div', * 'attrs':{ * 'id':'id', * 'class': 'new_class', * 'style':'"width:50px' * }, * 'child':[ * * ] * }, * { * 'tag':'div', * * 'attrs':{ * 'id':'id', * 'class': 'new_class', * 'style':'"width:50px' * }, * 'child':[ * * ] * } * ] * }; * createHTMLTree(obj); * * @param obj */ function createHTMLTree(obj){ var el = document.createElement(obj.tag); for(var key in obj.attrs) { if (obj.attrs.hasOwnProperty(key)){ el.setAttribute(key, obj.attrs[key]); } } if(typeof obj.child != 'undefined'){ for(var i=0; i>> (32 - s)), b); } function ff(a, b, c, d, x, s, t) { return cmn((b & c) | ((~b) & d), a, b, x, s, t); } function gg(a, b, c, d, x, s, t) { return cmn((b & d) | (c & (~d)), a, b, x, s, t); } function hh(a, b, c, d, x, s, t) { return cmn(b ^ c ^ d, a, b, x, s, t); } function ii(a, b, c, d, x, s, t) { return cmn(c ^ (b | (~d)), a, b, x, s, t); } function md51(s) { txt = ''; var n = s.length, state = [1732584193, -271733879, -1732584194, 271733878], i; for (i=64; i<=s.length; i+=64) { md5cycle(state, md5blk(s.substring(i-64, i))); } s = s.substring(i-64); var tail = [0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0]; for (i=0; i>2] |= s.charCodeAt(i) << ((i%4) << 3); tail[i>>2] |= 0x80 << ((i%4) << 3); if (i > 55) { md5cycle(state, tail); for (i=0; i<16; i++) tail[i] = 0; } tail[14] = n*8; md5cycle(state, tail); return state; } /* there needs to be support for Unicode here, * unless we pretend that we can redefine the MD-5 * algorithm for multi-byte characters (perhaps * by adding every four 16-bit characters and * shortening the sum to 32 bits). Otherwise * I suggest performing MD-5 as if every character * was two bytes--e.g., 0040 0025 = @%--but then * how will an ordinary MD-5 sum be matched? * There is no way to standardize text to something * like UTF-8 before transformation; speed cost is * utterly prohibitive. The JavaScript standard * itself needs to look at this: it should start * providing access to strings as preformed UTF-8 * 8-bit unsigned value arrays. */ function md5blk(s) { /* I figured global was faster. */ var md5blks = [], i; /* Andy King said do it this way. */ for (i=0; i<64; i+=4) { md5blks[i>>2] = s.charCodeAt(i) + (s.charCodeAt(i+1) << 8) + (s.charCodeAt(i+2) << 16) + (s.charCodeAt(i+3) << 24); } return md5blks; } var hex_chr = '0123456789abcdef'.split(''); function rhex(n) { var s='', j=0; for(; j<4; j++) s += hex_chr[(n >> (j * 8 + 4)) & 0x0F] + hex_chr[(n >> (j * 8)) & 0x0F]; return s; } function hex(x) { for (var i=0; i> 16) + (y >> 16) + (lsw >> 16); return (msw << 16) | (lsw & 0xFFFF); } }