app.js 32 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890
  1. /**
  2. Core script to handle the entire layout and base functions
  3. **/
  4. var App = 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. var handleInit = function() {
  24. if ($('body').css('direction') === 'rtl') {
  25. isRTL = true;
  26. }
  27. isIE8 = !! navigator.userAgent.match(/MSIE 8.0/);
  28. isIE9 = !! navigator.userAgent.match(/MSIE 9.0/);
  29. isIE10 = !! navigator.userAgent.match(/MSIE 10/);
  30. if (isIE10) {
  31. jQuery('html').addClass('ie10'); // detect IE10 version
  32. }
  33. }
  34. var handleDesktopTabletContents = function () {
  35. // loops all page elements with "responsive" class and applies classes for tablet mode
  36. // For metornic 1280px or less set as tablet mode to display the content properly
  37. if ($(window).width() <= 1280 || $('body').hasClass('page-boxed')) {
  38. $(".responsive").each(function () {
  39. var forTablet = $(this).attr('data-tablet');
  40. var forDesktop = $(this).attr('data-desktop');
  41. if (forTablet) {
  42. $(this).removeClass(forDesktop);
  43. $(this).addClass(forTablet);
  44. }
  45. });
  46. }
  47. // loops all page elements with "responsive" class and applied classes for desktop mode
  48. // For metornic higher 1280px set as desktop mode to display the content properly
  49. if ($(window).width() > 1280 && $('body').hasClass('page-boxed') === false) {
  50. $(".responsive").each(function () {
  51. var forTablet = $(this).attr('data-tablet');
  52. var forDesktop = $(this).attr('data-desktop');
  53. if (forTablet) {
  54. $(this).removeClass(forTablet);
  55. $(this).addClass(forDesktop);
  56. }
  57. });
  58. }
  59. }
  60. var handleSidebarState = function () {
  61. // remove sidebar toggler if window width smaller than 900(for table and phone mode)
  62. if ($(window).width() < 980) {
  63. $('body').removeClass("page-sidebar-closed");
  64. }
  65. }
  66. var runResponsiveHandlers = function () {
  67. // reinitialize other subscribed elements
  68. for (var i in responsiveHandlers) {
  69. var each = responsiveHandlers[i];
  70. each.call();
  71. }
  72. }
  73. var handleResponsive = function () {
  74. handleTooltips();
  75. handleSidebarState();
  76. handleDesktopTabletContents();
  77. handleSidebarAndContentHeight();
  78. handleChoosenSelect();
  79. handleFixedSidebar();
  80. runResponsiveHandlers();
  81. }
  82. var handleResponsiveOnInit = function () {
  83. handleSidebarState();
  84. handleDesktopTabletContents();
  85. handleSidebarAndContentHeight();
  86. }
  87. var handleResponsiveOnResize = function () {
  88. var resize;
  89. if (isIE8) {
  90. var currheight;
  91. $(window).resize(function() {
  92. if(currheight == document.documentElement.clientHeight) {
  93. return; //quite event since only body resized not window.
  94. }
  95. if (resize) {
  96. clearTimeout(resize);
  97. }
  98. resize = setTimeout(function() {
  99. handleResponsive();
  100. }, 50); // wait 50ms until window resize finishes.
  101. currheight = document.documentElement.clientHeight; // store last body client height
  102. });
  103. } else {
  104. $(window).resize(function() {
  105. if (resize) {
  106. clearTimeout(resize);
  107. }
  108. resize = setTimeout(function() {
  109. console.log('resize');
  110. handleResponsive();
  111. }, 50); // wait 50ms until window resize finishes.
  112. });
  113. }
  114. }
  115. //* BEGIN:CORE HANDLERS *//
  116. // this function handles responsive layout on screen size resize or mobile device rotate.
  117. var handleSidebarAndContentHeight = function () {
  118. var content = $('.page-content');
  119. var sidebar = $('.page-sidebar');
  120. var body = $('body');
  121. var height;
  122. if (body.hasClass("page-footer-fixed") === true && body.hasClass("page-sidebar-fixed") === false) {
  123. var available_height = $(window).height() - $('.footer').height();
  124. if (content.height() < available_height) {
  125. content.attr('style', 'min-height:' + available_height + 'px !important');
  126. }
  127. } else {
  128. if (body.hasClass('page-sidebar-fixed')) {
  129. height = _calculateFixedSidebarViewportHeight();
  130. } else {
  131. height = sidebar.height() + 20;
  132. }
  133. if (height >= content.height()) {
  134. content.attr('style', 'min-height:' + height + 'px !important');
  135. }
  136. }
  137. }
  138. var handleSidebarMenu = function () {
  139. jQuery('.page-sidebar').on('click', 'li > a', function (e) {
  140. if ($(this).next().hasClass('sub-menu') == false) {
  141. if ($('.btn-navbar').hasClass('collapsed') == false) {
  142. $('.btn-navbar').click();
  143. }
  144. return;
  145. }
  146. var parent = $(this).parent().parent();
  147. parent.children('li.open').children('a').children('.arrow').removeClass('open');
  148. parent.children('li.open').children('.sub-menu').slideUp(200);
  149. parent.children('li.open').removeClass('open');
  150. var sub = jQuery(this).next();
  151. if (sub.is(":visible")) {
  152. jQuery('.arrow', jQuery(this)).removeClass("open");
  153. jQuery(this).parent().removeClass("open");
  154. sub.slideUp(200, function () {
  155. handleSidebarAndContentHeight();
  156. });
  157. } else {
  158. jQuery('.arrow', jQuery(this)).addClass("open");
  159. jQuery(this).parent().addClass("open");
  160. sub.slideDown(200, function () {
  161. handleSidebarAndContentHeight();
  162. });
  163. }
  164. e.preventDefault();
  165. });
  166. // handle ajax links
  167. jQuery('.page-sidebar').on('click', ' li > a.ajaxify', function (e) {
  168. e.preventDefault();
  169. App.scrollTop();
  170. var url = $(this).attr("href");
  171. var menuContainer = jQuery('.page-sidebar ul');
  172. var pageContent = $('.page-content');
  173. var pageContentBody = $('.page-content .page-content-body');
  174. menuContainer.children('li.active').removeClass('active');
  175. menuContainer.children('arrow.open').removeClass('open');
  176. $(this).parents('li').each(function () {
  177. $(this).addClass('active');
  178. $(this).children('a > span.arrow').addClass('open');
  179. });
  180. $(this).parents('li').addClass('active');
  181. App.blockUI(pageContent, false);
  182. $.post(url, {}, function (res) {
  183. App.unblockUI(pageContent);
  184. pageContentBody.html(res);
  185. App.fixContentHeight(); // fix content height
  186. App.initUniform(); // initialize uniform elements
  187. });
  188. });
  189. }
  190. var _calculateFixedSidebarViewportHeight = function () {
  191. var sidebarHeight = $(window).height() - $('.header').height() + 1;
  192. if ($('body').hasClass("page-footer-fixed")) {
  193. sidebarHeight = sidebarHeight - $('.footer').height();
  194. }
  195. return sidebarHeight;
  196. }
  197. var handleFixedSidebar = function () {
  198. var menu = $('.page-sidebar-menu');
  199. if (menu.parent('.slimScrollDiv').size() === 1) { // destroy existing instance before updating the height
  200. menu.slimScroll({
  201. destroy: true
  202. });
  203. menu.removeAttr('style');
  204. $('.page-sidebar').removeAttr('style');
  205. }
  206. if ($('.page-sidebar-fixed').size() === 0) {
  207. handleSidebarAndContentHeight();
  208. return;
  209. }
  210. if ($(window).width() >= 980) {
  211. var sidebarHeight = _calculateFixedSidebarViewportHeight();
  212. menu.slimScroll({
  213. size: '7px',
  214. color: '#a1b2bd',
  215. opacity: .3,
  216. position: isRTL ? 'left' : ($('.page-sidebar-on-right').size() === 1 ? 'left' : 'right'),
  217. height: sidebarHeight,
  218. allowPageScroll: false,
  219. disableFadeOut: false
  220. });
  221. handleSidebarAndContentHeight();
  222. }
  223. }
  224. var handleFixedSidebarHoverable = function () {
  225. if ($('body').hasClass('page-sidebar-fixed') === false) {
  226. return;
  227. }
  228. $('.page-sidebar').off('mouseenter').on('mouseenter', function () {
  229. var body = $('body');
  230. if ((body.hasClass('page-sidebar-closed') === false || body.hasClass('page-sidebar-fixed') === false) || $(this).hasClass('page-sidebar-hovering')) {
  231. return;
  232. }
  233. body.removeClass('page-sidebar-closed').addClass('page-sidebar-hover-on');
  234. $(this).addClass('page-sidebar-hovering');
  235. $(this).animate({
  236. width: sidebarWidth
  237. }, 400, '', function () {
  238. $(this).removeClass('page-sidebar-hovering');
  239. });
  240. });
  241. $('.page-sidebar').off('mouseleave').on('mouseleave', function () {
  242. var body = $('body');
  243. if ((body.hasClass('page-sidebar-hover-on') === false || body.hasClass('page-sidebar-fixed') === false) || $(this).hasClass('page-sidebar-hovering')) {
  244. return;
  245. }
  246. $(this).addClass('page-sidebar-hovering');
  247. $(this).animate({
  248. width: sidebarCollapsedWidth
  249. }, 400, '', function () {
  250. $('body').addClass('page-sidebar-closed').removeClass('page-sidebar-hover-on');
  251. $(this).removeClass('page-sidebar-hovering');
  252. });
  253. });
  254. }
  255. var handleSidebarToggler = function () {
  256. // handle sidebar show/hide
  257. $('.page-sidebar').on('click', '.sidebar-toggler', function (e) {
  258. var body = $('body');
  259. var sidebar = $('.page-sidebar');
  260. if ((body.hasClass("page-sidebar-hover-on") && body.hasClass('page-sidebar-fixed')) || sidebar.hasClass('page-sidebar-hovering')) {
  261. body.removeClass('page-sidebar-hover-on');
  262. sidebar.css('width', '').hide().show();
  263. e.stopPropagation();
  264. runResponsiveHandlers();
  265. return;
  266. }
  267. $(".sidebar-search", sidebar).removeClass("open");
  268. if (body.hasClass("page-sidebar-closed")) {
  269. body.removeClass("page-sidebar-closed");
  270. if (body.hasClass('page-sidebar-fixed')) {
  271. sidebar.css('width', '');
  272. }
  273. } else {
  274. body.addClass("page-sidebar-closed");
  275. }
  276. runResponsiveHandlers();
  277. });
  278. // handle the search bar close
  279. $('.page-sidebar').on('click', '.sidebar-search .remove', function (e) {
  280. e.preventDefault();
  281. $('.sidebar-search').removeClass("open");
  282. });
  283. // handle the search query submit on enter press
  284. $('.page-sidebar').on('keypress', '.sidebar-search input', function (e) {
  285. if (e.which == 13) {
  286. window.location.href = "extra_search.html";
  287. return false; //<---- Add this line
  288. }
  289. });
  290. // handle the search submit
  291. $('.sidebar-search .submit').on('click', function (e) {
  292. e.preventDefault();
  293. if ($('body').hasClass("page-sidebar-closed")) {
  294. if ($('.sidebar-search').hasClass('open') == false) {
  295. if ($('.page-sidebar-fixed').size() === 1) {
  296. $('.page-sidebar .sidebar-toggler').click(); //trigger sidebar toggle button
  297. }
  298. $('.sidebar-search').addClass("open");
  299. } else {
  300. window.location.href = "extra_search.html";
  301. }
  302. } else {
  303. window.location.href = "extra_search.html";
  304. }
  305. });
  306. }
  307. var handleHorizontalMenu = function () {
  308. //handle hor menu search form toggler click
  309. $('.header').on('click', '.hor-menu .hor-menu-search-form-toggler', function (e) {
  310. if ($(this).hasClass('hide')) {
  311. $(this).removeClass('hide');
  312. $('.header .hor-menu .search-form').hide();
  313. } else {
  314. $(this).addClass('hide');
  315. $('.header .hor-menu .search-form').show();
  316. }
  317. e.preventDefault();
  318. });
  319. //handle hor menu search button click
  320. $('.header').on('click', '.hor-menu .search-form .btn', function (e) {
  321. window.location.href = "extra_search.html";
  322. e.preventDefault();
  323. });
  324. //handle hor menu search form on enter press
  325. $('.header').on('keypress', '.hor-menu .search-form input', function (e) {
  326. if (e.which == 13) {
  327. window.location.href = "extra_search.html";
  328. return false;
  329. }
  330. });
  331. }
  332. var handleGoTop = function () {
  333. /* set variables locally for increased performance */
  334. jQuery('.footer').on('click', '.go-top', function (e) {
  335. App.scrollTo();
  336. e.preventDefault();
  337. });
  338. }
  339. var handlePortletTools = function () {
  340. jQuery('body').on('click', '.portlet .tools a.remove', function (e) {
  341. e.preventDefault();
  342. var removable = jQuery(this).parents(".portlet");
  343. if (removable.next().hasClass('portlet') || removable.prev().hasClass('portlet')) {
  344. jQuery(this).parents(".portlet").remove();
  345. } else {
  346. jQuery(this).parents(".portlet").parent().remove();
  347. }
  348. });
  349. jQuery('body').on('click', '.portlet .tools a.reload', function (e) {
  350. e.preventDefault();
  351. var el = jQuery(this).parents(".portlet");
  352. App.blockUI(el);
  353. window.setTimeout(function () {
  354. App.unblockUI(el);
  355. }, 1000);
  356. });
  357. jQuery('body').on('click', '.portlet .tools .collapse, .portlet .tools .expand', function (e) {
  358. e.preventDefault();
  359. var el = jQuery(this).closest(".portlet").children(".portlet-body");
  360. if (jQuery(this).hasClass("collapse")) {
  361. jQuery(this).removeClass("collapse").addClass("expand");
  362. el.slideUp(200);
  363. } else {
  364. jQuery(this).removeClass("expand").addClass("collapse");
  365. el.slideDown(200);
  366. }
  367. });
  368. }
  369. var handleUniform = function () {
  370. if (!jQuery().uniform) {
  371. return;
  372. }
  373. var test = $("input[type=checkbox]:not(.toggle), input[type=radio]:not(.toggle, .star)");
  374. if (test.size() > 0) {
  375. test.each(function () {
  376. if ($(this).parents(".checker").size() == 0) {
  377. $(this).show();
  378. $(this).uniform();
  379. }
  380. });
  381. }
  382. }
  383. var handleAccordions = function () {
  384. $(".accordion").collapse().height('auto');
  385. var lastClicked;
  386. //add scrollable class name if you need scrollable panes
  387. jQuery('body').on('click', '.accordion.scrollable .accordion-toggle', function () {
  388. lastClicked = jQuery(this);
  389. }); //move to faq section
  390. jQuery('body').on('shown', '.accordion.scrollable', function () {
  391. jQuery('html,body').animate({
  392. scrollTop: lastClicked.offset().top - 150
  393. }, 'slow');
  394. });
  395. }
  396. var handleTabs = function () {
  397. // function to fix left/right tab contents
  398. var fixTabHeight = function(tab) {
  399. $(tab).each(function() {
  400. var content = $($($(this).attr("href")));
  401. var tab = $(this).parent().parent();
  402. if (tab.height() > content.height()) {
  403. content.css('min-height', tab.height());
  404. }
  405. });
  406. }
  407. // fix tab content on tab shown
  408. $('body').on('shown', '.nav.nav-tabs.tabs-left a[data-toggle="tab"], .nav.nav-tabs.tabs-right a[data-toggle="tab"]', function(){
  409. fixTabHeight($(this));
  410. });
  411. $('body').on('shown', '.nav.nav-tabs', function(){
  412. handleSidebarAndContentHeight();
  413. });
  414. //fix tab contents for left/right tabs
  415. fixTabHeight('.nav.nav-tabs.tabs-left > li.active > a[data-toggle="tab"], .nav.nav-tabs.tabs-right > li.active > a[data-toggle="tab"]');
  416. //activate tab if tab id provided in the URL
  417. if(location.hash) {
  418. var tabid = location.hash.substr(1);
  419. $('a[href="#'+tabid+'"]').click();
  420. }
  421. }
  422. var handleScrollers = function () {
  423. $('.scroller').each(function () {
  424. $(this).slimScroll({
  425. size: '7px',
  426. color: '#a1b2bd',
  427. position: isRTL ? 'left' : 'right',
  428. height: $(this).attr("data-height"),
  429. alwaysVisible: ($(this).attr("data-always-visible") == "1" ? true : false),
  430. railVisible: ($(this).attr("data-rail-visible") == "1" ? true : false),
  431. disableFadeOut: true
  432. });
  433. });
  434. }
  435. var handleTooltips = function () {
  436. if (App.isTouchDevice()) { // if touch device, some tooltips can be skipped in order to not conflict with click events
  437. jQuery('.tooltips:not(.no-tooltip-on-touch-device)').tooltip();
  438. } else {
  439. jQuery('.tooltips').tooltip();
  440. }
  441. }
  442. var handleDropdowns = function () {
  443. $('body').on('click', '.dropdown-menu.hold-on-click', function(e){
  444. e.stopPropagation();
  445. })
  446. }
  447. var handlePopovers = function () {
  448. jQuery('.popovers').popover();
  449. }
  450. var handleChoosenSelect = function () {
  451. if (!jQuery().chosen) {
  452. return;
  453. }
  454. $(".chosen").each(function () {
  455. $(this).chosen({
  456. allow_single_deselect: $(this).attr("data-with-diselect") === "1" ? true : false
  457. });
  458. });
  459. }
  460. var handleFancybox = function () {
  461. if (!jQuery.fancybox) {
  462. return;
  463. }
  464. if (jQuery(".fancybox-button").size() > 0) {
  465. jQuery(".fancybox-button").fancybox({
  466. groupAttr: 'data-rel',
  467. prevEffect: 'none',
  468. nextEffect: 'none',
  469. closeBtn: true,
  470. helpers: {
  471. title: {
  472. type: 'inside'
  473. }
  474. }
  475. });
  476. }
  477. }
  478. var handleTheme = function () {
  479. var panel = $('.color-panel');
  480. if ($('body').hasClass('page-boxed') == false) {
  481. $('.layout-option', panel).val("fluid");
  482. }
  483. $('.sidebar-option', panel).val("default");
  484. $('.header-option', panel).val("fixed");
  485. $('.footer-option', panel).val("default");
  486. //handle theme layout
  487. var resetLayout = function () {
  488. $("body").
  489. removeClass("page-boxed").
  490. removeClass("page-footer-fixed").
  491. removeClass("page-sidebar-fixed").
  492. removeClass("page-header-fixed");
  493. $('.header > .navbar-inner > .container').removeClass("container").addClass("container-fluid");
  494. if ($('.page-container').parent(".container").size() === 1) {
  495. $('.page-container').insertAfter('.header');
  496. }
  497. if ($('.footer > .container').size() === 1) {
  498. $('.footer').html($('.footer > .container').html());
  499. } else if ($('.footer').parent(".container").size() === 1) {
  500. $('.footer').insertAfter('.page-container');
  501. }
  502. $('body > .container').remove();
  503. }
  504. var lastSelectedLayout = '';
  505. var setLayout = function () {
  506. var layoutOption = $('.layout-option', panel).val();
  507. var sidebarOption = $('.sidebar-option', panel).val();
  508. var headerOption = $('.header-option', panel).val();
  509. var footerOption = $('.footer-option', panel).val();
  510. if (sidebarOption == "fixed" && headerOption == "default") {
  511. alert('Default Header with Fixed Sidebar option is not supported. Proceed with Default Header with Default Sidebar.');
  512. $('.sidebar-option', panel).val("default");
  513. sidebarOption = 'default';
  514. }
  515. resetLayout(); // reset layout to default state
  516. if (layoutOption === "boxed") {
  517. $("body").addClass("page-boxed");
  518. // set header
  519. $('.header > .navbar-inner > .container-fluid').removeClass("container-fluid").addClass("container");
  520. var cont = $('.header').after('<div class="container"></div>');
  521. // set content
  522. $('.page-container').appendTo('body > .container');
  523. // set footer
  524. if (footerOption === 'fixed' || sidebarOption === 'default') {
  525. $('.footer').html('<div class="container">'+$('.footer').html()+'</div>');
  526. } else {
  527. $('.footer').appendTo('body > .container');
  528. }
  529. }
  530. if (lastSelectedLayout != layoutOption) {
  531. //layout changed, run responsive handler:
  532. runResponsiveHandlers();
  533. }
  534. lastSelectedLayout = layoutOption;
  535. //header
  536. if (headerOption === 'fixed') {
  537. $("body").addClass("page-header-fixed");
  538. $(".header").removeClass("navbar-static-top").addClass("navbar-fixed-top");
  539. } else {
  540. $("body").removeClass("page-header-fixed");
  541. $(".header").removeClass("navbar-fixed-top").addClass("navbar-static-top");
  542. }
  543. //sidebar
  544. if (sidebarOption === 'fixed') {
  545. $("body").addClass("page-sidebar-fixed");
  546. } else {
  547. $("body").removeClass("page-sidebar-fixed");
  548. }
  549. //footer
  550. if (footerOption === 'fixed') {
  551. $("body").addClass("page-footer-fixed");
  552. } else {
  553. $("body").removeClass("page-footer-fixed");
  554. }
  555. handleSidebarAndContentHeight(); // fix content height
  556. handleFixedSidebar(); // reinitialize fixed sidebar
  557. handleFixedSidebarHoverable(); // reinitialize fixed sidebar hover effect
  558. }
  559. // handle theme colors
  560. var setColor = function (color) {
  561. $('#style_color').attr("href", "assets/css/themes/" + color + ".css");
  562. $.cookie('style_color', color);
  563. }
  564. $('.icon-color', panel).click(function () {
  565. $('.color-mode').show();
  566. $('.icon-color-close').show();
  567. });
  568. $('.icon-color-close', panel).click(function () {
  569. $('.color-mode').hide();
  570. $('.icon-color-close').hide();
  571. });
  572. $('li', panel).click(function () {
  573. var color = $(this).attr("data-style");
  574. setColor(color);
  575. $('.inline li', panel).removeClass("current");
  576. $(this).addClass("current");
  577. });
  578. $('.layout-option, .header-option, .sidebar-option, .footer-option', panel).change(setLayout);
  579. }
  580. var handleFixInputPlaceholderForIE = function () {
  581. //fix html5 placeholder attribute for ie7 & ie8
  582. if (isIE8 || isIE9) { // ie7&ie8
  583. // this is html5 placeholder fix for inputs, inputs with placeholder-no-fix class will be skipped(e.g: we need this for password fields)
  584. jQuery('input[placeholder]:not(.placeholder-no-fix), textarea[placeholder]:not(.placeholder-no-fix)').each(function () {
  585. var input = jQuery(this);
  586. if(input.val()=='' && input.attr("placeholder") != '') {
  587. input.addClass("placeholder").val(input.attr('placeholder'));
  588. }
  589. input.focus(function () {
  590. if (input.val() == input.attr('placeholder')) {
  591. input.val('');
  592. }
  593. });
  594. input.blur(function () {
  595. if (input.val() == '' || input.val() == input.attr('placeholder')) {
  596. input.val(input.attr('placeholder'));
  597. }
  598. });
  599. });
  600. }
  601. }
  602. //* END:CORE HANDLERS *//
  603. return {
  604. //main function to initiate template pages
  605. init: function () {
  606. //IMPORTANT!!!: Do not modify the core handlers call order.
  607. //core handlers
  608. handleInit();
  609. handleResponsiveOnResize(); // set and handle responsive
  610. handleUniform();
  611. handleScrollers(); // handles slim scrolling contents
  612. handleResponsiveOnInit(); // handler responsive elements on page load
  613. //layout handlers
  614. handleFixedSidebar(); // handles fixed sidebar menu
  615. handleFixedSidebarHoverable(); // handles fixed sidebar on hover effect
  616. handleSidebarMenu(); // handles main menu
  617. handleHorizontalMenu(); // handles horizontal menu
  618. handleSidebarToggler(); // handles sidebar hide/show
  619. handleFixInputPlaceholderForIE(); // fixes/enables html5 placeholder attribute for IE9, IE8
  620. handleGoTop(); //handles scroll to top functionality in the footer
  621. handleTheme(); // handles style customer tool
  622. //ui component handlers
  623. handlePortletTools(); // handles portlet action bar functionality(refresh, configure, toggle, remove)
  624. handleDropdowns(); // handle dropdowns
  625. handleTabs(); // handle tabs
  626. handleTooltips(); // handle bootstrap tooltips
  627. handlePopovers(); // handles bootstrap popovers
  628. handleAccordions(); //handles accordions
  629. handleChoosenSelect(); // handles bootstrap chosen dropdowns
  630. App.addResponsiveHandler(handleChoosenSelect); // reinitiate chosen dropdown on main content resize. disable this line if you don't really use chosen dropdowns.
  631. },
  632. fixContentHeight: function () {
  633. handleSidebarAndContentHeight();
  634. },
  635. addResponsiveHandler: function (func) {
  636. responsiveHandlers.push(func);
  637. },
  638. // useful function to make equal height for contacts stand side by side
  639. setEqualHeight: function (els) {
  640. var tallestEl = 0;
  641. els = jQuery(els);
  642. els.each(function () {
  643. var currentHeight = $(this).height();
  644. if (currentHeight > tallestEl) {
  645. tallestColumn = currentHeight;
  646. }
  647. });
  648. els.height(tallestEl);
  649. },
  650. // wrapper function to scroll to an element
  651. scrollTo: function (el, offeset) {
  652. pos = el ? el.offset().top : 0;
  653. jQuery('html,body').animate({
  654. scrollTop: pos + (offeset ? offeset : 0)
  655. }, 'slow');
  656. },
  657. scrollTop: function () {
  658. App.scrollTo();
  659. },
  660. // wrapper function to block element(indicate loading)
  661. blockUI: function (el, centerY) {
  662. var el = jQuery(el);
  663. el.block({
  664. message: '<img src="./assets/img/ajax-loading.gif" align="">',
  665. centerY: centerY != undefined ? centerY : true,
  666. css: {
  667. top: '10%',
  668. border: 'none',
  669. padding: '2px',
  670. backgroundColor: 'none'
  671. },
  672. overlayCSS: {
  673. backgroundColor: '#000',
  674. opacity: 0.05,
  675. cursor: 'wait'
  676. }
  677. });
  678. },
  679. // wrapper function to un-block element(finish loading)
  680. unblockUI: function (el) {
  681. jQuery(el).unblock({
  682. onUnblock: function () {
  683. jQuery(el).removeAttr("style");
  684. }
  685. });
  686. },
  687. // initializes uniform elements
  688. initUniform: function (els) {
  689. if (els) {
  690. jQuery(els).each(function () {
  691. if ($(this).parents(".checker").size() == 0) {
  692. $(this).show();
  693. $(this).uniform();
  694. }
  695. });
  696. } else {
  697. handleUniform();
  698. }
  699. },
  700. // initializes choosen dropdowns
  701. initChosenSelect: function (els) {
  702. $(els).chosen({
  703. allow_single_deselect: true
  704. });
  705. },
  706. initFancybox: function () {
  707. handleFancybox();
  708. },
  709. getActualVal: function (el) {
  710. var el = jQuery(el);
  711. if (el.val() === el.attr("placeholder")) {
  712. return "";
  713. }
  714. return el.val();
  715. },
  716. getURLParameter: function (paramName) {
  717. var searchString = window.location.search.substring(1),
  718. i, val, params = searchString.split("&");
  719. for (i = 0; i < params.length; i++) {
  720. val = params[i].split("=");
  721. if (val[0] == paramName) {
  722. return unescape(val[1]);
  723. }
  724. }
  725. return null;
  726. },
  727. // check for device touch support
  728. isTouchDevice: function () {
  729. try {
  730. document.createEvent("TouchEvent");
  731. return true;
  732. } catch (e) {
  733. return false;
  734. }
  735. },
  736. isIE8: function () {
  737. return isIE8;
  738. },
  739. isRTL: function () {
  740. return isRTL;
  741. },
  742. getLayoutColorCode: function (name) {
  743. if (layoutColorCodes[name]) {
  744. return layoutColorCodes[name];
  745. } else {
  746. return '';
  747. }
  748. }
  749. };
  750. }();