Конфликт 2х плагинов JS
Как убрать конфликт ? Слыхал о jQuery.noConflict(); но не знаю как пользоваться.
<script src="http://code.jquery.com/jquery-latest.js"></script> <script type="text/javascript" src="./js/utils.js"></script> <script type="text/javascript" src="./js/my_tooltip.js"></script> <script type="text/javascript" src="./js/my_tooltip.js"></script> /* My tooltip lib */ var config = new Object(); config. width = 0 // Tooltip width, 0 for auto config. OffsetX = 40 // Horizontal offset of left-top corner from mousepointer config. OffsetY = -30 // Vertical offset config. Sticky = true // Move or not while shown config. Border = true // Show border config. step = 15 // Opacity step time config. timeUp = 0 // Show opacity time config. timeDown = 300 // Hide opacity time tt_aV = new Array(); // Caches and enumerates config data for currently active tooltip // Mouse data var tt_musX = 0, tt_musY = 0; // tip data var tt_opaTimer = new Number(0), tt_mainDiv = 0, // Main div tt_subDiv = 0, // Main sub div - for opacity tt_status = 0, // Status & 1 - tip shown/hide tt_element = 0, // onmouseover element for hide tooltip tt_opacity = 0, // Current sub div opacity tt_isIE = 0, tt_currentTip = -1, tt_loading_text = '<div class=loading_new> </div>'; function tt_hrefTip() { if (!this.id) return; if (this.firstChild.tagName=='IMG') ajaxTip(this.id); else ajaxTip(this.id, STICKY, false); } function Tip() { tt_currentTip = -1; tt_Tip(arguments); } function tt_Tip(arg) { tt_ReadCmds(arg); tt_UpdateTip(arg[0]); tt_updatePosition(); tt_startShowTip(); } function tt_updateTipData(id, text) { if (tt_currentTip != id) return; if ((tt_status & 1) == 0) return; tt_UpdateTip(text); setOpacity(tt_subDiv, tt_opacity); tt_updatePosition(); } function tt_opaStepUp(step) { tt_opacity+=(100*step/tt_aV[TIMEUP]); if (tt_opacity < 100) tt_opaTimer.Timer("tt_opaStepUp(" + step + ")", step, true); else {tt_opaTimer.EndTimer();tt_opacity = 100;} setOpacity(tt_subDiv, tt_opacity); } function tt_opaStepDown(step) { tt_opacity-=(100*step/tt_aV[TIMEDOWN]); if (tt_opacity > 0) tt_opaTimer.Timer("tt_opaStepDown(" + step + ")", step, true); else {tt_opaTimer.EndTimer();tt_finishHideTip();} setOpacity(tt_subDiv, tt_opacity); } function tt_startShowTip() { tt_opaTimer.EndTimer(); if (tt_element) { removeEvent(tt_element, "mouseout", tt_Hide); tt_element = 0; } tt_status|=1; tt_mainDiv.style.visibility = "visible"; if (tt_aV[TIMEUP]) { tt_opacity = 0; tt_opaStepUp(tt_aV[STEP]); } else { tt_opacity = 100; setOpacity(tt_subDiv, tt_opacity); } } function tt_startHideTip() { tt_opaTimer.EndTimer(); tt_status&=~1; if (tt_aV[TIMEDOWN]) tt_opaStepDown(tt_aV[STEP]); else tt_finishHideTip(); } function tt_finishHideTip() { tt_mainDiv.style.visibility = "hidden"; tt_opacity = 0; } function tt_updatePosition() { var p = getPageRect(), width = tt_subDiv.offsetWidth, height= tt_subDiv.offsetHeight, max_x = p.left + p.width - width, max_y = p.top + p.height - height, x = tt_musX + tt_aV[OFFSETX], y = tt_musY + tt_aV[OFFSETY]; if (x >= max_x) x = max_x; if (y >= max_y) y = max_y; var inX_ByX = (tt_musX > x && tt_musX < x + width); var inY_ByY = (tt_musY > y && tt_musY < y + height); if (inX_ByX && inY_ByY) { x = tt_musX - width - tt_aV[OFFSETX]; x = x<p.left?p.left:x; inX_ByX = (tt_musX > x && tt_musX < x + width); if (inX_ByX) y = tt_musY - height - tt_aV[OFFSETY]; } var css = tt_mainDiv.style; css.left = (x<p.left?p.left:x) + 'px'; css.top = (y<p.top?p.top:y) + 'px'; } function tt_UpdateTip(text) { if (tt_aV[BORDER]) { var tt_tipBody = $('tt_tip_body'); tt_mainDiv.innerHTML = '' + '<div id=tt_tooltip_new>' + '<table class=tooltip_new cellSpacing=0 cellPadding=0><tbody>' + '<tr><td class=tiptopl></td><td class=tiptop></td><td class=tiptopr></td></tr>' + '<tr><td class=tipl> </td><td class=tipbody id=tt_tip_body><div id=ttcontent>' + text + '</div></td><td class=tipr> </td></tr>' + '<tr><td class=tipbottoml></td><td class=tipbottom></td><td class=tipbottomr></td></tr>' + '</tbody></table></div>'; tt_subDiv = $('tt_tooltip_new'); tt_subDiv.style.width = tt_aV[WIDTH] ? tt_aV[WIDTH] + 'px' : 'auto'; } else tt_mainDiv.innerHTML = '' + '<div id=tt_tooltip_new>' + text + '</div>'; tt_subDiv = $('tt_tooltip_new'); tt_subDiv.style.width = tt_aV[WIDTH] ? tt_aV[WIDTH] + 'px' : 'auto'; } function tt_Hide(e) { e = window.event || e; if (!e) return; var target = e.target || e.srcElement; if (tt_element == target) { removeEvent(tt_element, "mouseout", tt_Hide); tt_element = 0; tt_startHideTip(); } } function tt_Move(e) { e = window.event || e; if (!e) return; var b = document.body || document.documentElement; tt_musX = e.pageX || (e.clientX + b.scrollLeft); tt_musY = e.pageY || (e.clientY + b.scrollTop); if (tt_element == 0 && tt_status & 1) { tt_element = e.target || e.srcElement; addEvent(tt_element, "mouseout", tt_Hide); } if (!tt_aV[STICKY] && tt_status&1) tt_updatePosition(); } function Init() { // Create the tooltip DIV tt_mainDiv = insertElement(getBody(), 'DIV','tt_mytooltip_new'); tt_mainDiv.style.position = "absolute"; tt_mainDiv.style.zIndex = 1000; tt_MkCmdEnum(); addEvent(document, "mousemove", tt_Move); tt_finishHideTip(); } // Creates command names by translating config variable names to upper case function tt_MkCmdEnum() { var n = 0; for(var i in config) eval("window." + i.toString().toUpperCase() + " = " + n++); } function tt_ReadCmds(a) { var i=0; // First load the global config values, to initialize also values // for which no command has been passed for(var j in config) tt_aV[i++] = config[j]; // Then replace each cached config value for which a command has been // passed (ensure the # of command args plus value args be even) if(a.length & 1) { for(i = a.length - 1; i > 0; i -= 2) tt_aV[a[i - 1]] = a[i]; return true; } tt_Err("Incorrect call of Tip() or ajaxTip().\n" + "Each command must be followed by a value."); return false; } Init(); |
<script type="text/javascript" src="./js/utils.js"></script>
// // Custom project scripts // function $() { var elements = new Array(); for (var i = 0; i < arguments.length; i++) { var element = arguments[i]; if (typeof element == 'string') element = document.getElementById(element); if (arguments.length == 1) return element; elements.push(element); } return elements; } function getElementsByClass(searchClass,node,tag) { var classElements = new Array(); if ( node == null ) node = document; if ( tag == null ) tag = '*'; var els = node.getElementsByTagName(tag); var pattern = new RegExp("(^|\\s)" + searchClass + "(\\s|$)"); for (i = 0; i < els.length; i++) if ( pattern.test(els[i].className) ) classElements.push(els[i]); return classElements; } function getBody(){ return document.body||document.documentElement||(document.getElementsByTagName ? document.getElementsByTagName("body")[0] : null); } function getPageRect(){ var b = document.body || document.documentElement, sTop = window.pageYOffset || b.scrollTop, sLeft = window.pageXOffset || b.scrollLeft, sWidth= b.clientWidth || window.innerWidth, sHeight= b.clientHeight || window.innerHeight, oWidth= b.scrollWidth || b.offsetWidth, oHeight= b.scrollHeight || b.offsetHeight; return {top: sTop, left: sLeft, width: sWidth, height: sHeight, scrollX: oWidth, scrollY: oHeight}; } function getBounds(e) { var left = e.offsetLeft, top = e.offsetTop, width = e.offsetWidth, height = e.offsetHeight; while (e = e.offsetParent){ left += e.offsetLeft; top += e.offsetTop; } return {left: left, top: top, width: width, height: height}; } function insertElement(parent, tag, id) { if(parent.insertAdjacentHTML) { parent.insertAdjacentHTML("afterBegin", '<'+tag+ ' id="'+id+'"></'+tag+'>'); return document.getElementById(id); } else if(document.createElement && parent.appendChild) { var el = document.createElement(tag); el.id = id; parent.appendChild(el); return el; } return 0; } function addEvent(el, sEvt, PFnc) { if(el) { if(el.addEventListener) el.addEventListener(sEvt, PFnc, false); else el.attachEvent("on" + sEvt, PFnc); } } function addLoadEvent(func) { var oldonload = window.onload; if (typeof window.onload != 'function') window.onload = func; else window.onload = function(){oldonload();func();} } function removeEvent(el, sEvt, PFnc) { if(el) { if(el.removeEventListener) el.removeEventListener(sEvt, PFnc, false); else el.detachEvent("on" + sEvt, PFnc); } } function ChangeCssProperty(myclass, element, value) { var CSSRules = document.styleSheets[0].rules || document.styleSheets[0].cssRules; for (var i = 0; i < CSSRules.length; i++) if (CSSRules[i].selectorText.toLowerCase() == myclass.toLowerCase()) CSSRules[i].style[element] = value; } function getOpaSettings() { var p = null; var s = document.body.style; if (typeof s.opacity == 'string') p = 'opacity'; else if (typeof s.MozOpacity == 'string') p = 'MozOpacity'; else if (typeof s.KhtmlOpacity == 'string') p = 'KhtmlOpacity'; else if (document.body.filters && navigator.appVersion.match(/MSIE ([\d.]+);/)[1]>=5.5) p='filter'; return p; } function setOpacity(oElem, nOpacity) { var p = getOpaSettings(); if (p=='filter') setOpacity = new Function('oElem', 'nOpacity', 'if (nOpacity >= 100) {oElem.style.filter = ""; return;} var oAlpha = oElem.filters["DXImageTransform.Microsoft.alpha"] || oElem.filters.alpha; if (oAlpha) oAlpha.opacity = nOpacity;else {oElem.style.zoom = 1;oElem.style.filter = "progid:DXImageTransform.Microsoft.Alpha(opacity="+nOpacity+")";}'); else if (p) setOpacity = new Function('oElem', 'nOpacity', 'oElem.style.'+p+' = nOpacity/100;'); else setOpacity = new Function(oElem, nOpacity); return setOpacity(oElem, nOpacity); } function getOpacity(oElem) { var p = getOpaSettings(); if (p=='filter') getOpacity = new Function('oElem', 'var m = oElem.style.filter.match(/alpha\(opacity=(.+)\)/i); return m ? parseFloat(m[1]) : 1;'); else if (p) getOpacity = new Function('oElem', 'var v = oElem.style.'+p+'; return v*100;'); else getOpacity = new Function(oElem); return getOpacity(oElem); } Number.prototype.Timer = function(s, iT, bUrge){ this.EndTimer(); if(!this.value || bUrge) this.value = window.setTimeout(s, iT); } Number.prototype.EndTimer = function(){ if(this.value){ window.clearTimeout(this.value); this.value = 0; } } |
Проблема решена вставил <script>var $j = jQuery.noConflict();</script> в конец скриптов.
|
Часовой пояс GMT +3, время: 04:22. |