metronic.js 36 KB

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