1/** 2Core script to handle the entire theme and core functions 3**/ 4var Biblos = function () { 5 6 // IE mode 7 var isRTL = false; 8 var isIE8 = false; 9 var isIE9 = false; 10 var isIE10 = false; 11 12 var resizeHandlers = []; 13 14 var assetsPath = ROOT_URL +'/assets/'; 15 16 var globalImgPath = assetsPath + 'global/img/'; 17 18 // theme layout color set 19 20 var brandColors = { 21 'blue': '#89C4F4', 22 'red': '#F3565D', 23 'green': '#1bbc9b', 24 'purple': '#9b59b6', 25 'grey': '#95a5a6', 26 'yellow': '#F8CB00' 27 }; 28 29 // initializes main settings 30 var handleInit = function () { 31 32 if ($('body').css('direction') === 'rtl') { 33 isRTL = true; 34 } 35 36 isIE8 = !! navigator.userAgent.match(/MSIE 8.0/); 37 isIE9 = !! navigator.userAgent.match(/MSIE 9.0/); 38 isIE10 = !! navigator.userAgent.match(/MSIE 10.0/); 39 40 if (isIE10) { 41 $('html').addClass('ie10'); // detect IE10 version 42 } 43 44 if (isIE10 || isIE9 || isIE8) { 45 $('html').addClass('ie'); // detect IE10 version 46 } 47 } 48 49 // runs callback functions set by Biblos.addResponsiveHandler(). 50 var _runResizeHandlers = function () { 51 // reinitialize other subscribed elements 52 for (var i = 0; i < resizeHandlers.length; i++) { 53 var each = resizeHandlers[i]; 54 each.call(); 55 } 56 } 57 58 // handle the layout reinitialization on window resize 59 var handleOnResize = function () { 60 var resize; 61 if (isIE8) { 62 var currheight; 63 $(window).resize(function () { 64 if (currheight == document.documentElement.clientHeight) { 65 return; //quite event since only body resized not window. 66 } 67 if (resize) { 68 clearTimeout(resize); 69 } 70 resize = setTimeout(function () { 71 _runResizeHandlers(); 72 }, 50); // wait 50ms until window resize finishes. 73 currheight = document.documentElement.clientHeight; // store last body client height 74 }); 75 } else { 76 $(window).resize(function () { 77 if (resize) { 78 clearTimeout(resize); 79 } 80 resize = setTimeout(function () { 81 _runResizeHandlers(); 82 }, 50); // wait 50ms until window resize finishes. 83 }); 84 } 85 } 86 87 // Handles portlet tools & actions 88 var handlePortletTools = function () { 89 $('body').on('click', '.portlet > .portlet-title > .tools > a.remove', function (e) { 90 e.preventDefault(); 91 $(this).closest(".portlet").remove(); 92 }); 93 94 $('body').on('click', '.portlet > .portlet-title > .tools > a.reload', function (e) { 95 e.preventDefault(); 96 var el = $(this).closest(".portlet").children(".portlet-body"); 97 var url = $(this).attr("data-url"); 98 var error = $(this).attr("data-error-display"); 99 if (url) { 100 Biblos.blockUI({target: el, iconOnly: true}); 101 $.ajax({ 102 type: "GET", 103 cache: false, 104 url: url, 105 dataType: "html", 106 success: function(res) 107 { 108 Biblos.unblockUI(el); 109 el.html(res); 110 }, 111 error: function(xhr, ajaxOptions, thrownError) 112 { 113 Biblos.unblockUI(el); 114 var msg = 'Error on reloading the content. Please check your connection and try again.'; 115 if (error == "toastr" && toastr) { 116 toastr.error(msg); 117 } else if (error == "notific8" && $.notific8) { 118 $.notific8('zindex', 11500); 119 $.notific8(msg, {theme: 'ruby', life: 3000}); 120 } else { 121 alert(msg); 122 } 123 } 124 }); 125 } else { 126 // for demo purpose 127 Biblos.blockUI({target: el, iconOnly: true}); 128 window.setTimeout(function () { 129 Biblos.unblockUI(el); 130 }, 1000); 131 } 132 }); 133 134 // load ajax data on page init 135 $('.portlet .portlet-title a.reload[data-load="true"]').click(); 136 137 $('body').on('click', '.portlet > .portlet-title > .tools > .collapse, .portlet .portlet-title > .tools > .expand', function (e) { 138 e.preventDefault(); 139 var el = $(this).closest(".portlet").children(".portlet-body"); 140 if ($(this).hasClass("collapse")) { 141 $(this).removeClass("collapse").addClass("expand"); 142 el.slideUp(200); 143 } else { 144 $(this).removeClass("expand").addClass("collapse"); 145 el.slideDown(200); 146 } 147 }); 148 } 149 150 // Handles custom checkboxes & radios using jQuery Uniform plugin 151 var handleUniform = function () { 152 if (!$().uniform) { 153 return; 154 } 155 var test = $("input[type=checkbox]:not(.toggle, .make-switch), input[type=radio]:not(.toggle, .star, .make-switch)"); 156 if (test.length > 0) { 157 test.each(function () { 158 if ($(this).parents(".checker").length == 0) { 159 $(this).show(); 160 $(this).uniform(); 161 } 162 }); 163 } 164 } 165 166 var handleBootstrapSwitch = function () { 167 if (!$().bootstrapSwitch) { 168 return; 169 } 170 $('.make-switch').bootstrapSwitch(); 171 } 172 173 // Handles Bootstrap Accordions. 174 var handleAccordions = function () { 175 $('body').on('shown.bs.collapse', '.accordion.scrollable', function (e) { 176 Biblos.scrollTo($(e.target)); 177 }); 178 } 179 180 // Handles Bootstrap Tabs. 181 var handleTabs = function() { 182 //activate tab if tab id provided in the URL 183 if (encodeURI(location.hash)) { 184 var tabid = encodeURI(location.hash.substr(1)); 185 $('a[href="#' + tabid + '"]').parents('.tab-pane:hidden').each(function() { 186 var tabid = $(this).attr("id"); 187 $('a[href="#' + tabid + '"]').click(); 188 }); 189 $('a[href="#' + tabid + '"]').click(); 190 } 191 192 if ($().tabdrop) { 193 $('.tabbable-tabdrop .nav-pills, .tabbable-tabdrop .nav-tabs').tabdrop({ 194 text: '<i class="fa fa-ellipsis-v"></i> <i class="fa fa-angle-down"></i>' 195 }); 196 } 197 }; 198 199 // Handles Bootstrap Modals. 200 var handleModals = function () { 201 // fix stackable modal issue: when 2 or more modals opened, closing one of modal will remove .modal
201-open class. 202 $('body').on('hide.bs.modal', function () { 203 if ($('.modal:visible').length > 1 && $('html').hasClass('modal-open') == false) { 204 $('html').addClass('modal-open'); 205 } else if ($('.modal:visible').length <= 1) { 206 $('html').removeClass('modal-open'); 207 } 208 }); 209 210 $('body').on('show.bs.modal', '.modal', function () { 211 if ($(this).hasClass("modal-scroll")) { 212 $('body').addClass("modal-open-noscroll"); 213 } 214 }); 215 216 $('body').on('hide.bs.modal', '.modal', function () { 217 $('body').removeClass("modal-open-noscroll"); 218 }); 219 } 220 221 // Handles Bootstrap Tooltips. 222 var handleTooltips = function () { 223 $('.tooltips').tooltip(); 224 } 225 226 // Handles Bootstrap Dropdowns 227 var handleDropdowns = function () { 228 /* 229 Hold dropdown on click 230 */ 231 $('body').on('click', '.dropdown-menu.hold-on-click', function (e) { 232 e.stopPropagation(); 233 }); 234 } 235 236 var handleAlerts = function () { 237 $('body').on('click', '[data-close="alert"]', function(e){ 238 $(this).parent('.alert').hide(); 239 e.preventDefault(); 240 }); 241 } 242 243 // Handle Hower Dropdowns 244 var handleDropdownHover = function () { 245 $('[data-hover="dropdown"]').dropdownHover(); 246 } 247 248 // Handles Bootstrap Popovers 249 250 // last popep popover 251 var lastPopedPopover; 252 253 var handlePopovers = function () { 254 $('.popovers').popover(); 255 256 // close last displayed popover 257 258 $(document).on('click.bs.popover.data-api', function (e) { 259 if (lastPopedPopover) { 260 lastPopedPopover.popover('hide'); 261 } 262 }); 263 } 264 265 // Handles scrollable contents using jQuery SlimScroll plugin. 266 var handleScrollers = function () { 267 Biblos.initSlimScroll('.scroller'); 268 } 269 270 // Handles Image Preview using jQuery Fancybox plugin 271 var handleFancybox = function () { 272 if (!jQuery.fancybox) { 273 return; 274 } 275 276 if ($(".fancybox-button").length > 0) { 277 $(".fancybox-button").fancybox({ 278 groupAttr: 'data-rel', 279 prevEffect: 'none', 280 nextEffect: 'none', 281 closeBtn: true, 282 helpers: { 283 title: { 284 type: 'inside' 285 } 286 } 287 }); 288 } 289 } 290 291 // Fix input placeholder issue for IE8 and IE9 292 var handleFixInputPlaceholderForIE = function () { 293 //fix html5 placeholder attribute for ie7 & ie8 294 if (isIE8 || isIE9) { // ie8 & ie9 295 // this is html5 placeholder fix for inputs, inputs with placeholder-no-fix class will be skipped(e.g: we need this for password fields) 296 $('input[placeholder]:not(.placeholder-no-fix), textarea[placeholder]:not(.placeholder-no-fix)').each(function () { 297 var input = $(this); 298 299 if (input.val() == '' && input.attr("placeholder") != '') { 300 input.addClass("placeholder").val(input.attr('placeholder')); 301 } 302 303 input.focus(function () { 304 if (input.val() == input.attr('placeholder')) { 305 input.val(''); 306 } 307 }); 308 309 input.blur(function () { 310 if (input.val() == '' || input.val() == input.attr('placeholder')) { 311 input.val(input.attr('placeholder')); 312 } 313 }); 314 }); 315 } 316 } 317 318 // Handle Select2 Dropdowns 319 var handleSelect2 = function() { 320 if ($().select2) { 321 $('.select2me').select2({ 322 placeholder: "Select", 323 allowClear: true 324 }); 325 } 326 } 327 328 //* END:CORE HANDLERS *// 329 330 return { 331 332 //main function to initiate the theme 333 init: function () { 334 //IMPORTANT!!!: Do not modify the core handlers call order. 335 336 //Core handlers 337 handleInit(); // initialize core variables 338 handleOnResize(); // set and handle responsive 339 340 //UI Component handlers 341 handleUniform(); // hanfle custom radio & checkboxes 342 handleBootstrapSwitch(); // handle bootstrap switch plugin 343 handleScrollers(); // handles slim scrolling contents 344 handleFancybox() // handle fancy box 345 handleSelect2(); // handle custom Select2 dropdowns 346 handlePortletTools(); // handles portlet action bar functionality(refresh, configure, toggle, remove) 347 handleAlerts(); //handle closabled alerts 348 handleDropdowns(); // handle dropdowns 349 handleTabs(); // handle tabs 350 handleTooltips(); // handle bootstrap tooltips 351 handlePopovers(); // handles bootstrap popovers 352 handleAccordions(); //handles accordions 353 handleModals(); // handle modals 354 355 // Hacks 356 handleFixInputPlaceholderForIE(); //IE8 & IE9 input placeholder issue fix 357 }, 358
359 //main function to initiate core javascript after ajax complete 360 initAjax: function () { 361 handleScrollers(); // handles slim scrolling contents 362 handleSelect2(); // handle custom Select2 dropdowns 363 handleDropdowns(); // handle dropdowns 364 handleTooltips(); // handle bootstrap tooltips 365 handlePopovers(); // handles bootstrap popovers 366 handleAccordions(); //handles accordions 367 handleUniform(); // hanfle custom radio & checkboxes 368 handleBootstrapSwitch(); // handle bootstrap switch plugin 369 handleDropdownHover() // handles dropdown hover 370 }, 371 372 //public function to remember last opened popover that needs to be closed on click 373 setLastPopedPopover: function (el) { 374 lastPopedPopover = el; 375 }, 376 377 //public function to add callback a function which will be called on window resize 378 addResizeHandler: function (func) { 379 resizeHandlers.push(func); 380 }, 381 382 //public functon to call _runresizeHandlers 383 runResizeHandlers: function() { 384 _runResizeHandlers(); 385 }, 386 387 // wrBibloser function to scroll(focus) to an element 388 scrollTo: function (el, offeset) { 389 var pos = (el && el.length > 0) ? el.offset().top : 0; 390 391 if (el) { 392 if ($('body').hasClass('page-header-fixed')) { 393 pos = pos - $('.page-header').height(); 394 } 395 pos = pos + (offeset ? offeset : -1 * el.height()); 396 } 397 398 $('html,body').animate({ 399 scrollTop: pos 400 }, 'slow'); 401 }, 402 403 initSlimScroll: function(el) { 404 $(el).each(function () { 405 if ($(this).attr("data-initialized")) { 406 return; // exit 407 } 408 var height; 409 if ($(this).attr("data-height")) { 410 height = $(this).attr("data-height"); 411 } else { 412 height = $(this).css('height'); 413 } 414 415 $(this).slimScroll({ 416 allowPageScroll: true, // allow page scroll when the element scroll is ended 417 size: '7px', 418 color: ($(this).attr("data-handle-color") ? $(this).attr("data-handle-color") : '#bbb'), 419 wrapperClass: ($(this).attr("data-wrapper-class") ? $(this).attr("data-wrapper-class") : 'slimScrollDiv'), 420 railColor: ($(this).attr("data-rail-color") ? $(this).attr("data-rail-color") : '#eaeaea'), 421 position: isRTL ? 'left' : 'right', 422 height: height, 423 alwaysVisible: ($(this).attr("data-always-visible") == "1" ? true : false), 424 railVisible: ($(this).attr("data-rail-visible") == "1" ? true : false), 425 disableFadeOut: true 426 }); 427 $(this).attr("data-initialized", "1"); 428 }); 429 }, 430 431 destroySlimScroll: function(el) { 432 $(el).each(function () { 433 if ($(this).attr("data-initialized") === "1") { // destroy existing instance before updating the height 434 $(this).removeAttr("data-initialized"); 435 $(this).removeAttr("style"); 436 437 var attrList = {}; 438 439 // store the custom attribures so later we will reassign. 440 if ($(this).attr("data-handle-color")) { 441 attrList["data-handle-color"] = $(this).attr("data-handle-color"); 442 } 443 if ($(this).attr("data-wrapper-class")) { 444 attrList["data-wrapper-class"] = $(this).attr("data-wrapper-class"); 445 } 446 if ($(this).attr("data-rail-color")) { 447 attrList["data-rail-color"] = $(this).attr("data-rail-color"); 448 } 449 if ($(this).attr("data-always-visible")) { 450 attrList["data-always-visible"] = $(this).attr("data-always-visible"); 451 } 452 if ($(this).attr("data-rail-visible")) { 453 attrList["data-rail-visible"] = $(this).attr("data-rail-visible"); 454 } 455 456 $(this).slimScroll({ 457 wrapperClass: ($(this).attr("data-wrapper-class") ? $(this).attr("data-wrapper-class") : 'slimScrollDiv'), 458 destroy: true 459 }); 460 461 var the = $(this); 462 463 // reassign custom attributes 464 $.each(attrList, function (key, value) { 465 the.attr(key, value); 466 }); 467 } 468 }); 469 }, 470 471 // function to scroll to the top 472 scrollTop: function () { 473 Biblos.scrollTo(); 474 }, 475 476 // wrBibloser function to block element(indicate loading) 477 blockUI: function (options) { 478 var options = $.extend(true, {}, options); 479 var html = ''; 480 if (options.iconOnly) { 481 html = '<div class="loading-message ' + (options.boxed ? 'loading-message-boxed' : '')+'"><img src="' + this.getGlobalImgPath() + 'loading-spinner-grey.gif" align=""></div>'; 482 } else if (options.textOnly) { 483 html = '<div class="loading-message ' + (options.boxed ? 'loading-message-boxed' : '')+'"><span> ' + (options.message ? options.message : 'LOADING...') + '</span></div>'; 484 } else { 485 html = '<div class="loading-message ' + (options.boxed ? 'loading-message-boxed' : '')+'"><img src="' + this.getGlobalImgPath() + 'loading-spinner-grey.gif" align=""><span> ' + (options.message ? options.message : 'LOADING...') + '</span></div>'; 486 } 487 488 if (options.target) { // element blocking 489 var el = $(options.target); 490 if (el.height() <= ($(window).height())) { 491 options.cenrerY = true; 492 } 493 el.block({ 494 message: html, 495 baseZ: options.zIndex ? options.zIndex : 1000, 496 centerY: options.cenrerY != undefined ? options.cenrerY : false, 497 css: { 498 top: '10%', 499 border: '0', 500 padding: '0', 501 backgroundColor: 'none' 502 }, 503 overlayCSS: { 504 backgroundColor: options.overlayColor ? options.overlayColor : '#000', 505 opacity: options.boxed ? 0.05 : 0.1, 506 cursor: 'wait' 507 } 508 }); 509 } else { // page blocking 510 $.blockUI({ 511 message: html, 512 baseZ: options.zIndex ? options.zIndex : 1000, 513 css: { 514 border: '0', 515 padding: '0', 516 backgroundColor: 'none' 517 }, 518 overlayCSS: { 519 backgroundColor: options.overlayColor ? options.overlayColor : '#000', 520 opacity: options.boxed ? 0.05 : 0.1, 521 cursor: 'wait' 522 } 523 }); 524 } 525 }, 526 527 // wrBibloser function to un-block element(finish loading) 528 unblockUI: function (target) { 529 if (target) { 530 $(target).unblock({ 531 onUnblock: function () { 532 $(target).css('position', ''); 533 $(target).css('zoom', ''); 534 } 535 }); 536 } else { 537 $.unblockUI(); 538 } 539 }, 540 541 startPageLoading: function(message) { 542 $('.page-loading').remove(); 543 $('body').append('<div class="page-loading"><img src="' + this.getGlobalImgPath() + 'loading-spinner-grey.gif"/> <span>' + (message ? message : 'Loading...') + '</span></div>'); 544 }, 545 546 stopPageLoading: function() { 547 $('.page-loading').remove(); 548 }, 549 550 alert: function(options) { 551 552 options = $.extend(true, { 553 container: "", // alerts parent container(by default placed after the page breadcrumbs) 554 place: "append", // append or prepent in container 555 type: 'success', // alert's type 556 message: "", // alert's message 557 close: true, // make alert closable 558 reset: true, // close all previouse alerts first 559 focus: true, // auto scroll to the alert after shown 560 closeInSeconds: 0, // auto close after defined seconds 561 icon: "" // put icon before the message 562 }, options); 563 564 var id = Biblos.getUniqueID("Biblos_alert"); 565 566 var html = '<div id="'+id+'" class="Biblos-alerts alert alert-'+options.type+' fade in">' + (options.close ? '<button type="button" class="close" data-dismiss="alert" aria-hidden="true"></button>' : '' ) + (options.icon != "" ? '<i class="fa-lg fa fa-'+options.icon + '"></i> ' : '') + options.message+'</div>' 567 568 if (options.reset) {0 569 $('.Biblos-alerts').remove(); 570 } 571 572 if (!options.container) { 573 $('.page-breadcrumb').after(html); 574 } else { 575 if (options.place == "append") { 576 $(options.container).append(html); 577 } else { 578 $(options.container).prepend(html); 579 } 580 } 581 582 if (options.focus) { 583 Biblos.scrollTo($('#' + id)); 584 } 585 586 if (options.closeInSeconds > 0) { 587 setTimeout(function(){ 588 $('#' + id).remove(); 589 }, options.closeInSeconds * 1000); 590 } 591 592 return id; 593 }, 594 595 // initializes uniform elements 596 initUniform: function (els) { 597 if (els) { 598 $(els).each(function () { 599 if ($(this).parents(".checker").length == 0) { 600 $(this).show(); 601 $(this).uniform(); 602 } 603 }); 604 } else { 605 handleUniform(); 606 } 607 }, 608 609 //wrBibloser function to update/sync jquery uniform checkbox & radios 610 updateUniform: function (els) { 611 $.uniform.update(els); // update the uniform checkbox & radios UI after the actual input control state changed 612 }, 613 614 //public function to initialize the fancybox plugin 615 initFancybox: function () { 616 handleFancybox(); 617 }, 618 619 //public helper function to get actual input value(used in IE9 and IE8 due to placeholder attribute not supported) 620 getActualVal: function (el) { 621 var el = $(el); 622 if (el.val() === el.attr("placeholder")) { 623 return ""; 624 } 625 return el.val(); 626 }, 627 628 //public function to get a paremeter by name from URL 629 getURLParameter: function (paramName) { 630 var searchString = window.location.search.substring(1), 631 i, val, params = searchString.split("&"); 632 633 for (i = 0; i < params.length; i++) { 634 val = params[i].split("="); 635 if (val[0] == paramName) { 636 return unescape(val[1]); 637 } 638 } 639 return null; 640 }, 641 642 // check for device touch support 643 isTouchDevice: function () { 644 try { 645 document.createEvent("TouchEvent"); 646 return true; 647 } catch (e) { 648 return false;
649 } 650 }, 651 652 // To get the correct viewport width based on http://andylangton.co.uk/articles/javascript/get-viewport-size-javascript/ 653 getViewPort: function () { 654 var e = window, a = 'inner'; 655 if (!('innerWidth' in window)) { 656 a = 'client'; 657 e = document.documentElement || document.body; 658 } 659 return { 660 width: e[a + 'Width'], 661 height: e[a + 'Height'] 662 } 663 }, 664 665 getUniqueID: function(prefix) { 666 return 'prefix_' + Math.floor(Math.random() * (new Date()).getTime()); 667 }, 668 669 // check IE8 mode 670 isIE8: function () { 671 return isIE8; 672 }, 673 674 // check IE9 mode 675 isIE9: function () { 676 return isIE9; 677 }, 678 679 //check RTL mode 680 isRTL: function () { 681 return isRTL; 682 }, 683 684 getAssetsPath: function () { 685 return assetsPath; 686 }, 687 688 setAssetsPath: function(path) { 689 assetsPath = path; 690 }, 691 692 getGlobalImgPath: function () { 693 return globalImgPath; 694 }, 695 696 // get layout color code by color name 697 getBrandColor: function (name) { 698 if (brandColors[name]) { 699 return brandColors[name]; 700 } else { 701 return ''; 702 } 703 }, 704 705 706 707 }; 708 709}();
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.