selectSrchInit.js 40 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122
  1. /**
  2. Core script to handle the entire theme and core functions
  3. **/
  4. var selectSrchInit = function () {
  5. // IE mode
  6. var isRTL = false;
  7. var isIE8 = false;
  8. var isIE9 = false;
  9. var isIE10 = false;
  10. var sidebarWidth = 225;
  11. var sidebarCollapsedWidth = 35;
  12. var responsiveHandlers = [];
  13. // theme layout color set
  14. var layoutColorCodes = {
  15. 'blue': '#4b8df8',
  16. 'red': '#e02222',
  17. 'green': '#35aa47',
  18. 'purple': '#852b99',
  19. 'grey': '#555555',
  20. 'light-grey': '#fafafa',
  21. 'yellow': '#ffb848'
  22. };
  23. // To get the correct viewport width based on http://andylangton.co.uk/articles/javascript/get-viewport-size-javascript/
  24. var _getViewPort = function () {
  25. var e = window, a = 'inner';
  26. if (!('innerWidth' in window)) {
  27. a = 'client';
  28. e = document.documentElement || document.body;
  29. }
  30. return {
  31. width: e[a + 'Width'],
  32. height: e[a + 'Height']
  33. }
  34. }
  35. // initializes main settings
  36. var handleInit = function () {
  37. if ($('body').css('direction') === 'rtl') {
  38. isRTL = true;
  39. }
  40. isIE8 = !! navigator.userAgent.match(/MSIE 8.0/);
  41. isIE9 = !! navigator.userAgent.match(/MSIE 9.0/);
  42. isIE10 = !! navigator.userAgent.match(/MSIE 10.0/);
  43. if (isIE10) {
  44. jQuery('html').addClass('ie10'); // detect IE10 version
  45. }
  46. if (isIE10 || isIE9 || isIE8) {
  47. jQuery('html').addClass('ie'); // detect IE10 version
  48. }
  49. /*
  50. Virtual keyboards:
  51. Also, note that if you're using inputs in your modal – iOS has a rendering bug which doesn't
  52. update the position of fixed elements when the virtual keyboard is triggered
  53. */
  54. var deviceAgent = navigator.userAgent.toLowerCase();
  55. if (deviceAgent.match(/(iphone|ipod|ipad)/)) {
  56. $(document).on('focus', 'input, textarea', function () {
  57. $('.header').hide();
  58. $('.footer').hide();
  59. });
  60. $(document).on('blur', 'input, textarea', function () {
  61. $('.header').show();
  62. $('.footer').show();
  63. });
  64. }
  65. }
  66. var handleSidebarState = function () {
  67. // remove sidebar toggler if window width smaller than 992(for tablet and phone mode)
  68. var viewport = _getViewPort();
  69. if (viewport.width < 992) {
  70. $('body').removeClass("page-sidebar-closed");
  71. }
  72. }
  73. // runs callback functions set by App.addResponsiveHandler().
  74. var runResponsiveHandlers = function () {
  75. // reinitialize other subscribed elements
  76. for (var i in responsiveHandlers) {
  77. var each = responsiveHandlers[i];
  78. each.call();
  79. }
  80. }
  81. // reinitialize the laypot on window resize
  82. var handleResponsive = function () {
  83. handleSidebarState();
  84. handleSidebarAndContentHeight();
  85. handleFixedSidebar();
  86. runResponsiveHandlers();
  87. }
  88. // initialize the layout on page load
  89. var handleResponsiveOnInit = function () {
  90. handleSidebarState();
  91. handleSidebarAndContentHeight();
  92. }
  93. // handle the layout reinitialization on window resize
  94. var handleResponsiveOnResize = function () {
  95. var resize;
  96. if (isIE8) {
  97. var currheight;
  98. $(window).resize(function () {
  99. if (currheight == document.documentElement.clientHeight) {
  100. return; //quite event since only body resized not window.
  101. }
  102. if (resize) {
  103. clearTimeout(resize);
  104. }
  105. resize = setTimeout(function () {
  106. handleResponsive();
  107. }, 50); // wait 50ms until window resize finishes.
  108. currheight = document.documentElement.clientHeight; // store last body client height
  109. });
  110. } else {
  111. $(window).resize(function () {
  112. if (resize) {
  113. clearTimeout(resize);
  114. }
  115. resize = setTimeout(function () {
  116. handleResponsive();
  117. }, 50); // wait 50ms until window resize finishes.
  118. });
  119. }
  120. }
  121. //* BEGIN:CORE HANDLERS *//
  122. // this function handles responsive layout on screen size resize or mobile device rotate.
  123. // Set proper height for sidebar and content. The content and sidebar height must be synced always.
  124. var handleSidebarAndContentHeight = function () {
  125. var content = $('.page-content');
  126. var sidebar = $('.page-sidebar');
  127. var body = $('body');
  128. var height;
  129. if (body.hasClass("page-footer-fixed") === true && body.hasClass("page-sidebar-fixed") === false) {
  130. var available_height = $(window).height() - $('.footer').outerHeight();
  131. if (content.height() < available_height) {
  132. content.attr('style', 'min-height:' + available_height + 'px !important');
  133. }
  134. } else {
  135. if (body.hasClass('page-sidebar-fixed')) {
  136. height = _calculateFixedSidebarViewportHeight();
  137. } else {
  138. height = sidebar.height() + 20;
  139. }
  140. if (height >= content.height()) {
  141. content.attr('style', 'min-height:' + height + 'px !important');
  142. }
  143. }
  144. }
  145. // Handle sidebar menu
  146. var handleSidebarMenu = function () {
  147. jQuery('.page-sidebar').on('click', 'li > a', function (e) {
  148. if ($(this).next().hasClass('sub-menu') == false) {
  149. if ($('.btn-navbar').hasClass('collapsed') == false) {
  150. $('.btn-navbar').click();
  151. }
  152. return;
  153. }
  154. if ($(this).next().hasClass('sub-menu.always-open')) {
  155. return;
  156. }
  157. var parent = $(this).parent().parent();
  158. var the = $(this);
  159. parent.children('li.open').children('a').children('.arrow').removeClass('open');
  160. parent.children('li.open').children('.sub-menu').slideUp(200);
  161. parent.children('li.open').removeClass('open');
  162. var sub = jQuery(this).next();
  163. var slideOffeset = -200;
  164. var slideSpeed = 200;
  165. if (sub.is(":visible")) {
  166. jQuery('.arrow', jQuery(this)).removeClass("open");
  167. jQuery(this).parent().removeClass("open");
  168. sub.slideUp(slideSpeed, function () {
  169. if ($('body').hasClass('page-sidebar-fixed') == false && $('body').hasClass('page-sidebar-closed') == false) {
  170. selectSrchInit.scrollTo(the, slideOffeset);
  171. }
  172. handleSidebarAndContentHeight();
  173. });
  174. } else {
  175. jQuery('.arrow', jQuery(this)).addClass("open");
  176. jQuery(this).parent().addClass("open");
  177. sub.slideDown(slideSpeed, function () {
  178. if ($('body').hasClass('page-sidebar-fixed') == false && $('body').hasClass('page-sidebar-closed') == false) {
  179. selectSrchInit.scrollTo(the, slideOffeset);
  180. }
  181. handleSidebarAndContentHeight();
  182. });
  183. }
  184. e.preventDefault();
  185. });
  186. // handle ajax links
  187. jQuery('.page-sidebar').on('click', ' li > a.ajaxify', function (e) {
  188. e.preventDefault();
  189. selectSrchInit.scrollTop();
  190. var url = $(this).attr("href");
  191. var menuContainer = jQuery('.page-sidebar ul');
  192. var pageContent = $('.page-content');
  193. var pageContentBody = $('.page-content .page-content-body');
  194. menuContainer.children('li.active').removeClass('active');
  195. menuContainer.children('arrow.open').removeClass('open');
  196. $(this).parents('li').each(function () {
  197. $(this).addClass('active');
  198. $(this).children('a > span.arrow').addClass('open');
  199. });
  200. $(this).parents('li').addClass('active');
  201. selectSrchInit.blockUI(pageContent, false);
  202. $.ajax({
  203. type: "GET",
  204. cache: false,
  205. url: url,
  206. dataType: "html",
  207. success: function (res) {
  208. selectSrchInit.unblockUI(pageContent);
  209. pageContentBody.html(res);
  210. selectSrchInit.fixContentHeight(); // fix content height
  211. selectSrchInit.initAjax(); // initialize core stuff
  212. },
  213. error: function (xhr, ajaxOptions, thrownError) {
  214. pageContentBody.html('<h4>Could not load the requested content.</h4>');
  215. selectSrchInit.unblockUI(pageContent);
  216. },
  217. async: false
  218. });
  219. });
  220. }
  221. // Helper function to calculate sidebar height for fixed sidebar layout.
  222. var _calculateFixedSidebarViewportHeight = function () {
  223. var sidebarHeight = $(window).height() - $('.header').height() + 1;
  224. if ($('body').hasClass("page-footer-fixed")) {
  225. sidebarHeight = sidebarHeight - $('.footer').outerHeight();
  226. }
  227. return sidebarHeight;
  228. }
  229. // Handles fixed sidebar
  230. var handleFixedSidebar = function () {
  231. var menu = $('.page-sidebar-menu');
  232. if (menu.parent('.slimScrollDiv').size() === 1) { // destroy existing instance before updating the height
  233. menu.slimScroll({
  234. destroy: true
  235. });
  236. menu.removeAttr('style');
  237. $('.page-sidebar').removeAttr('style');
  238. }
  239. if ($('.page-sidebar-fixed').size() === 0) {
  240. handleSidebarAndContentHeight();
  241. return;
  242. }
  243. var viewport = _getViewPort();
  244. if (viewport.width >= 992) {
  245. var sidebarHeight = _calculateFixedSidebarViewportHeight();
  246. menu.slimScroll({
  247. size: '7px',
  248. color: '#a1b2bd',
  249. opacity: .3,
  250. position: isRTL ? 'left' : 'right',
  251. height: sidebarHeight,
  252. allowPageScroll: false,
  253. disableFadeOut: false
  254. });
  255. handleSidebarAndContentHeight();
  256. }
  257. }
  258. // Handles the sidebar menu hover effect for fixed sidebar.
  259. var handleFixedSidebarHoverable = function () {
  260. if ($('body').hasClass('page-sidebar-fixed') === false) {
  261. return;
  262. }
  263. $('.page-sidebar').off('mouseenter').on('mouseenter', function () {
  264. var body = $('body');
  265. if ((body.hasClass('page-sidebar-closed') === false || body.hasClass('page-sidebar-fixed') === false) || $(this).hasClass('page-sidebar-hovering')) {
  266. return;
  267. }
  268. body.removeClass('page-sidebar-closed').addClass('page-sidebar-hover-on');
  269. if (body.hasClass("page-sidebar-reversed")) {
  270. $(this).width(sidebarWidth);
  271. } else {
  272. $(this).addClass('page-sidebar-hovering');
  273. $(this).animate({
  274. width: sidebarWidth
  275. }, 400, '', function () {
  276. $(this).removeClass('page-sidebar-hovering');
  277. });
  278. }
  279. });
  280. $('.page-sidebar').off('mouseleave').on('mouseleave', function () {
  281. var body = $('body');
  282. if ((body.hasClass('page-sidebar-hover-on') === false || body.hasClass('page-sidebar-fixed') === false) || $(this).hasClass('page-sidebar-hovering')) {
  283. return;
  284. }
  285. if (body.hasClass("page-sidebar-reversed")) {
  286. $('body').addClass('page-sidebar-closed').removeClass('page-sidebar-hover-on');
  287. $(this).width(sidebarCollapsedWidth);
  288. } else {
  289. $(this).addClass('page-sidebar-hovering');
  290. $(this).animate({
  291. width: sidebarCollapsedWidth
  292. }, 400, '', function () {
  293. $('body').addClass('page-sidebar-closed').removeClass('page-sidebar-hover-on');
  294. $(this).removeClass('page-sidebar-hovering');
  295. });
  296. }
  297. });
  298. }
  299. // Handles sidebar toggler to close/hide the sidebar.
  300. var handleSidebarToggler = function () {
  301. var viewport = _getViewPort();
  302. if ($.cookie('sidebar_closed') === '1' && viewport.width >= 992) {
  303. $('body').addClass('page-sidebar-closed');
  304. }
  305. // handle sidebar show/hide
  306. $('.page-sidebar, .header').on('click', '.sidebar-toggler', function (e) {
  307. var body = $('body');
  308. var sidebar = $('.page-sidebar');
  309. if ((body.hasClass("page-sidebar-hover-on") && body.hasClass('page-sidebar-fixed')) || sidebar.hasClass('page-sidebar-hovering')) {
  310. body.removeClass('page-sidebar-hover-on');
  311. sidebar.css('width', '').hide().show();
  312. handleSidebarAndContentHeight(); //fix content & sidebar height
  313. $.cookie('sidebar_closed', '0');
  314. e.stopPropagation();
  315. runResponsiveHandlers();
  316. return;
  317. }
  318. $(".sidebar-search", sidebar).removeClass("open");
  319. if (body.hasClass("page-sidebar-closed")) {
  320. body.removeClass("page-sidebar-closed");
  321. if (body.hasClass('page-sidebar-fixed')) {
  322. sidebar.css('width', '');
  323. }
  324. $.cookie('sidebar_closed', '0');
  325. } else {
  326. body.addClass("page-sidebar-closed");
  327. $.cookie('sidebar_closed', '1');
  328. }
  329. handleSidebarAndContentHeight(); //fix content & sidebar height
  330. runResponsiveHandlers();
  331. });
  332. // handle the search bar close
  333. $('.page-sidebar').on('click', '.sidebar-search .remove', function (e) {
  334. e.preventDefault();
  335. $('.sidebar-search').removeClass("open");
  336. });
  337. // handle the search query submit on enter press
  338. $('.page-sidebar .sidebar-search').on('keypress', 'input.form-control', function (e) {
  339. if (e.which == 13) {
  340. $('.sidebar-search').submit();
  341. return false; //<---- Add this line
  342. }
  343. });
  344. // handle the search submit(for sidebar search and responsive mode of the header search)
  345. $('.sidebar-search .submit').on('click', function (e) {
  346. e.preventDefault();
  347. if ($('body').hasClass("page-sidebar-closed")) {
  348. if ($('.sidebar-search').hasClass('open') == false) {
  349. if ($('.page-sidebar-fixed').size() === 1) {
  350. $('.page-sidebar .sidebar-toggler').click(); //trigger sidebar toggle button
  351. }
  352. $('.sidebar-search').addClass("open");
  353. } else {
  354. $('.sidebar-search').submit();
  355. }
  356. } else {
  357. $('.sidebar-search').submit();
  358. }
  359. });
  360. // header search box:
  361. // handle the search query submit on enter press
  362. $('.header .search-form').on('keypress', 'input.form-control', function (e) {
  363. if (e.which == 13) {
  364. $('.sidebar-search').submit();
  365. return false; //<---- Add this line
  366. }
  367. });
  368. //handle header search button click
  369. $('.header .search-form .submit').on('click', function (e) {
  370. e.preventDefault();
  371. $('.header .search-form').submit();
  372. });
  373. }
  374. // Handles the horizontal menu
  375. var handleHorizontalMenu = function () {
  376. //handle hor menu search form toggler click
  377. $('.header').on('click', '.hor-menu .hor-menu-search-form-toggler', function (e) {
  378. if ($(this).hasClass('off')) {
  379. $(this).removeClass('off');
  380. $('.header .hor-menu .search-form').hide();
  381. } else {
  382. $(this).addClass('off');
  383. $('.header .hor-menu .search-form').show();
  384. }
  385. e.preventDefault();
  386. });
  387. //handle tab click
  388. $('.header').on('click', '.hor-menu a[data-toggle="tab"]', function (e) {
  389. e.preventDefault();
  390. var nav = $(".hor-menu .nav");
  391. var active_link = nav.find('li.current');
  392. $('li.active', active_link).removeClass("active");
  393. $('.selected', active_link).remove();
  394. var new_link = $(this).parents('li').last();
  395. new_link.addClass("current");
  396. new_link.find("a:first").append('<span class="selected"></span>');
  397. });
  398. //handle hor menu search button click
  399. $('.header').on('click', '.hor-menu .search-form .btn', function (e) {
  400. $('.form-search').submit();
  401. e.preventDefault();
  402. });
  403. //handle hor menu search form on enter press
  404. $('.header').on('keypress', '.hor-menu .search-form input', function (e) {
  405. if (e.which == 13) {
  406. $('.form-search').submit();
  407. return false;
  408. }
  409. });
  410. }
  411. // Handles the go to top button at the footer
  412. var handleGoTop = function () {
  413. /* set variables locally for increased performance */
  414. jQuery('.footer').on('click', '.go-top', function (e) {
  415. selectSrchInit.scrollTo();
  416. e.preventDefault();
  417. });
  418. }
  419. // Handles portlet tools & actions
  420. var handlePortletTools = function () {
  421. jQuery('body').on('click', '.portlet > .portlet-title > .tools > a.remove', function (e) {
  422. e.preventDefault();
  423. jQuery(this).closest(".portlet").remove();
  424. });
  425. jQuery('body').on('click', '.portlet > .portlet-title > .tools > a.reload', function (e) {
  426. e.preventDefault();
  427. var el = jQuery(this).closest(".portlet").children(".portlet-body");
  428. selectSrchInit.blockUI(el);
  429. window.setTimeout(function () {
  430. selectSrchInit.unblockUI(el);
  431. }, 1000);
  432. });
  433. jQuery('body').on('click', '.portlet > .portlet-title > .tools > .collapse, .portlet .portlet-title > .tools > .expand', function (e) {
  434. e.preventDefault();
  435. var el = jQuery(this).closest(".portlet").children(".portlet-body");
  436. if (jQuery(this).hasClass("collapse")) {
  437. jQuery(this).removeClass("collapse").addClass("expand");
  438. el.slideUp(200);
  439. } else {
  440. jQuery(this).removeClass("expand").addClass("collapse");
  441. el.slideDown(200);
  442. }
  443. });
  444. }
  445. // Handles custom checkboxes & radios using jQuery Uniform plugin
  446. var handleUniform = function () {
  447. if (!jQuery().uniform) {
  448. return;
  449. }
  450. var test = $("input[type=checkbox]:not(.toggle), input[type=radio]:not(.toggle, .star)");
  451. if (test.size() > 0) {
  452. test.each(function () {
  453. if ($(this).parents(".checker").size() == 0) {
  454. $(this).show();
  455. $(this).uniform();
  456. }
  457. });
  458. }
  459. }
  460. // Handles Bootstrap Accordions.
  461. var handleAccordions = function () {
  462. var lastClicked;
  463. //add scrollable class name if you need scrollable panes
  464. jQuery('body').on('click', '.accordion.scrollable .accordion-toggle', function () {
  465. lastClicked = jQuery(this);
  466. }); //move to faq section
  467. jQuery('body').on('show.bs.collapse', '.accordion.scrollable', function () {
  468. jQuery('html,body').animate({
  469. scrollTop: lastClicked.offset().top - 150
  470. }, 'slow');
  471. });
  472. }
  473. // Handles Bootstrap Tabs.
  474. var handleTabs = function () {
  475. // fix content height on tab click
  476. $('body').on('shown.bs.tab', '.nav.nav-tabs', function () {
  477. handleSidebarAndContentHeight();
  478. });
  479. //activate tab if tab id provided in the URL
  480. if (location.hash) {
  481. var tabid = location.hash.substr(1);
  482. $('a[href="#' + tabid + '"]').parents('.tab-pane:hidden').each(function(){
  483. var tabid = $(this).attr("id");
  484. $('a[href="#' + tabid + '"]').click();
  485. });
  486. $('a[href="#' + tabid + '"]').click();
  487. }
  488. }
  489. // Handles Bootstrap Modals.
  490. var handleModals = function () {
  491. // fix stackable modal issue: when 2 or more modals opened, closing one of modal will remove .modal-open class.
  492. $('body').on('hide.bs.modal', function () {
  493. if ($('.modal:visible').size() > 1 && $('html').hasClass('modal-open') == false) {
  494. $('html').addClass('modal-open');
  495. } else if ($('.modal:visible').size() <= 1) {
  496. $('html').removeClass('modal-open');
  497. }
  498. });
  499. $('body').on('show.bs.modal', '.modal', function () {
  500. if ($(this).hasClass("modal-scroll")) {
  501. $('body').addClass("modal-open-noscroll");
  502. }
  503. });
  504. $('body').on('hide.bs.modal', '.modal', function () {
  505. $('body').removeClass("modal-open-noscroll");
  506. });
  507. }
  508. // Handles Bootstrap Tooltips.
  509. var handleTooltips = function () {
  510. //jQuery('.tooltips').tooltip();
  511. }
  512. // Handles Bootstrap Dropdowns
  513. var handleDropdowns = function () {
  514. /*
  515. For touch supported devices disable the
  516. hoverable dropdowns - data-hover="dropdown"
  517. */
  518. if (selectSrchInit.isTouchDevice()) {
  519. $('[data-hover="dropdown"]').each(function(){
  520. $(this).parent().off("hover");
  521. $(this).off("hover");
  522. });
  523. }
  524. /*
  525. Hold dropdown on click
  526. */
  527. $('body').on('click', '.dropdown-menu.hold-on-click', function (e) {
  528. e.stopPropagation();
  529. });
  530. }
  531. // Handle Hower Dropdowns
  532. var handleDropdownHover = function () {
  533. $('[data-hover="dropdown"]').dropdownHover();
  534. }
  535. var handleAlerts = function () {
  536. $('body').on('click', '[data-close="alert"]', function(e){
  537. $(this).parent('.alert').hide();
  538. e.preventDefault();
  539. });
  540. }
  541. // Handles Bootstrap Popovers
  542. // last popep popover
  543. var lastPopedPopover;
  544. var handlePopovers = function () {
  545. //jQuery('.popovers').popover();
  546. // close last poped popover
  547. $(document).on('click.bs.popover.data-api', function (e) {
  548. if (lastPopedPopover) {
  549. lastPopedPopover.popover('hide');
  550. }
  551. });
  552. }
  553. // Handles scrollable contents using jQuery SlimScroll plugin.
  554. var handleScrollers = function () {
  555. $('.scroller').each(function () {
  556. var height;
  557. if ($(this).attr("data-height")) {
  558. height = $(this).attr("data-height");
  559. } else {
  560. height = $(this).css('height');
  561. }
  562. $(this).slimScroll({
  563. size: '7px',
  564. color: ($(this).attr("data-handle-color") ? $(this).attr("data-handle-color") : '#a1b2bd'),
  565. railColor: ($(this).attr("data-rail-color") ? $(this).attr("data-rail-color") : '#333'),
  566. position: isRTL ? 'left' : 'right',
  567. height: height,
  568. alwaysVisible: ($(this).attr("data-always-visible") == "1" ? true : false),
  569. railVisible: ($(this).attr("data-rail-visible") == "1" ? true : false),
  570. disableFadeOut: true
  571. });
  572. });
  573. }
  574. // Handles Image Preview using jQuery Fancybox plugin
  575. var handleFancybox = function () {
  576. if (!jQuery.fancybox) {
  577. return;
  578. }
  579. if (jQuery(".fancybox-button").size() > 0) {
  580. jQuery(".fancybox-button").fancybox({
  581. groupAttr: 'data-rel',
  582. prevEffect: 'none',
  583. nextEffect: 'none',
  584. closeBtn: true,
  585. helpers: {
  586. title: {
  587. type: 'inside'
  588. }
  589. }
  590. });
  591. }
  592. }
  593. // Fix input placeholder issue for IE8 and IE9
  594. var handleFixInputPlaceholderForIE = function () {
  595. //fix html5 placeholder attribute for ie7 & ie8
  596. if (isIE8 || isIE9) { // ie8 & ie9
  597. // this is html5 placeholder fix for inputs, inputs with placeholder-no-fix class will be skipped(e.g: we need this for password fields)
  598. jQuery('input[placeholder]:not(.placeholder-no-fix), textarea[placeholder]:not(.placeholder-no-fix)').each(function () {
  599. var input = jQuery(this);
  600. if (input.val() == '' && input.attr("placeholder") != '') {
  601. input.addClass("placeholder").val(input.attr('placeholder'));
  602. }
  603. input.focus(function () {
  604. if (input.val() == input.attr('placeholder')) {
  605. input.val('');
  606. }
  607. });
  608. input.blur(function () {
  609. if (input.val() == '' || input.val() == input.attr('placeholder')) {
  610. input.val(input.attr('placeholder'));
  611. }
  612. });
  613. });
  614. }
  615. }
  616. // Handle full screen mode toggle
  617. var handleFullScreenMode = function() {
  618. // mozfullscreenerror event handler
  619. // toggle full screen
  620. function toggleFullScreen() {
  621. if (!document.fullscreenElement && // alternative standard method
  622. !document.mozFullScreenElement && !document.webkitFullscreenElement) { // current working methods
  623. if (document.documentElement.requestFullscreen) {
  624. document.documentElement.requestFullscreen();
  625. } else if (document.documentElement.mozRequestFullScreen) {
  626. document.documentElement.mozRequestFullScreen();
  627. } else if (document.documentElement.webkitRequestFullscreen) {
  628. document.documentElement.webkitRequestFullscreen(Element.ALLOW_KEYBOARD_INPUT);
  629. }
  630. } else {
  631. if (document.cancelFullScreen) {
  632. document.cancelFullScreen();
  633. } else if (document.mozCancelFullScreen) {
  634. document.mozCancelFullScreen();
  635. } else if (document.webkitCancelFullScreen) {
  636. document.webkitCancelFullScreen();
  637. }
  638. }
  639. }
  640. $('#trigger_fullscreen').click(function() {
  641. toggleFullScreen();
  642. });
  643. }
  644. // Handle Select2 Dropdowns
  645. var handleSelect2 = function() {
  646. if (jQuery().selectSrchFun) {
  647. $('.sp-select-srch').selectSrchFun({
  648. placeholder: "Select",
  649. allowClear: true
  650. });
  651. }
  652. }
  653. // Handle Theme Settings
  654. var handleTheme = function () {
  655. var panel = $('.theme-panel');
  656. if ($('body').hasClass('page-boxed') == false) {
  657. $('.layout-option', panel).val("fluid");
  658. }
  659. $('.sidebar-option', panel).val("default");
  660. $('.header-option', panel).val("fixed");
  661. $('.footer-option', panel).val("default");
  662. if ( $('.sidebar-pos-option').attr("disabled") === false) {
  663. $('.sidebar-pos-option', panel).val(selectSrchInit.isRTL() ? 'right' : 'left');
  664. }
  665. //handle theme layout
  666. var resetLayout = function () {
  667. $("body").
  668. removeClass("page-boxed").
  669. removeClass("page-footer-fixed").
  670. removeClass("page-sidebar-fixed").
  671. removeClass("page-header-fixed").
  672. removeClass("page-sidebar-reversed");
  673. $('.header > .header-inner').removeClass("container");
  674. if ($('.page-container').parent(".container").size() === 1) {
  675. $('.page-container').insertAfter('body > .clearfix');
  676. }
  677. if ($('.footer > .container').size() === 1) {
  678. $('.footer').html($('.footer > .container').html());
  679. } else if ($('.footer').parent(".container").size() === 1) {
  680. $('.footer').insertAfter('.page-container');
  681. }
  682. $('body > .container').remove();
  683. }
  684. var lastSelectedLayout = '';
  685. var setLayout = function () {
  686. var layoutOption = $('.layout-option', panel).val();
  687. var sidebarOption = $('.sidebar-option', panel).val();
  688. var headerOption = $('.header-option', panel).val();
  689. var footerOption = $('.footer-option', panel).val();
  690. var sidebarPosOption = $('.sidebar-pos-option', panel).val();
  691. if (sidebarOption == "fixed" && headerOption == "default") {
  692. alert('Default Header with Fixed Sidebar option is not supported. Proceed with Fixed Header with Fixed Sidebar.');
  693. $('.header-option', panel).val("fixed");
  694. $('.sidebar-option', panel).val("fixed");
  695. sidebarOption = 'fixed';
  696. headerOption = 'fixed';
  697. }
  698. resetLayout(); // reset layout to default state
  699. if (layoutOption === "boxed") {
  700. $("body").addClass("page-boxed");
  701. // set header
  702. $('.header > .header-inner').addClass("container");
  703. var cont = $('body > .clearfix').after('<div class="container"></div>');
  704. // set content
  705. $('.page-container').appendTo('body > .container');
  706. // set footer
  707. if (footerOption === 'fixed') {
  708. $('.footer').html('<div class="container">' + $('.footer').html() + '</div>');
  709. } else {
  710. $('.footer').appendTo('body > .container');
  711. }
  712. }
  713. if (lastSelectedLayout != layoutOption) {
  714. //layout changed, run responsive handler:
  715. runResponsiveHandlers();
  716. }
  717. lastSelectedLayout = layoutOption;
  718. //header
  719. if (headerOption === 'fixed') {
  720. $("body").addClass("page-header-fixed");
  721. $(".header").removeClass("navbar-static-top").addClass("navbar-fixed-top");
  722. } else {
  723. $("body").removeClass("page-header-fixed");
  724. $(".header").removeClass("navbar-fixed-top").addClass("navbar-static-top");
  725. }
  726. //sidebar
  727. if (sidebarOption === 'fixed') {
  728. $("body").addClass("page-sidebar-fixed");
  729. } else {
  730. $("body").removeClass("page-sidebar-fixed");
  731. }
  732. //footer
  733. if (footerOption === 'fixed') {
  734. $("body").addClass("page-footer-fixed");
  735. } else {
  736. $("body").removeClass("page-footer-fixed");
  737. }
  738. //sidebar position
  739. if (selectSrchInit.isRTL()) {
  740. if (sidebarPosOption === 'left') {
  741. $("body").addClass("page-sidebar-reversed");
  742. $('#frontend-link').tooltip('destroy').tooltip({placement: 'right'});
  743. } else {
  744. $("body").removeClass("page-sidebar-reversed");
  745. $('#frontend-link').tooltip('destroy').tooltip({placement: 'left'});
  746. }
  747. } else {
  748. if (sidebarPosOption === 'right') {
  749. $("body").addClass("page-sidebar-reversed");
  750. $('#frontend-link').tooltip('destroy').tooltip({placement: 'left'});
  751. } else {
  752. $("body").removeClass("page-sidebar-reversed");
  753. $('#frontend-link').tooltip('destroy').tooltip({placement: 'right'});
  754. }
  755. }
  756. handleSidebarAndContentHeight(); // fix content height
  757. handleFixedSidebar(); // reinitialize fixed sidebar
  758. handleFixedSidebarHoverable(); // reinitialize fixed sidebar hover effect
  759. }
  760. // handle theme colors
  761. var setColor = function (color) {
  762. var color_ = (selectSrchInit.isRTL() ? color + '-rtl' : color);
  763. $('#style_color').attr("href", "assets/css/themes/" + color_ + ".css");
  764. $.cookie('style_color', color);
  765. }
  766. $('.toggler', panel).click(function () {
  767. $('.toggler').hide();
  768. $('.toggler-close').show();
  769. $('.theme-panel > .theme-options').show();
  770. });
  771. $('.toggler-close', panel).click(function () {
  772. $('.toggler').show();
  773. $('.toggler-close').hide();
  774. $('.theme-panel > .theme-options').hide();
  775. });
  776. $('.theme-colors > ul > li', panel).click(function () {
  777. var color = $(this).attr("data-style");
  778. setColor(color);
  779. $('ul > li', panel).removeClass("current");
  780. $(this).addClass("current");
  781. });
  782. $('.layout-option, .header-option, .sidebar-option, .footer-option, .sidebar-pos-option', panel).change(setLayout);
  783. if ($.cookie('style_color')) {
  784. setColor($.cookie('style_color'));
  785. }
  786. }
  787. //* END:CORE HANDLERS *//
  788. return {
  789. //main function to initiate the theme
  790. init: function () {
  791. //IMPORTANT!!!: Do not modify the core handlers call order.
  792. //core handlers
  793. handleInit(); // initialize core variables
  794. handleResponsiveOnResize(); // set and handle responsive
  795. handleUniform(); // hanfle custom radio & checkboxes
  796. handleScrollers(); // handles slim scrolling contents
  797. handleResponsiveOnInit(); // handler responsive elements on page load
  798. //layout handlers
  799. handleFixedSidebar(); // handles fixed sidebar menu
  800. handleFixedSidebarHoverable(); // handles fixed sidebar on hover effect
  801. handleSidebarMenu(); // handles main menu
  802. handleHorizontalMenu(); // handles horizontal menu
  803. handleSidebarToggler(); // handles sidebar hide/show
  804. handleFixInputPlaceholderForIE(); // fixes/enables html5 placeholder attribute for IE9, IE8
  805. handleGoTop(); //handles scroll to top functionality in the footer
  806. handleTheme(); // handles style customer tool
  807. //ui component handlers
  808. handleFancybox() // handle fancy box
  809. handleSelect2(); // handle custom Select2 dropdowns
  810. handlePortletTools(); // handles portlet action bar functionality(refresh, configure, toggle, remove)
  811. handleAlerts(); //handle closabled alerts
  812. handleDropdowns(); // handle dropdowns
  813. handleTabs(); // handle tabs
  814. handleTooltips(); // handle bootstrap tooltips
  815. handlePopovers(); // handles bootstrap popovers
  816. handleAccordions(); //handles accordions
  817. handleModals(); // handle modals
  818. handleFullScreenMode(); // handles full screen
  819. },
  820. //main function to initiate core javascript after ajax complete
  821. initAjax: function () {
  822. handleSelect2(); // handle custom Select2 dropdowns
  823. handleDropdowns(); // handle dropdowns
  824. handleTooltips(); // handle bootstrap tooltips
  825. handlePopovers(); // handles bootstrap popovers
  826. handleAccordions(); //handles accordions
  827. handleUniform(); // hanfle custom radio & checkboxes
  828. handleDropdownHover() // handles dropdown hover
  829. },
  830. //public function to fix the sidebar and content height accordingly
  831. fixContentHeight: function () {
  832. handleSidebarAndContentHeight();
  833. },
  834. //public function to remember last opened popover that needs to be closed on click
  835. setLastPopedPopover: function (el) {
  836. lastPopedPopover = el;
  837. },
  838. //public function to add callback a function which will be called on window resize
  839. addResponsiveHandler: function (func) {
  840. responsiveHandlers.push(func);
  841. },
  842. // useful function to make equal height for contacts stand side by side
  843. setEqualHeight: function (els) {
  844. var tallestEl = 0;
  845. els = jQuery(els);
  846. els.each(function () {
  847. var currentHeight = $(this).height();
  848. if (currentHeight > tallestEl) {
  849. tallestColumn = currentHeight;
  850. }
  851. });
  852. els.height(tallestEl);
  853. },
  854. // wrapper function to scroll(focus) to an element
  855. scrollTo: function (el, offeset) {
  856. pos = (el && el.size() > 0) ? el.offset().top : 0;
  857. jQuery('html,body').animate({
  858. scrollTop: pos + (offeset ? offeset : 0)
  859. }, 'slow');
  860. },
  861. // function to scroll to the top
  862. scrollTop: function () {
  863. selectSrchInit.scrollTo();
  864. },
  865. // wrapper function to block element(indicate loading)
  866. blockUI: function (el, centerY) {
  867. var el = jQuery(el);
  868. if (el.height() <= 400) {
  869. centerY = true;
  870. }
  871. el.block({
  872. message: '<img src="./assets/img/ajax-loading.gif" align="">',
  873. centerY: centerY != undefined ? centerY : true,
  874. css: {
  875. top: '10%',
  876. border: 'none',
  877. padding: '2px',
  878. backgroundColor: 'none'
  879. },
  880. overlayCSS: {
  881. backgroundColor: '#000',
  882. opacity: 0.05,
  883. cursor: 'wait'
  884. }
  885. });
  886. },
  887. // wrapper function to un-block element(finish loading)
  888. unblockUI: function (el, clean) {
  889. jQuery(el).unblock({
  890. onUnblock: function () {
  891. jQuery(el).css('position', '');
  892. jQuery(el).css('zoom', '');
  893. }
  894. });
  895. },
  896. // initializes uniform elements
  897. initUniform: function (els) {
  898. if (els) {
  899. jQuery(els).each(function () {
  900. if ($(this).parents(".checker").size() == 0) {
  901. $(this).show();
  902. $(this).uniform();
  903. }
  904. });
  905. } else {
  906. handleUniform();
  907. }
  908. },
  909. //wrapper function to update/sync jquery uniform checkbox & radios
  910. updateUniform: function (els) {
  911. $.uniform.update(els); // update the uniform checkbox & radios UI after the actual input control state changed
  912. },
  913. //public function to initialize the fancybox plugin
  914. initFancybox: function () {
  915. handleFancybox();
  916. },
  917. //public helper function to get actual input value(used in IE9 and IE8 due to placeholder attribute not supported)
  918. getActualVal: function (el) {
  919. var el = jQuery(el);
  920. if (el.val() === el.attr("placeholder")) {
  921. return "";
  922. }
  923. return el.val();
  924. },
  925. //public function to get a paremeter by name from URL
  926. getURLParameter: function (paramName) {
  927. var searchString = window.location.search.substring(1),
  928. i, val, params = searchString.split("&");
  929. for (i = 0; i < params.length; i++) {
  930. val = params[i].split("=");
  931. if (val[0] == paramName) {
  932. return unescape(val[1]);
  933. }
  934. }
  935. return null;
  936. },
  937. // check for device touch support
  938. isTouchDevice: function () {
  939. try {
  940. document.createEvent("TouchEvent");
  941. return true;
  942. } catch (e) {
  943. return false;
  944. }
  945. },
  946. // check IE8 mode
  947. isIE8: function () {
  948. return isIE8;
  949. },
  950. // check IE9 mode
  951. isIE9: function () {
  952. return isIE9;
  953. },
  954. //check RTL mode
  955. isRTL: function () {
  956. return isRTL;
  957. },
  958. // get layout color code by color name
  959. getLayoutColorCode: function (name) {
  960. if (layoutColorCodes[name]) {
  961. return layoutColorCodes[name];
  962. } else {
  963. return '';
  964. }
  965. }
  966. };
  967. }();