/**********************************************************************/ /*********** Bitrix JS Core library ver 0.9.0 beta ********************/ /**********************************************************************/ ;(function(window){ if (window.BX) return; var BX = function(node, bCache) { if (BX.type.isNotEmptyString(node)) { var ob; if (!!bCache && null != NODECACHE[node]) ob = NODECACHE[node]; ob = ob || document.getElementById(node); if (!!bCache) NODECACHE[node] = ob; return ob; } else if (BX.type.isDomNode(node)) return node; else if (BX.type.isFunction(node)) return BX.ready(node); return null; }, /* language messages */ MESS = {}, /* ready */ __readyHandler = null, readyBound = false, readyList = [], /* list of registered proxy functions */ proxyId = 1, proxyList = [], /* getElementById cache */ NODECACHE = {}, /* List of denied event handlers */ deniedEvents = [], /* list of registered event handlers */ eventsList = [], /* list of registered custom events */ customEvents = {}, /* list of external garbage collectors */ garbageCollectors = [], /* browser detection */ bOpera = navigator.userAgent.toLowerCase().indexOf('opera') != -1, bSafari = navigator.userAgent.toLowerCase().indexOf('webkit') != -1, bIE = document.attachEvent && !bOpera, /* regexps */ r = { script: /]*)>/i, script_src: /src=["\']([^"\']+)["\']/i, space: /\s+/, ltrim: /^[\s\r\n]+/g, rtrim: /[\s\r\n]+$/g, style: /]*/i, style_href: /href=["\']([^"\']+)["\']/i }, eventTypes = { click: 'MouseEvent', dblclick: 'MouseEvent', mousedown: 'MouseEvent', mousemove: 'MouseEvent', mouseout: 'MouseEvent', mouseover: 'MouseEvent', mouseup: 'MouseEvent' }, lastWait = []; BX.ext = function(ob) {for (var i in ob) this[i] = ob[i];} /* OO emulation utility */ BX.extend = function(child, parent) { var f = function() {}; f.prototype = parent.prototype; child.prototype = new f(); child.prototype.constructor = child; child.superclass = parent.prototype; if(parent.prototype.constructor == Object.prototype.constructor) { parent.prototype.constructor = parent; } } BX.is_subclass_of = function(ob, parent_class) { if (ob instanceof parent_class) return true; if (parent_class.superclass) return BX.is_subclass_of(ob, parent_class.superclass); return false; } // language utility BX.message = function(mess) { if (BX.type.isString(mess)) return MESS[mess]; else { for (var i in mess) { MESS[i] = mess[i]; } return true; } } BX.bitrix_sessid = function() {return MESS.bitrix_sessid;} /* DOM manipulation */ BX.create = function(tag, data, context) { context = context || document; if (null == data && typeof tag == 'object' && tag.constructor !== String) { data = tag; tag = tag.tag; } var elem; if (BX.browser.IsIE() && !BX.browser.IsIE9() && null != data && null != data.props && (data.props.name || data.props.id)) { elem = context.createElement('<' + tag + (data.props.name ? ' name="' + data.props.name + '"' : '') + (data.props.id ? ' id="' + data.props.id + '"' : '') + '>'); } else { elem = context.createElement(tag); } return data ? BX.adjust(elem, data) : elem; } BX.adjust = function(elem, data) { var j,len; if (!elem.nodeType) return null; if (elem.nodeType == 9) elem = elem.body; if (data.attrs) { for (j in data.attrs) { if (j == 'class' || j == 'className') elem.className = data.attrs[j]; else if(data.attrs[j] == "") elem.removeAttribute(j); else elem.setAttribute(j, data.attrs[j]); } } if (data.style) { for (j in data.style) elem.style[j] = data.style[j]; } if (data.props) { for (j in data.props) elem[j] = data.props[j]; } if (data.events) { for (j in data.events) BX.bind(elem, j, data.events[j]); } if (data.children && data.children.length > 0) { for (j=0,len=data.children.length; j 0) node.removeChild(node.firstChild); } if (node && bSuicide) { node = BX.remove(node); } return node; } BX.addClass = function(ob, value) { var classNames; ob = BX(ob) if (ob) { if (!ob.className) { ob.className = value } else { classNames = (value || "").split(r.space); var className = " " + ob.className + " "; for (var j = 0, cl = classNames.length; j < cl; j++) { if (className.indexOf(" " + classNames[j] + " ") < 0) { ob.className += " " + classNames[j]; } } } } return ob; } BX.removeClass = function(ob, value) { ob = BX(ob); if (ob) { if (ob.className) { if (BX.type.isString(value)) { var classNames = value.split(r.space), className = " " + ob.className + " "; for (var j = 0, cl = classNames.length; j < cl; j++) { className = className.replace(" " + classNames[j] + " ", " "); } ob.className = BX.util.trim(className); } else { ob.className = ""; } } } return ob; } BX.toggleClass = function(ob, value) { var className; if (BX.type.isArray(value)) { className = ' ' + ob.className + ' '; for (var j = 0, len = value.length; j < len; j++) { if (BX.hasClass(ob, value[j])) { className = (' ' + className + ' ').replace(' ' + value[j] + ' ', ' '); className += ' ' + value[j >= len-1 ? 0 : j+1]; j--; break; } } if (j == len) ob.className += ' ' + value[0]; else ob.className = className; ob.className = BX.util.trim(ob.className); } else if (BX.type.isNotEmptyString(value)) { className = ob.className; if (BX.hasClass(ob, value)) { className = (' ' + className + ' ').replace(' ' + value + ' ', ' '); } else { className += ' ' + value; } ob.className = BX.util.trim(className); } return ob; } BX.hasClass = function(el, className) { if (!el.className) return false; return ((" " + el.className + " ").indexOf(" " + className + " ")) >= 0; } BX.hoverEvents = function(el) { if (el) return BX.adjust(el, {events: BX.hoverEvents()}); else return {mouseover: BX.hoverEventsHover, mouseout: BX.hoverEventsHout}; } BX.hoverEventsHover = function(){BX.addClass(this,'bx-hover');this.BXHOVER=true;} BX.hoverEventsHout = function(){BX.removeClass(this,'bx-hover');this.BXHOVER=false;} BX.focusEvents = function(el) { if (el) return BX.adjust(el, {events: BX.focusEvents()}); else return {mouseover: BX.focusEventsFocus, mouseout: BX.focusEventsBlur}; } BX.focusEventsFocus = function(){BX.addClass(this,'bx-focus');this.BXFOCUS=true;} BX.focusEventsBlur = function(){BX.removeClass(this,'bx-focus');this.BXFOCUS=false;} BX.setUnselectable = function(node) { BX.addClass(node, 'bx-unselectable'); node.setAttribute('unSelectable', 'on'); } BX.setSelectable = function(node) { BX.removeClass(node, 'bx-unselectable'); node.removeAttribute('unSelectable'); } BX.styleIEPropertyName = function(name) { if (name == 'float') name = BX.browser.IsIE() ? 'styleFloat' : 'cssFloat'; else { var reg = /(\-([a-z]){1})/g; if (reg.test(name)) { name = name.replace(reg, function () {return arguments[2].toUpperCase();}); } } return name; } /* CSS-notation should be used here */ BX.style = function(el, property, value) { if (!BX.type.isElementNode(el)) return null; if (value == null) { var res; if(el.currentStyle) res = el.currentStyle[BX.styleIEPropertyName(property)]; else if(window.getComputedStyle) res = BX.GetContext(el).getComputedStyle(el, null).getPropertyValue(property); if(!res) res = ''; return res; } else { el.style[BX.styleIEPropertyName(property)] = value; return el; } } BX.focus = function(el) { try { el.focus(); return true; } catch (e) { return false; } } /* params: { tagName|tag : 'tagName', className|class : 'className', attribute : {attribute : value, attribute : value} | attribute | [attribute, attribute....], property : {prop: value, prop: value} | prop | [prop, prop] } all values can be RegExps or strings */ BX.findChildren = function(obj, params, recursive) { return BX.findChild(obj, params, recursive, true); } BX.findChild = function(obj, params, recursive, get_all) { if(!obj || !obj.childNodes) return null; recursive = !!recursive; get_all = !!get_all; var n = obj.childNodes.length, result = []; for (var j=0; j 0) return result; else return null; } BX.findParent = function(obj, params) { if(!obj) return null; var o = obj; while(o.parentNode) { var parent = o.parentNode; if (_checkNode(parent, params)) return parent; o = parent; } return null; } BX.findNextSibling = function(obj, params) { if(!obj) return null; var o = obj; while(o.nextSibling) { var sibling = o.nextSibling; if (_checkNode(sibling, params)) return sibling; o = sibling; } return null; } BX.findPreviousSibling = function(obj, params) { if(!obj) return null; var o = obj; while(o.previousSibling) { var sibling = o.previousSibling; if(_checkNode(sibling, params)) return sibling; o = sibling; } return null; } BX.clone = function(obj, bCopyObj) { var _obj, i, l; if (bCopyObj !== false) bCopyObj = true; if (obj === null) return null; if (BX.type.isDomNode(obj)) { _obj = obj.cloneNode(bCopyObj); } else if (typeof obj == 'object') { if (BX.type.isArray(obj)) { _obj = []; for (i=0,l=obj.length;i= 0) eval('result = ' + data); else result = (new Function("return " + data))(); }catch(e){} } return result; } /* ready */ BX.isReady = false; BX.ready = function(handler) { bindReady(); if (BX.isReady) handler.call(document); else if (readyList) readyList.push(handler); } BX.submit = function(obForm, action_name, action_value) { action_name = action_name || 'save'; if (!obForm['BXFormSubmit_' + action_name]) { obForm['BXFormSubmit_' + action_name] = obForm.appendChild(BX.create('INPUT', { 'props': { 'type': 'submit', 'name': action_name, 'value': action_value || 'Y' }, 'style': { 'display': 'none' } })); } BX.fireEvent(obForm['BXFormSubmit_' + action_name], 'click'); } /* browser detection */ BX.browser = { IsMac: function() { return (/Macintosh/i.test(navigator.userAgent)); }, IsIE: function() { return bIE; }, IsIE6: function() { return (/MSIE 6/i.test(navigator.userAgent)); }, IsIE9: function() { return !!document.documentMode && document.documentMode >= 9; }, IsOpera: function() { return bOpera; }, IsSafari: function() { return bSafari; }, IsDoctype: function(pDoc) { pDoc = pDoc || document; if (pDoc.compatMode) return (pDoc.compatMode == "CSS1Compat"); if (pDoc.documentElement && pDoc.documentElement.clientHeight) return true; return false; }, SupportLocalStorage: function() { return !!BX.localStorage && !!BX.localStorage.checkBrowser() } } /* low-level fx funcitons*/ BX.show = function(ob) { if (ob.BXDISPLAY || !_checkDisplay(ob)) { ob.style.display = ob.BXDISPLAY; } } BX.hide = function(ob) { if (!ob.BXDISPLAY) _checkDisplay(ob); ob.style.display = 'none'; } BX.toggle = function(ob, values) { if (!values && BX.type.isElementNode(ob)) { var bShow = true; if (ob.BXDISPLAY) bShow = !_checkDisplay(ob); else bShow = ob.style.display == 'none'; if (bShow) BX.show(ob); else BX.hide(ob); } else if (BX.type.isArray(values)) { for (var i=0,len=values.length; i/g, '>'); }, htmlspecialcharsback: function(str) { if(!str.replace) return str; return str.replace(/\"/g, '"').replace(/'/g, "'").replace(/\</g, '<').replace(/\>/g, '>').replace(/\&/g, '&'); }, // Quote regular expression characters plus an optional character preg_quote: function(str, delimiter) { if(!str.replace) return str; return str.replace(new RegExp('[.\\\\+*?\\[\\^\\]$(){}=!<>|:\\' + (delimiter || '') + '-]', 'g'), '\\$&'); }, jsencode: function(str) { if (!str || !str.replace) return str; var escapes = [ { c: "\\\\", r: "\\\\" }, // should be first { c: "\\t", r: "\\t" }, { c: "\\n", r: "\\n" }, { c: "\\r", r: "\\r" }, { c: "\"", r: "\\\"" }, { c: "'", r: "\\'" }, { c: "<", r: "\\x3C" }, { c: ">", r: "\\x3E" }, { c: "\\u2028", r: "\\u2028" }, { c: "\\u2029", r: "\\u2029" } ]; for (var i = 0; i < escapes.length; i++) str = str.replace(new RegExp(escapes[i].c, 'g'), escapes[i].r); return str; }, str_pad: function(input, pad_length, pad_string, pad_type) { pad_string = pad_string || ' '; pad_type = pad_type || 'right'; input = input.toString(); if (pad_type == 'left') return BX.util.str_pad_left(input, pad_length, pad_string); else return BX.util.str_pad_right(input, pad_length, pad_string); }, str_pad_left: function(input, pad_length, pad_string) { var i = input.length, q=pad_string.length; if (i >= pad_length) return input; for(;i= pad_length) return input; for(;i 0 : false; }, isBoolean: function(item) { return item === false || item === false; }, isNumber: function(item) { return item === 0 ? true : (item ? (typeof (item) == "number" || item instanceof Number) : false); }, isFunction: function(item) { return item === null ? false : (typeof (item) == "function" || item instanceof Function); }, isElementNode: function(item) { return item && typeof (item) == "object" && "nodeType" in item && item.nodeType == 1; //document.body.ELEMENT_NODE; }, isDomNode: function(item) { return item && typeof (item) == "object" && "nodeType" in item; }, isArray: function(item) { return item && Object.prototype.toString.call(item) == "[object Array]"; }, isDate : function(item) { return item && Object.prototype.toString.call(item) == "[object Date]"; } } BX.isNodeInDom = function(node) { return node === document ? true : (node.parentNode ? BX.isNodeInDom(node.parentNode) : false); } BX.evalPack = function(code) { while (code.length > 0) { var c = code.shift(); if (c.TYPE == 'SCRIPT_EXT' || c.TYPE == 'SCRIPT_SRC') { BX.loadScript(c.DATA, function() {BX.evalPack(code)}); } else if (c.TYPE == 'SCRIPT') BX.evalGlobal(c.DATA); } } BX.evalGlobal = function(data) { if (data) { var head = document.getElementsByTagName("head")[0] || document.documentElement, script = document.createElement("script"); script.type = "text/javascript"; if (!BX.browser.IsIE()) { script.appendChild(document.createTextNode(data)); } else { script.text = data; } head.insertBefore(script, head.firstChild); head.removeChild(script); } } BX.processHTML = function(HTML, scriptsRunFirst) { var matchScript, scripts = [], data = HTML; while ((matchScript = data.match(r.script)) !== null) { var end = data.search('<\/script>', 'i'); if (end == -1) break; var bRunFirst = scriptsRunFirst || (matchScript[1].indexOf('bxrunfirst') != '-1'); var matchSrc; if ((matchSrc = matchScript[1].match(r.script_src)) !== null) scripts.push({"bRunFirst": bRunFirst, "isInternal": false, "JS": matchSrc[1]}); else { var start = matchScript.index + matchScript[0].length; var js = data.substr(start, end-start); scripts.push({"bRunFirst": bRunFirst, "isInternal": true, "JS": js}); } data = data.substr(0, matchScript.index) + data.substr(end+9); } var res = {'HTML': data, 'SCRIPT': scripts, 'STYLE': []}; if (BX.browser.IsIE()/* && !BX.browser.IsIE9()*/) { while ((matchStyle = data.match(r.style)) !== null) { var matchHref; if ((matchHref = matchStyle[0].match(r.style_href)) !== null) { res.STYLE.push(matchHref[1]); } data = data.replace(matchStyle[0], ''); } } return res; } BX.garbage = function(call, thisObject) { garbageCollectors.push({callback: call, context: thisObject}); } /* window pos functions */ BX.GetDocElement = function (pDoc) { pDoc = pDoc || document; return (BX.browser.IsDoctype(pDoc) ? pDoc.documentElement : pDoc.body); } BX.GetContext = function(node) { if (BX.type.isElementNode(node)) return node.ownerDocument.parentWindow || node.ownerDocument.defaultView || window; else if (BX.type.isDomNode(node)) return node.parentWindow || node.defaultView || window; else return window; } BX.GetWindowInnerSize = function(pDoc) { var width, height; pDoc = pDoc || document; if (self.innerHeight) // all except Explorer { width = BX.GetContext(pDoc).innerWidth; height = BX.GetContext(pDoc).innerHeight; } else if (pDoc.documentElement && (pDoc.documentElement.clientHeight || pDoc.documentElement.clientWidth)) // Explorer 6 Strict Mode { width = pDoc.documentElement.clientWidth; height = pDoc.documentElement.clientHeight; } else if (pDoc.body) // other Explorers { width = pDoc.body.clientWidth; height = pDoc.body.clientHeight; } return {innerWidth : width, innerHeight : height}; } BX.GetWindowScrollPos = function(pDoc) { var left, top; pDoc = pDoc || document; if (self.pageYOffset) // all except Explorer { left = BX.GetContext(pDoc).pageXOffset; top = BX.GetContext(pDoc).pageYOffset; } else if (pDoc.documentElement && (pDoc.documentElement.scrollTop || pDoc.documentElement.scrollLeft)) // Explorer 6 Strict { left = pDoc.documentElement.scrollLeft; top = pDoc.documentElement.scrollTop; } else if (pDoc.body) // all other Explorers { left = pDoc.body.scrollLeft; top = pDoc.body.scrollTop; } return {scrollLeft : left, scrollTop : top}; } BX.GetWindowScrollSize = function(pDoc) { var width, height; if (!pDoc) pDoc = document; if ( (pDoc.compatMode && pDoc.compatMode == "CSS1Compat")) { width = pDoc.documentElement.scrollWidth; height = pDoc.documentElement.scrollHeight; } else { if (pDoc.body.scrollHeight > pDoc.body.offsetHeight) height = pDoc.body.scrollHeight; else height = pDoc.body.offsetHeight; if (pDoc.body.scrollWidth > pDoc.body.offsetWidth || (pDoc.compatMode && pDoc.compatMode == "BackCompat") || (pDoc.documentElement && !pDoc.documentElement.clientWidth) ) width = pDoc.body.scrollWidth; else width = pDoc.body.offsetWidth; } return {scrollWidth : width, scrollHeight : height}; } BX.GetWindowSize = function(pDoc) { var innerSize = this.GetWindowInnerSize(pDoc); var scrollPos = this.GetWindowScrollPos(pDoc); var scrollSize = this.GetWindowScrollSize(pDoc); return { innerWidth : innerSize.innerWidth, innerHeight : innerSize.innerHeight, scrollLeft : scrollPos.scrollLeft, scrollTop : scrollPos.scrollTop, scrollWidth : scrollSize.scrollWidth, scrollHeight : scrollSize.scrollHeight }; } BX.hide_object = function(ob) { ob = BX(ob); ob.style.position = 'absolute'; ob.style.top = '-1000px'; ob.style.left = '-1000px'; ob.style.height = '10px'; ob.style.width = '10px'; }; BX.is_relative = function(el) { var p = BX.style(el, 'position'); return p == 'relative' || p == 'absolute'; } BX.is_float = function(el) { var p = BX.style(el, 'float'); return p == 'right' || p == 'left'; } BX.pos = function(el, bRelative) { var r = { top: 0, right: 0, bottom: 0, left: 0, width: 0, height: 0 }; bRelative = !!bRelative; if (!el) return r; if (typeof (el.getBoundingClientRect) != "undefined" && el.ownerDocument == document && !bRelative) { var clientRect = el.getBoundingClientRect(); var root = document.documentElement; var body = document.body; r.top = clientRect.top + root.scrollTop + body.scrollTop; r.left = clientRect.left + root.scrollLeft + body.scrollLeft; r.width = clientRect.right - clientRect.left; r.height = clientRect.bottom - clientRect.top; r.right = clientRect.right + root.scrollLeft + body.scrollLeft; r.bottom = clientRect.bottom + root.scrollTop + body.scrollTop; } else { var x = 0, y = 0, w = el.offsetWidth, h = el.offsetHeight; var first = true; for (; el != null; el = el.offsetParent) { if (!first && bRelative && BX.is_relative(el)) break; x += el.offsetLeft; y += el.offsetTop; if (first) { first = false; continue; } var elBorderLeftWidth = parseInt(BX.style(el, 'border-left-width')), elBorderTopWidth = parseInt(BX.style(el, 'border-top-width')); if (!isNaN(elBorderLeftWidth) && elBorderLeftWidth > 0) x += elBorderLeftWidth; if (!isNaN(elBorderTopWidth) && elBorderTopWidth > 0) y += elBorderTopWidth; } r.top = y; r.left = x; r.width = w; r.height = h; r.right = r.left + w; r.bottom = r.top + h; } for (var i in r) r[i] = parseInt(r[i]); return r; } BX.align = function(pos, w, h) { var pDoc = document; if (BX.type.isElementNode(pos)) { pDoc = pos.ownerDocument; pos = BX.pos(pos); } var x = pos["left"], y = pos["bottom"]; var scroll = BX.GetWindowScrollPos(pDoc); var size = BX.GetWindowInnerSize(pDoc); if((size.innerWidth + scroll.scrollLeft) - (pos["left"] + w) < 0) { if(pos["right"] - w >= 0 ) x = pos["right"] - w; else x = scroll.scrollLeft; } if((size.innerHeight + scroll.scrollTop) - (pos["bottom"] + h) < 0) { if(pos["top"] - h >= 0) y = pos["top"] - h; else y = scroll.scrollTop; } return {'left':x, 'top':y}; } BX.scrollToNode = function(node) { var obNode = BX(node); if (obNode.scrollIntoView) obNode.scrollIntoView(true); else { var arNodePos = BX.pos(obNode); window.scrollTo(arNodePos.left, arNodePos.top); } } /* non-xhr loadings */ BX.showWait = function(node, msg) { node = BX(node) || document.body || document.documentElement; msg = msg || BX.message('JS_CORE_LOADING'); var container_id = node.id || Math.random(); var obMsg = node.bxmsg = document.body.appendChild(BX.create('DIV', { props: { id: 'wait_' + container_id, className: 'bx-core-waitwindow' }, text: msg })); setTimeout(BX.delegate(_adjustWait, node), 10); lastWait[lastWait.length] = obMsg; return obMsg; } BX.closeWait = function(node, obMsg) { obMsg = obMsg || node && (node.bxmsg || BX('wait_' + node.id)) || lastWait.pop(); if (obMsg && obMsg.parentNode) { for (var i=0,len=lastWait.length;i= script.length) return _callback(); var oHead = doc.getElementsByTagName("head")[0] || doc.documentElement; var oScript = doc.createElement('script'); oScript.src = script[ind]; var bLoaded = false; oScript.onload = oScript.onreadystatechange = function() { if (!bLoaded && (!oScript.readyState || oScript.readyState == "loaded" || oScript.readyState == "complete")) { bLoaded = true; setTimeout(function (){load_js(++ind);}, 50); oScript.onload = oScript.onreadystatechange = null; if (oHead && oScript.parentNode) { oHead.removeChild(oScript); } } } return oHead.insertBefore(oScript, oHead.firstChild); } load_js(0); } BX.loadCSS = function(arCSS, doc, win) { if (!BX.isReady) { var _args = arguments; BX.ready(function() { BX.loadCSS.apply(this, _args); }); return null; } if (BX.type.isString(arCSS)) { var bSingle = true; arCSS = [arCSS]; } var i, l = arCSS.length, pLnk = []; if (l == 0) return null; doc = doc || document; win = win ||window; if (!win.bxhead) { var heads = doc.getElementsByTagName('HEAD'); win.bxhead = heads[0]; } if (!win.bxhead) return null; for (i = 0; i < l; i++) { var lnk = document.createElement('LINK'); lnk.href = arCSS[i]; lnk.rel = 'stylesheet'; lnk.type = 'text/css'; win.bxhead.appendChild(lnk); pLnk.push(lnk); } if (bSingle) return lnk; return pLnk; } BX.reload = function(back_url, bAddClearCache) { if (back_url === true) { bAddClearCache = true; back_url = null; } var new_href = back_url || top.location.href; var hashpos = new_href.indexOf('#'), hash = ''; if (hashpos != -1) { hash = new_href.substr(hashpos); new_href = new_href.substr(0, hashpos); } if (bAddClearCache && new_href.indexOf('clear_cache=Y') < 0) new_href += (new_href.indexOf('?') == -1 ? '?' : '&') + 'clear_cache=Y'; if (hash) { // hack for clearing cache in ajax mode components with history emulation if (bAddClearCache && (hash.substr(0, 5) == 'view/' || hash.substr(0, 6) == '#view/') && hash.indexOf('clear_cache%3DY') < 0) hash += (hash.indexOf('%3F') == -1 ? '%3F' : '%26') + 'clear_cache%3DY' new_href = new_href.replace(/(\?|\&)_r=[\d]*/, ''); new_href += (new_href.indexOf('?') == -1 ? '?' : '&') + '_r='+Math.round(Math.random()*10000) + hash; } top.location.href = new_href; } BX.clearCache = function() { BX.showWait(); BX.reload(true); } BX.formatDate = function(date, format) { date = date || new Date(); var bTime = date.getHours() || date.getMinutes() || date.getSeconds(), str = !!format ? format : (bTime ? BX.message('FORMAT_DATETIME') : BX.message('FORMAT_DATE') ); return str.replace(/YYYY/ig, date.getFullYear()) .replace(/MM/ig, BX.util.str_pad_left((date.getMonth()+1).toString(), 2, '0')) .replace(/DD/ig, BX.util.str_pad_left(date.getDate().toString(), 2, '0')) .replace(/HH/ig, BX.util.str_pad_left(date.getHours().toString(), 2, '0')) .replace(/MI/ig, BX.util.str_pad_left(date.getMinutes().toString(), 2, '0')) .replace(/SS/ig, BX.util.str_pad_left(date.getSeconds().toString(), 2, '0')); } BX.parseDate = function(str) { var aDate = str.split(/\D/ig); var aFormat = BX.message('FORMAT_DATE').split(/\W/ig); if(aDate.length > aFormat.length) aFormat = BX.message('FORMAT_DATETIME').split(/\W/ig); var i, cnt; var aDateArgs=[], aFormatArgs=[]; for(i = 0, cnt = aDate.length; i < cnt; i++) if(BX.util.trim(aDate[i]) != '') aDateArgs[aDateArgs.length] = aDate[i]; for(i = 0, cnt = aFormat.length; i < cnt; i++) if(BX.util.trim(aFormat[i]) != '') aFormatArgs[aFormatArgs.length] = aFormat[i]; var aResult={}; for(i = 0, cnt = aFormatArgs.length; i < cnt; i++) aResult[aFormatArgs[i].toUpperCase()] = parseInt(aDateArgs[i], 10); if(aResult['DD'] > 0 && aResult['MM'] > 0 && aResult['YYYY'] > 0) { var d = new Date(); d.setDate(1); d.setFullYear(aResult['YYYY']); d.setMonth(aResult['MM']-1); d.setDate(aResult['DD']); d.setHours(0, 0, 0); if(!isNaN(aResult['HH']) && !isNaN(aResult['MI']) && !isNaN(aResult['SS'])) { d.setHours(aResult['HH'], aResult['MI'], aResult['SS']); } return d; } return null; } /******* HINT ***************/ // if function has 2 params - the 2nd one is hint html. otherwise hint_html is third and hint_title - 2nd; // '
; // BX.hint(el, 'This is Hint') - this won't work, use constructor BX.hint = function(el, hint_title, hint_html, hint_id) { if (null == hint_html) { hint_html = hint_title; hint_title = ''; } if (null == el.BXHINT) { el.BXHINT = new BX.CHint({ parent: el, hint: hint_html, title: hint_title, id: hint_id }); el.BXHINT.Show(); } } BX.hint_replace = function(el, hint_title, hint_html) { if (null == hint_html) { hint_html = hint_title; hint_title = ''; } if (!el || !el.parentNode || !hint_html) return null; var obHint = new BX.CHint({ hint: hint_html, title: hint_title }); obHint.CreateParent(); el.parentNode.insertBefore(obHint.PARENT, el); el.parentNode.removeChild(el); obHint.PARENT.style.marginLeft = '5px'; return el; } BX.CHint = function(params) { this.PARENT = BX(params.parent); this.HINT = params.hint; this.HINT_TITLE = params.title; this.PARAMS = {} for (var i in this.defaultSettings) { if (null == params[i]) this.PARAMS[i] = this.defaultSettings[i]; else this.PARAMS[i] = params[i]; } if (null != params.id) this.ID = params.id; this.timer = null; this.bInited = false; this.msover = true; if (this.PARAMS.showOnce) { this.__show(); this.msover = false; this.timer = setTimeout(BX.proxy(this.__hide, this), this.PARAMS.hide_timeout); } else if (this.PARENT) { BX.bind(this.PARENT, 'mouseover', BX.proxy(this.Show, this)); BX.bind(this.PARENT, 'mouseout', BX.proxy(this.Hide, this)); } BX.addCustomEvent('onMenuOpen', BX.delegate(this.disable, this)); BX.addCustomEvent('onMenuClose', BX.delegate(this.enable, this)); } BX.CHint.prototype.defaultSettings = { show_timeout: 1000, hide_timeout: 500, dx: 2, showOnce: false, preventHide: true, min_width: 250 } BX.CHint.prototype.CreateParent = function(element, params) { if (this.PARENT) { BX.unbind(this.PARENT, 'mouseover', BX.proxy(this.Show, this)); BX.unbind(this.PARENT, 'mouseout', BX.proxy(this.Hide, this)); } if (!params) params = {} var type = 'icon'; if (params.type && (params.type == "link" || params.type == "icon")) type = params.type; if (element) type = "element"; if (type == "icon") { element = BX.create('IMG', { props: { src: params.iconSrc ? params.iconSrc : "/bitrix/js/main/core/images/hint.gif" } }); } else if (type == "link") { element = BX.create("A", { props: {href: 'javascript:void(0)'}, html: '[?]' }); } this.PARENT = element; BX.bind(this.PARENT, 'mouseover', BX.proxy(this.Show, this)); BX.bind(this.PARENT, 'mouseout', BX.proxy(this.Hide, this)); return this.PARENT; } BX.CHint.prototype.Show = function() { this.msover = true; if (null != this.timer) clearTimeout(this.timer); this.timer = setTimeout(BX.proxy(this.__show, this), this.PARAMS.show_timeout); } BX.CHint.prototype.Hide = function() { this.msover = false; if (null != this.timer) clearTimeout(this.timer); this.timer = setTimeout(BX.proxy(this.__hide, this), this.PARAMS.hide_timeout); } BX.CHint.prototype.__show = function() { if (!this.msover || this.disabled) return; if (!this.bInited) this.Init(); this.prepareAdjustPos(); this.DIV.style.display = 'block'; this.adjustPos(); BX.bind(window, 'scroll', BX.proxy(this.__onscroll, this)); if (this.PARAMS.showOnce) { this.timer = setTimeout(BX.proxy(this.__hide, this), this.PARAMS.hide_timeout); } } BX.CHint.prototype.__onscroll = function() { if (!BX.admin || !BX.admin.panel || !BX.admin.panel.isFixed()) return; if (this.scrollTimer) clearTimeout(this.scrollTimer); this.DIV.style.display = 'none'; this.scrollTimer = setTimeout(BX.proxy(this.Reopen, this), this.PARAMS.show_timeout); } BX.CHint.prototype.Reopen = function() { if (null != this.timer) clearTimeout(this.timer); this.timer = setTimeout(BX.proxy(this.__show, this), 50); } BX.CHint.prototype.__hide = function() { if (this.msover) return; if (!this.bInited) return; BX.unbind(window, 'scroll', BX.proxy(this.Reopen, this)); if (this.PARAMS.showOnce) { this.Destroy(); } else { this.DIV.style.display = 'none'; } } BX.CHint.prototype.__hide_immediately = function() { this.msover = false; this.__hide(); } BX.CHint.prototype.Init = function() { this.DIV = document.body.appendChild(BX.create('DIV', { props: {className: 'bx-panel-tooltip'}, style: {display: 'none'}, children: [ BX.create('DIV', { props: {className: 'bx-panel-tooltip-top-border'}, html: '
' }), (this.CONTENT = BX.create('DIV', { props: {className: 'bx-panel-tooltip-content'}, children: [ BX.create('DIV', { props: {className: 'bx-panel-tooltip-underlay'}, children: [ BX.create('DIV', {props: {className: 'bx-panel-tooltip-underlay-bg'}}) ] }) ] })), BX.create('DIV', { props: {className: 'bx-panel-tooltip-bottom-border'}, html: '
' }) ] })); if (this.ID) { this.CONTENT.insertBefore(BX.create('A', { attrs: {href: 'javascript:void(0)'}, props: {className: 'bx-panel-tooltip-close'}, events: {click: BX.delegate(this.Close, this)} }), this.CONTENT.firstChild) } if (this.HINT_TITLE) { this.CONTENT.appendChild( BX.create('DIV', { props: {className: 'bx-panel-tooltip-title'}, text: this.HINT_TITLE }) ) } if (this.HINT) { this.CONTENT_TEXT = this.CONTENT.appendChild(BX.create('DIV', {props: {className: 'bx-panel-tooltip-text'}})).appendChild(BX.create('SPAN', {html: this.HINT})); } if (this.PARAMS.preventHide) { BX.bind(this.DIV, 'mouseout', BX.proxy(this.Hide, this)); BX.bind(this.DIV, 'mouseover', BX.proxy(this.Show, this)); } this.bInited = true; } BX.CHint.prototype.setContent = function(content) { this.HINT = content; if (this.CONTENT_TEXT) this.CONTENT_TEXT.innerHTML = this.HINT; else this.CONTENT_TEXT = this.CONTENT.appendChild(BX.create('DIV', {props: {className: 'bx-panel-tooltip-text'}})).appendChild(BX.create('SPAN', {html: this.HINT})); } BX.CHint.prototype.prepareAdjustPos = function() { this._wnd = {scrollPos: BX.GetWindowScrollPos(),scrollSize:BX.GetWindowScrollSize()}; } BX.CHint.prototype.getAdjustPos = function() { var res = {}, pos = BX.pos(this.PARENT); res.top = pos.bottom + this.PARAMS.dx; if (BX.admin && BX.admin.panel.DIV) { var min_top = BX.admin.panel.DIV.offsetHeight + this.PARAMS.dx; if (BX.admin.panel.isFixed()) { min_top += this._wnd.scrollPos.scrollTop; } } if (res.top < min_top) res.top = min_top; else { if (res.top + this.DIV.offsetHeight > this._wnd.scrollSize.scrollHeight) res.top = pos.top - this.PARAMS.dx - this.DIV.offsetHeight; } res.left = pos.left; if (pos.left < this.PARAMS.dx) pos.left = this.PARAMS.dx; else { floatWidth = this.DIV.offsetWidth; var max_left = this._wnd.scrollSize.scrollWidth - floatWidth - this.PARAMS.dx; if (res.left > max_left) res.left = max_left; } return res; } BX.CHint.prototype.adjustWidth = function() { if (this.bWidthAdjusted) return; var w = this.DIV.offsetWidth, h = this.DIV.offsetHeight; if (w > this.PARAMS.min_width) w = Math.round(Math.sqrt(1.618*w*h)); if (w < this.PARAMS.min_width) w = this.PARAMS.min_width; this.DIV.style.width = w + "px"; if (this._adjustWidthInt) clearInterval(this._adjustWidthInt); this._adjustWidthInt = setInterval(BX.delegate(this._adjustWidthInterval, this), 5); this.bWidthAdjusted = true; } BX.CHint.prototype._adjustWidthInterval = function() { if (!this.DIV || this.DIV.style.display == 'none') clearInterval(this._adjustWidthInt); var dW = 20, maxWidth = 1500, w = this.DIV.offsetWidth, w1 = this.CONTENT_TEXT.offsetWidth; if (w > 0 && w1 > 0 && w - w1 < dW && w < maxWidth) { this.DIV.style.width = (w + dW) + "px"; return; } clearInterval(this._adjustWidthInt); } BX.CHint.prototype.adjustPos = function() { this.adjustWidth(); var pos = this.getAdjustPos(); this.DIV.style.top = pos.top + 'px'; this.DIV.style.left = pos.left + 'px'; } BX.CHint.prototype.Close = function() { if (this.ID && BX.WindowManager) BX.WindowManager.saveWindowOptions(this.ID, {display: 'off'}); this.__hide_immediately(); this.Destroy(); } BX.CHint.prototype.Destroy = function() { if (this.PARENT) { BX.unbind(this.PARENT, 'mouseover', BX.proxy(this.Show, this)); BX.unbind(this.PARENT, 'mouseout', BX.proxy(this.Hide, this)); } if (this.DIV) { BX.unbind(this.DIV, 'mouseover', BX.proxy(this.Show, this)); BX.unbind(this.DIV, 'mouseout', BX.proxy(this.Hide, this)); BX.cleanNode(this.DIV, true); } } BX.CHint.prototype.enable = function(){this.disabled = false;} BX.CHint.prototype.disable = function(){this.__hide_immediately(); this.disabled = true;} /* ready */ if (document.addEventListener) { __readyHandler = function() { document.removeEventListener("DOMContentLoaded", __readyHandler, false); runReady(); } } else if (document.attachEvent) { __readyHandler = function() { if (document.readyState === "complete") { document.detachEvent("onreadystatechange", __readyHandler); runReady(); } } } function bindReady() { if (!readyBound) { readyBound = true; if (document.readyState === "complete") { return runReady(); } if (document.addEventListener) { document.addEventListener("DOMContentLoaded", __readyHandler, false); window.addEventListener("load", runReady, false); } else if (document.attachEvent) // IE { document.attachEvent("onreadystatechange", __readyHandler); window.attachEvent("onload", runReady); var toplevel = false; try {toplevel = (window.frameElement == null);} catch(e) {} if (document.documentElement.doScroll && toplevel) doScrollCheck(); } } return null; } function runReady() { if (!BX.isReady) { if (!document.body) return setTimeout(runReady, 15); BX.isReady = true; if (readyList && readyList.length > 0) { var fn, i = 0; while (readyList && (fn = readyList[i++])) { fn.call(document); } readyList = null; } // TODO: check ready handlers binded some other way; } return null; } // hack for IE function doScrollCheck() { if (BX.isReady) return; try {document.documentElement.doScroll("left");} catch( error ) {setTimeout(doScrollCheck, 1); return;} runReady(); } /* \ready */ /* garbage collector */ function Trash() { var i,len; for (i = 0, len = garbageCollectors.length; i