1/** 2* @author JoomlaShine.com http://www.joomlashine.com 3* @copyright Copyright (C) 2008 - 2011 JoomlaShine.com. All rights reserved. 4* @license GNU/GPL v2 http://www.gnu.org/licenses/gpl-2.0.html 5*/ 6 7var JSNUtils = { 8 9 /* ============================== BROWSER ============================== */ 10 11 writeCookie: function (name,value,days){ 12 if (days) { 13 var date = new Date(); 14 date.setTime(date.getTime()+(days*24*60*60*1000)); 15 var expires = "; expires="+date.toGMTString(); 16 } else expires = ""; 17 18 document.cookie = name+"="+value+expires+"; path=/"; 19 }, 20 21 readCookie: function (name){ 22 var nameEQ = name + "="; 23 var ca = document.cookie.split(';'); 24 for(var i=0;i < ca.length;i++) { 25 var c = ca[i]; 26 while (c.charAt(0)==' ') c = c.substring(1,c.length); 27 if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length); 28 } 29 return null; 30 }, 31 32 isIE7: function() { 33 return (navigator.appVersion.indexOf("MSIE 7.")!=-1); 34 }, 35 36 getBrowserInfo: function(){ 37 var name = ''; 38 var version = ''; 39 var ua = navigator.userAgent.toLowerCase(); 40 var match = ua.match(/(opera|ie|firefox|chrome|version)[\s\/:]([\w\d\.]+)?.*?(safari|version[\s\/:]([\w\d\.]+)|$)/) || [null, 'unknown', 0]; 41 if (match[1] == 'version') 42 { 43 name = match[3]; 44 } 45 else 46 { 47 name = match[1]; 48 } 49 version = parseFloat((match[1] == 'opera' && match[4]) ? match[4] : match[2]); 50 51 return {'name': name, 'version': version}; 52 }, 53 54 /* ============================== DEVICE ============================== */ 55 56 checkMobile: function(){ 57 var mobiles = [ 58 "midp","240x320","blackberry","netfront","nokia","panasonic", 59 "portalmmm","sharp","sie-","sonyericsson","symbian", 60 "windows ce","benq","mda","mot-","opera mini", 61 "philips","pocket pc","sagem","samsung","sda", 62 "sgh-","vodafone","xda","palm","iphone", 63 "ipod","android" 64 ]; 65 var uagent = navigator.userAgent.toLowerCase(); 66 var isMobile = false; 67 68 for(var d=0;d<mobiles.length;d+=1){ 69 if(uagent.indexOf(mobiles[d])!=-1){ 70 isMobile = true; 71 } 72 } 73 74 return isMobile; 75 }, 76 77 getScreenWidth: function(){ 78 var screenWidth; 79 80 if(JSNUtils.checkMobile()) 81 { 82 screenWidth = window.screen.width; 83 } 84 else 85 { 86 if( typeof( window.innerWidth ) == 'number' ) 87 { 88 //Non-IE 89 screenWidth = window.innerWidth; 90 } 91 else if ( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) 92 { 93 //IE 6+ in 'standards compliant mode' 94 screenWidth = document.documentElement.clientWidth; 95 } 96 } 97 98 return screenWidth; 99 }, 100 101 checkSmartphone: function(){ 102 var screenWidth = JSNUtils.getScreenWidth(); 103 var isSmartphone = false; 104 105 if (screenWidth >= 320 && screenWidth < 480) 106 { 107 isSmartphone = true; 108 } 109 110 return isSmartphone; 111 }, 112 113 checkTablet: function(){ 114 var screenWidth = JSNUtils.getScreenWidth(); 115 var isTablet = false; 116 117 if (screenWidth >= 481 && screenWidth < 1024) 118 { 119 isTablet = true; 120 } 121 122 return isTablet; 123 }, 124 125 getScreenType: function(){ 126 var screenType; 127 128 if (checkSmartphone()) { 129 screenType = 'smartphone'; 130 } else if (checkTablet()) { 131 screenType = 'tablet'; 132 } else { 133 screenType = 'desktop'; 134 } 135 }, 136 137 138 /* ============================== DOM - GENERAL ============================== */ 139 140 addEvent: function(target, event, func){ 141 if (target.addEventListener){ 142 target.addEventListener(event, func, false); 143 return true; 144 } else if (target.attachEvent){ 145 var result = target.attachEvent("on"+event, func); 146 return result; 147 } else { 148 return false; 149 } 150 }, 151 152 getElementsByClass: function(targetParent, targetTag, targetClass, targetLevel){ 153 var elements, tags, tag, tagClass; 154 155 if(targetLevel == undefined){ 156 tags = targetParent.getElementsByTagName(targetTag); 157 }else{ 158 tags = JSNUtils.getChildrenAtLevel(targetParent, targetTag, targetLevel); 159 } 160 161 elements = []; 162 163 for(var i=0;i<tags.length;i++){ 164 tagClass = tags[i].className; 165 if(tagClass != "" && JSNUtils.checkSubstring(tagClass, targetClass, " ", false)){ 166 elements[elements.length] = tags[i]; 167 } 168 } 169 170 return elements; 171 }, 172 173 getFirstChild: function(targetEl, targetTagName){ 174 var nodes, node; 175 nodes = targetEl.childNodes; 176 for(var i=0;i<nodes.length;i++){ 177 node = nodes[i]; 178 if (node.tagName == targetTagName) 179 return node; 180 } 181 return null; 182 }, 183 184 getFirstChildAtLevel: function(targetEl, targetTagName, targetLevel){ 185 var child, nodes, node; 186 nodes = targetEl.childNodes; 187 for(var i=0;i<nodes.length;i++){ 188 node = nodes[i]; 189 if (targetLevel == 1) { 190 if(node.tagName == targetTagName) return node; 191 } else { 192 child = JSNUtils.getFirstChildAtLevel(node, targetTagName, targetLevel-1); 193 if(child != null) return child; 194 } 195 } 196 return null; 197 }, 198 199 getChildren: function(targetEl, targetTagName){ 200 var nodes, node; 201 var children = []; 202 nodes = targetEl.childNodes; 203 for(var i=0;i<nodes.length;i++){ 204 node = nodes[i]; 205 if(node.tagName == targetTagName) 206 children.push(node); 207 } 208 return children; 209 }, 210 211 getChildrenAtLevel: function(targetEl, targetTagName, targetLevel){ 212 var children = []; 213 var nodes, node; 214 nodes = targetEl.childNodes; 215 for(var i=0;i<nodes.length;i++){ 216 node = nodes[i]; 217 if (targetLevel == 1) { 218 if(node.tagName == targetTagName) children.push(node); 219 } else { 220 children = children.concat(JSNUtils.getChildrenAtLevel(node, targetTagName, targetLevel-1)); 221 } 222 } 223 return children; 224 }, 225 226 addClass: function(targetTag, targetClass){ 227 if(targetTag.className == ""){ 228 targetTag.className = targetClass; 229 } else { 230 if(!JSNUtils.checkSubstring(targetTag.className, targetClass, " ")){ 231 targetTag.className += " " + targetClass; 232 } 233 } 234 }, 235 236 getViewportSize: function(){ 237 var myWidth = 0, myHeight = 0; 238 239 if( typeof( window.innerWidth ) == 'number' ) { 240 //Non-IE 241 myWidth = window.innerWidth; 242 myHeight = window.innerHeight; 243 } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) { 244 //IE 6+ in 'standards compliant mode' 245 myWidth = document.documentElement.clientWidth; 246 myHeight = document.documentElement.clientHeight; 247 } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) { 248 //IE 4 compatible 249 myWidth = document.body.clientWidth; 250 myHeight = document.body.clientHeight; 251 } 252 253 return {width:myWidth, height:myHeight }; 254 }, 255 256 addURLPrefix: function(targetId) 257 { 258 var navUrl = window.location.href; 259 var targetEl = document.getElementById(targetId); 260 if(targetEl != undefined && targetEl.tagName.toUpperCase() == 'A') 261 { 262 orgHref = targetEl.href; 263 targetEl.href = navUrl + ((navUrl.indexOf(orgHref) != -1)?'':orgHref); 264 } 265 }, 266 267 /* ============================== DOM - GUI ============================== */ 268 /* ============================== DOM - GUI - MENU ============================== */ 269 270 setMobileMenu: function(menuClass) 271 { 272 var toggle = function() { 273 this.toggleClass("active"); 274 this.getNext("ul").toggleClass("jsn-menu-mobile"); 275 276 $$("." + menuClass + " .jsn-menu-toggle").each(function (item) { 277 var a = item.getPrevious(), 278 size = a.getSize(); 279 280 item.setStyle('height', size.y); 281 }); 282 }; 283 284 // Setup toggle for main trigger 285 $$("." + menuClass).getPrevious(".jsn-menu-toggle").addEvent('click', toggle); 286 287 // Setup toggle for children triggers 288 $$("." + menuClass + " .jsn-menu-toggle").addEvent('click', toggle); 289 }, 290 291 setMobileSitetool: function() 292 { 293 var siteToolPanel = $("jsn-sitetoolspanel"); 294 if (siteToolPanel) 295 { 296 siteToolPanel.getElements("li.jsn-sitetool-control").addEvent("click", function() { 297 this.toggleClass("active"); 298 }); 299 } 300 }, 301 302 getSelectMenuitemIndex: function(elementID) 303 { 304 var childs = ($(elementID).childNodes); 305 var count = childs.length; 306 var index = 0; 307 308 for (var i = 0; i < count; i++) 309 { 310 if(childs[i].className != undefined && childs[i].className.indexOf('parent') != -1) 311 { 312 if(childs[i].className.indexOf('active') != -1) 313 { 314 return index; 315 } 316 index++; 317 } 318 } 319 return -1; 320 }, 321 322 createImageMenu: function(menuId, imageClass){ 323 if (!document.getElementById) return; 324 325 var list = document.getElementById(menuId); 326 var listItems; 327 328 var listItem; 329 330 if(list != undefined) { 331 listItems = list.getElementsByTagName("LI"); 332 for(i=0, j=0;i<listItems.length;i++){ 333 listItem = listItems[i]; 334 if (listItem.parentNode == list) { 335 listItem.className += " " + imageClass + (j+1); 336 j++; 337 } 338 } 339 } 340 }, 341 342 /* Set position of side menu sub panels */ 343 setSidemenuLayout: function(menuClass, rtlLayout) 344 { 345 var sidemenus, sidemenu, smChildren, smChild, smSubmenu; 346 sidemenus = JSNUtils.getElementsByClass(document, "UL", menuClass); 347 if (sidemenus != undefined) { 348 for(var i=0;i<sidemenus.length;i++){ 349 sidemenu = sidemenus[i]; 350 smChildren = JSNUtils.getChildren(sidemenu, "LI"); 351 if (smChildren != undefined) { 352 for(var j=0;j<smChildren.length;j++){ 353 smChild = smChildren[j]; 354 smSubmenu = JSNUtils.getFirstChild(smChild, "UL"); 355 if (smSubmenu != null) { 356 if(rtlLayout == true) { smSubmenu.style.marginRight = smChild.offsetWidth+"px"; } 357 else { smSubmenu.style.marginLeft = smChild.offsetWidth+"px"; } 358 } 359 } 360 } 361 } 362 } 363 }, 364 365 /* Set position of sitetools sub panel */ 366 setSitetoolsLayout: function(sitetoolsId, rtlLayout) 367 { 368 var sitetoolsContainer, parentItem, sitetoolsPanel, neighbour; 369 sitetoolsContainer = document.getElementById(sitetoolsId); 370 if (sitetoolsContainer != undefined) { 371 parentItem = JSNUtils.getFirstChild(sitetoolsContainer, "LI"); 372 sitetoolsPanel = JSNUtils.getFirstChild(parentItem, "UL"); 373 if (rtlLayout == true) { 374 sitetoolsPanel.style.marginRight = -1*(sitetoolsPanel.offsetWidth - parentItem.offsetWidth) + "px"; 375 } else { 376 sitetoolsPanel.style.marginLeft = -1*(sitetoolsPanel.offsetWidth - parentItem.offsetWidth) + "px"; 377 } 378 } 379 }, 380 381 /* Change template setting stored in cookie */ 382 setTemplateAttribute: function(templatePrefix, attribute, value) 383 { 384 JSNUtils.writeCookie(templatePrefix+attribute,value); 385 window.location.reload(true); 386 }, 387 388 createExtList: function(listClass, extTag, className, includeNumber){ 389 if (!document.getElementById) return; 390 391 var lists = JSNUtils.getElementsByClass(document, "UL", listClass); 392 var list; 393 var listItems; 394 var listItem; 395 396 if(lists != undefined) { 397 for(j=0;j<lists.length;j++){ 398 list = lists[j]; 399 listItems = JSNUtils.getChildren(list, "LI"); 400 for(i=0,k=0;i<listItems.length;i++){ 401 listItem = listItems[i]; 402 if(className !=''){ 403 listItem.innerHTML = '<'+ extTag + ' class='+className+'>' + (includeNumber?(k+1):'') + '</'+ extTag +'>' + listItem.innerHTML; 404 }else{ 405 listItem.innerHTML = '<'+ extTag + '>' + (includeNumber?(k+1):'') + '</'+ extTag +'>' + listItem.innerHTML; 406 }
407 k++; 408 } 409 } 410 } 411 }, 412 413 createGridLayout: function(containerTag, containerClass, columnClass, lastcolumnClass) { 414 var gridLayouts, gridLayout, gridColumns, gridColumn, columnsNumber; 415 gridLayouts = JSNUtils.getElementsByClass(document, containerTag, containerClass); 416 for(var i=0;i<gridLayouts.length;i++){ 417 gridLayout = gridLayouts[i]; 418 gridColumns = JSNUtils.getChildren(gridLayout, containerTag); 419 columnsNumber = gridColumns.length; 420 JSNUtils.addClass(gridLayout, containerClass + columnsNumber); 421 JSNUtils.addClass(gridLayout, 'clearafter'); 422 for(var j=0;j<columnsNumber;j++){ 423 gridColumn = gridColumns[j]; 424 JSNUtils.addClass(gridColumn, columnClass); 425 if(j == gridColumns.length-1) { 426 JSNUtils.addClass(gridColumn, lastcolumnClass); 427 } 428 gridColumn.innerHTML = '<div class="' + columnClass + '_inner">' + gridColumn.innerHTML + '</div>'; 429 } 430 } 431 }, 432 433 sfHover: function(menuId, menuDelay) { 434 if(menuId == undefined) return; 435 436 var delay = (menuDelay == undefined)?0:menuDelay; 437 var pEl = document.getElementById(menuId); 438 if (pEl != undefined) { 439 var sfEls = pEl.getElementsByTagName("li"); 440 for (var i=0; i<sfEls.length; ++i) { 441 sfEls[i].onmouseover=function() { 442 clearTimeout(this.timer); 443 if(this.className.indexOf("sfhover") == -1) { 444 this.className += " sfhover"; 445 } 446 } 447 sfEls[i].onmouseout=function() { 448 this.timer = setTimeout(JSNUtils.sfHoverOut.bind(this), delay); 449 } 450 } 451 } 452 }, 453 454 sfHoverOut: function() { 455 clearTimeout(this.timer); 456 this.className=this.className.replace(new RegExp(" sfhover\\b"), ""); 457 }, 458 459 setFontSize: function (targetId, fontSize){ 460 var targetObj = (document.getElementById) ? document.getElementById(targetId) : document.all(targetId); 461 targetObj.style.fontSize = fontSize + '%'; 462 }, 463 464 setVerticalPosition: function(pName, pAlignment) { 465 var targetElement = document.getElementById(pName); 466 467 if (targetElement != undefined) { 468 var topDelta, vpHeight, pHeight; 469 vpHeight = (JSNUtils.getViewportSize()).height; 470 pHeight = targetElement.offsetHeight; 471 switch(pAlignment){ 472 case "top": 473 topDelta = 0; 474 break; 475 476 case "middle": 477 topDelta = Math.floor((100 - Math.round((pHeight/vpHeight)*100))/2); 478 break; 479 480 case "bottom": 481 topDelta = 100 - Math.round((pHeight/vpHeight)*100); 482 break; 483 } 484 485 topDelta = (topDelta < 0)?0:topDelta; 486 487 targetElement.style.top = topDelta + "%"; 488 489 targetElement.style.visibility = "visible"; 490 } 491 }, 492 493 setInnerLayout:function(elements) 494 { 495 var pleftWidth = 0; 496 var pinnerleftWidth = 0; 497 var prightWidth = 0; 498 var pinnerrightWidth = 0; 499 var root = document.getElementById(elements[0]); 500 var rootWidth = root.offsetWidth; 501 if(document.getElementById(elements[1]) != null) { 502 pleftWidth = document.getElementById(elements[1]).offsetWidth; 503 } 504 if(document.getElementById(elements[3]) != null) { 505 pinnerleftWidth = document.getElementById(elements[3]).offsetWidth; 506 var resultLeft = (pleftWidth + pinnerleftWidth)*100/rootWidth; 507 root.firstChild.style.right = (100 - resultLeft) + "%"; 508 root.firstChild.firstChild.style.left = (100 - resultLeft) + "%"; 509 } 510 if(document.getElementById(elements[2]) != null) { 511 prightWidth = document.getElementById(elements[2]).offsetWidth; 512 } 513 if(document.getElementById(elements[4]) != null) { 514 pinnerrightWidth = document.getElementById(elements[4]).offsetWidth; 515 var resultRight = (prightWidth + pinnerrightWidth)*100/rootWidth; 516 root.firstChild.firstChild.firstChild.style.left = (100 - resultRight) + "%"; 517 root.firstChild.firstChild.firstChild.firstChild.style.right = (100 - resultRight) + "%"; 518 } 519 }, 520 521 setEqualHeight: function() 522 { 523 var containerClass = "jsn-horizontallayout"; 524 var columnClass = "jsn-modulecontainer_inner"; 525 var horizontallayoutObjs = $$('.'+containerClass); 526 var maxHeight = 0; 527 Array.each(horizontallayoutObjs, function(item) { 528 var columns = item.getElements('.'+columnClass); 529 maxHeight = 0; 530 Array.each(columns, function(col) { 531 var coordinates = col.getCoordinates(); 532 if (coordinates.height > maxHeight) maxHeight = coordinates.height; 533 }); 534 Array.each(columns, function(col) { 535 col.setStyle('height',maxHeight); 536 }); 537 }); 538 }, 539 540 541 /* ============================== MOOTOOLS ANIMATION ============================== */ 542 543 setToTopLinkCenter: function(rtl, jquery) 544 { 545 /* Min distance to be away from top for the link to be displayed */ 546 var min = 200; 547 548 /* Determine RTL layout or not to set margin correctly */ 549 var marginFrom = "margin-left"; 550 if (rtl === true) { 551 marginFrom = "margin-right"; 552 } 553 554 if (jquery) { 555 var element = $j('#jsn-gotoplink'); 556 var marginValue = ($j(window).width() - element.width() - element.css('padding-left').replace('px', '')*2)/2; 557 558 element.css(marginFrom, marginValue + 'px'); 559 element.hide(); 560 ($j(window).scrollTop() >= min) ? element.fadeIn() : element.fadeOut(); 561 } else if (typeof(MooTools) != 'undefined') { 562 var element = $('jsn-gotoplink'); 563 var marginValue = (window.getSize().x - element.getSize().x)/2; 564 565 element.setStyle('display', 'block'); 566 element.setStyle(marginFrom, marginValue + 'px'); 567 568 element.set('opacity','0'); 569 element.fade((window.getScroll().y >= min) ? 'in' : 'out'); 570 element.fade((window.getScroll().y >= min) ? 1 : 0); 571 } 572 }, 573 574 setSmoothScroll: function(jquery) 575 {
576 var objBrowser = JSNUtils.getBrowserInfo(); 577 578 // Setup smooth go to top link 579 if (jquery) { 580 $j('#jsn-gotoplink').click(function() { 581 var gotoplinkOffset = $j('#top').offset().top; 582 $j('html,body').animate({scrollTop: gotoplinkOffset}, 500); 583 return false; 584 }); 585 } else if (typeof(MooTools) != 'undefined') { 586 new SmoothScroll({ duration:300 }, window); 587 } 588 }, 589 590 setFadeScroll: function(jquery) 591 { 592 var min = 200; 593 if (jquery) { 594 var element = $j('#jsn-gotoplink'); 595 if(element == null) return false; 596 597 $j(window).scroll(function () { 598 ($j(window).scrollTop() >= min) ? element.fadeIn() : element.fadeOut(); 599 }); 600 } else if (typeof(MooTools) != 'undefined') { 601 var element = $('jsn-gotoplink'); 602 if (element == null) return false; 603 if (parseFloat(MooTools.version) < 1.2) 604 { 605 var fx = new Fx.Style(element, "opacity", {duration: 500}); 606 var inside = false; 607 window.addEvent('scroll',function(e) { 608 var position = window.getSize().scroll; 609 var y = position.y; 610 if (y >= min) 611 { 612 if (!inside) 613 { 614 inside = true; 615 fx.start(0, 1); 616 } 617 } 618 else 619 { 620 if (inside) 621 { 622 inside = false;
623 fx.start(1, 0); 624 } 625 } 626 }.bind(this)); 627 } 628 else 629 { 630 window.addEvent('scroll',function(e) { 631 element.fade((window.getScroll().y >= min) ? 'in' : 'out'); 632 element.fade((window.getScroll().y >= min) ? 1 : 0); 633 }.bind(this)); 634 } 635 } 636 }, 637 638 /* ============================== TEXT ============================== */ 639 640 checkSubstring: function(targetString, targetSubstring, delimeter, wholeWord){ 641 if(wholeWord == undefined) wholeWord = false; 642 var parts = targetString.split(delimeter); 643 for (var i = 0; i < parts.length; i++){ 644 if (wholeWord && parts[i] == targetSubstring) return true; 645 if (!wholeWord && parts[i].indexOf(targetSubstring) > -1) return true; 646 } 647 return false; 648 }, 649 650 /* ============================== REMOVE DUPLICATE CSS3 TAG IN IE7 - CSS3 PIE ============================== */ 651 652 removeCss3Duplicate: function(className) 653 { 654 var element = $$('.' + className); 655 if (element != undefined) 656 { 657 element.each(function(e){ 658 var elementParent = e.getParent(); 659 var duplicateTag = elementParent.getChildren('css3-container'); 660 if (duplicateTag.length && duplicateTag.length > 1) 661 { 662 elementParent.removeChild(duplicateTag[0]); 663 } 664 }); 665 } 666 } 667};
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.