1
0

app.js 39 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052
  1. "use strict";
  2. var app = {
  3. app: false,
  4. isloaded: false,
  5. header: false,
  6. footer: false,
  7. settings: {
  8. navDetectAuto: true,
  9. navHorizontalDetectAuto: true,
  10. screen_md: 992,
  11. sidepanelMobileHeight: 400,
  12. sidebarMobileHeight: 400
  13. },
  14. accordion_settings: {titleHeight: 50, noResize: false},
  15. init: function(){
  16. this.app = $(".app");
  17. this.header = $(".app > .app-header").length > 0 ? $(".app > .app-header") : false;
  18. this.footer = $(".app > .app-footer").length > 0 ? $(".app > .app-footer") : false;
  19. },
  20. layout: function(){
  21. // sidebars media
  22. app.layoutSidebars();
  23. // end
  24. // check header position
  25. if($(".app-content > .app-header").length === 1)
  26. $(".app-container").addClass("app-header-inside-content");
  27. // end
  28. // params for app-container
  29. $(".app-container").each(function(){
  30. var app_content = $(this).find(".app-content");
  31. $(this).find(".app-sidebar").each(function(){
  32. if($(this).hasClass("dir-left")){
  33. app_content.addClass("app-sidebar-left");
  34. }
  35. if($(this).hasClass("dir-right"))
  36. app_content.addClass("app-sidebar-right");
  37. });
  38. });
  39. // end of params
  40. // sidebar actions
  41. $(".app-sidebar-left-closed .app-sidebar, .app-sidebar-right-closed .app-sidebar").css("display","none");
  42. $("[data-sidebar-toggle]").on("click",function(){
  43. var app_sidebar = $($(this).data("sidebar-toggle")),
  44. app_sidebar_direction = app_sidebar.hasClass("dir-left") ? 'left' : 'right',
  45. app_container = app_sidebar.parent(".app-container");
  46. if(app_container.hasClass("app-sidebar-"+app_sidebar_direction+"-closed")){
  47. app_sidebar.css("display","block");
  48. setTimeout(function(){
  49. app_container.removeClass("app-sidebar-"+app_sidebar_direction+"-closed");
  50. },10);
  51. }else{
  52. app_sidebar.css("display","none");
  53. app_container.addClass("app-sidebar-"+app_sidebar_direction+"-closed");
  54. }
  55. //app_container.toggleClass("app-sidebar-"+app_sidebar_direction+"-closed");
  56. //app_sidebar.toggleClass("app-sidebar-open"); ??? WTF?
  57. $(window).resize();
  58. return false;
  59. });
  60. $("[data-sidebar-minimize]").on("click",function(){
  61. if($(window).width() < app.settings.screen_md) return false;
  62. var app_sidebar = $($(this).data("sidebar-minimize")),
  63. app_sidebar_direction = app_sidebar.hasClass("dir-left") ? 'left' : 'right',
  64. app_container = app_sidebar.parent(".app-container"),
  65. toggle_class = "app-sidebar-"+app_sidebar_direction+"-minimized";
  66. app_container.removeClass("app-sidebar-"+app_sidebar_direction+"-closed");
  67. app_sidebar.css("display","block");
  68. if(app_container.hasClass(toggle_class)){
  69. app_container.removeClass(toggle_class);
  70. app_sidebar.removeClass("app-navigation-minimized").find("li.open").removeClass("open");
  71. app_sidebar.removeAttr("data-minimized").removeData("minimized");
  72. if(app_sidebar.hasClass("scroll"))
  73. app_sidebar.mCustomScrollbar("update");
  74. }else{
  75. app_container.addClass(toggle_class);
  76. app_sidebar.addClass("app-navigation-minimized").find("li.open").removeClass("open");
  77. app_sidebar.removeAttr("data-minimized").removeData("minimized");
  78. if(app_sidebar.hasClass("scroll"))
  79. app_sidebar.mCustomScrollbar("disable",true);
  80. }
  81. // fix after resize
  82. $(window).resize();
  83. return false;
  84. });
  85. // sidepanel
  86. $("[data-sidepanel-toggle]").on("click",function(){
  87. var app_sidepanel = $($(this).data('sidepanel-toggle'));
  88. if($(".app").hasClass("app-sidepanel-open")){
  89. // close sidepanel
  90. $(".app").removeClass("app-sidepanel-open");
  91. // remove overlay if needs
  92. if(app_sidepanel.data("overlay") === 'show'){
  93. app.hideOverlay();
  94. }
  95. }else{
  96. // open sidepanel
  97. $(".app").addClass("app-sidepanel-open");
  98. // show overlay if needs
  99. if(app_sidepanel.data("overlay") === 'show'){
  100. app.showOverlay(function(){
  101. $(".app-overlay").on("click",function(){
  102. $(".app").removeClass("app-sidepanel-open");
  103. app.hideOverlay();
  104. });
  105. });
  106. }
  107. }
  108. // fix after resize
  109. $(window).resize();
  110. return false;
  111. });
  112. // end sidepanel actions
  113. // separated content actions
  114. $("[data-separate-toggle-panel]").on("click",function(){
  115. $($(this).data("separate-toggle-panel")).toggleClass("open");
  116. });
  117. },
  118. layoutSidebars: function(){
  119. // control sidebar media
  120. if($(window).width() < app.settings.screen_md){
  121. if($(".app-container").hasClass("app-sidebar-left-minimized")){
  122. $(".app-container").removeClass("app-sidebar-left-minimized");
  123. $(".app-sidebar.dir-left").removeClass("app-navigation-minimized");
  124. $(".app-sidebar.dir-left").attr("data-minimized","minimized");
  125. }
  126. if($(".app-container").hasClass("app-sidebar-right-minimized")){
  127. $(".app-container").removeClass("app-sidebar-right-minimized");
  128. $(".app-sidebar.dir-right").removeClass("app-navigation-minimized");
  129. $(".app-sidebar.dir-right").attr("data-minimized","minimized");
  130. }
  131. }else{
  132. if($(".app-sidebar.dir-left").data("minimized") === "minimized"){
  133. $(".app-container").addClass("app-sidebar-left-minimized");
  134. $(".app-sidebar.dir-left").addClass("app-navigation-minimized");
  135. $(".app-sidebar.dir-left").mCustomScrollbar("disable",true);
  136. }
  137. if($(".app-sidebar.dir-right").data("minimized") === "minimized"){
  138. $(".app-container").addClass("app-sidebar-right-minimized");
  139. $(".app-sidebar.dir-right").addClass("app-navigation-minimized");
  140. $(".app-sidebar.dir-right").mCustomScrollbar("disable",true);
  141. }
  142. }
  143. // end
  144. },
  145. navigation: function(){
  146. // set openable navigation items
  147. $(".app-navigation nav > ul").find("ul").parent("li").addClass("openable");
  148. // set open element if it's avail
  149. if(app.settings.navDetectAuto && !$(".app-navigation").hasClass("app-navigation-minimized")){
  150. var path = window.location.pathname,
  151. pathArray = path.split("/"),
  152. page = pathArray[pathArray.length - 1];
  153. $(".app-navigation a[href='"+page+"']").addClass("active").parents(".openable").addClass("open");
  154. }
  155. // add open handler
  156. $(".app-navigation .openable > a").on("click",function(e){
  157. e.stopPropagation();
  158. var element = $(this).parent(".openable");
  159. if(element.hasClass("open")){
  160. element.removeClass("open");
  161. element.find("li.open").removeClass("open");
  162. }else{
  163. if(element.parents(".app-navigation").hasClass("app-navigation-minimized") || element.parents(".app-navigation").data("type") === "close-other"){
  164. element.parent("ul").find("> li").not(element).removeClass("open");
  165. }
  166. //element.parents(".app-navigation").css("height","auto"); // Tell me why?
  167. element.addClass("open");
  168. setTimeout(function(){
  169. $(".app-navigation").mCustomScrollbar('scrollTo',element);
  170. },200);
  171. }
  172. // fix after resize
  173. if($(".app-navigation").hasClass("scroll")){
  174. $(".app-navigation").mCustomScrollbar("update");
  175. }else{
  176. $(window).resize();
  177. }
  178. return false;
  179. });
  180. // horizontal navigation handler
  181. $(".app-navigation-horizontal nav > ul > li > ul").each(function(){
  182. $(this).parent("li").addClass("openable");
  183. });
  184. // set open element if it's avail
  185. if(app.settings.navHorizontalDetectAuto){
  186. var path = window.location.pathname,
  187. pathArray = path.split("/"),
  188. page = pathArray[pathArray.length - 1];
  189. $(".app-navigation-horizontal a[href='"+page+"']").parent("li").addClass("active").parents(".openable").addClass("active");
  190. }
  191. $(".app-navigation-horizontal .openable > a").on("click",function(e){
  192. e.stopPropagation();
  193. var nav = $(this).parents(".app-navigation-horizontal");
  194. nav.find(".openable").removeClass("active");
  195. $(this).parent(".openable").addClass("active");
  196. return false;
  197. });
  198. // end horizontal navigation handler
  199. },
  200. navigationMobile: function(){
  201. /* Mobile navigation handler */
  202. if($(".app-navigation-moblie-wrapper").length > 0){
  203. $("[data-navigation-mobile-toggle]").on("click",function(e){
  204. e.stopPropagation();
  205. $(".app").toggleClass("app-navigation-moblie-open");
  206. return false;
  207. });
  208. $(".app .app-navigation-mobile").on("click",function(e){
  209. e.stopPropagation();
  210. });
  211. $(".app .app-content").on("click",function(){
  212. $(".app").removeClass("app-navigation-moblie-open");
  213. });
  214. }
  215. /* end Mobile navigation handler */
  216. /* header navigation handler */
  217. if($(".app-header-navigation").length > 0){
  218. $("[data-header-navigation-toggle]").on("click",function(){
  219. $(".app-header-navigation").toggleClass("show");
  220. return false;
  221. });
  222. $(".app-header-navigation li > a").on("click",function(){
  223. var pli = $(this).parent("li");
  224. if(pli.find("ul").length > 0 || pli.find(".app-header-navigation-megamenu").length > 0){
  225. pli.toggleClass("open");
  226. return false;
  227. }
  228. });
  229. }
  230. /* end header navigation handler */
  231. /* navigation vertical handler */
  232. if($(".app-navigation-horizontal").length > 0){
  233. $("[data-navigation-horizontal-toggle]").on("click",function(){
  234. $(".app-navigation-horizontal").toggleClass("show");
  235. return false;
  236. });
  237. }
  238. /* end navigation vertical handler */
  239. },
  240. spy: function(){
  241. app.layoutSidebars();
  242. // return height to default
  243. if($(".app-content .container-full-size").length > 0){
  244. $(".app-content .container-full-size").removeAttr("style");
  245. }
  246. if($(".block-flying").length > 0){
  247. $(".block-flying").removeAttr("style");
  248. $(".block-flying .block-flying-content").removeAttr("style");
  249. }
  250. // end of...
  251. var winHeight = $(window).height(),
  252. offsetHeight = this._getHeaderHeight() + this._getFooterHeight() + this._getCustomOffset(),
  253. navFixed = $(".app-container .app-sidebar.app-navigation-fixed").length > 0 ? true : false,
  254. sidebars = $(".app-container .app-sidebar"),
  255. content = $(".app-container .app-content"),
  256. sidepanel = $(".app-sidepanel").length > 0 ? $(".app-sidepanel") : false;
  257. sidebars.css({"height":"auto"});
  258. var contentHeight = app._getTotalHeight(content.children()),
  259. sidebarHeight = this._getMaxHeight(sidebars);
  260. if($(window).width() > app.settings.screen_md){
  261. if(contentHeight >= sidebarHeight && sidebarHeight !== 0){
  262. if(sidebarHeight === 0 && (contentHeight+offsetHeight) < winHeight){
  263. content.height(winHeight - offsetHeight);
  264. }else{
  265. if((contentHeight + offsetHeight) <= winHeight){
  266. content.height(winHeight - offsetHeight);
  267. contentHeight = content.height();
  268. }
  269. }
  270. sidebars.height(contentHeight);
  271. }else{
  272. if((contentHeight + offsetHeight) <= winHeight){
  273. content.height(winHeight - offsetHeight);
  274. }
  275. if((sidebarHeight + offsetHeight) <= winHeight){
  276. sidebars.height(winHeight - offsetHeight);
  277. }
  278. }
  279. sidebars.each(function(){
  280. if($(this).attr("data-control-height") === 'true'){
  281. $(this).height(sidebarHeight);
  282. }
  283. });
  284. if($("[data-separate-control-height]").length > 0){
  285. var contentHeight = $(".app-container").height() - app._getTotalHeight($(".app-content > div").not(".app-content-separate"));
  286. $("[data-separate-control-height]").height(contentHeight);
  287. }
  288. if(navFixed){
  289. var nav = $(".app-container .app-sidebar.app-navigation-fixed");
  290. if(app.footer){
  291. nav.addClass("app-navigation-fixed-absolute");
  292. nav.height($(".app").height() - app.footer.height());
  293. }else
  294. nav.height(winHeight);
  295. }
  296. if(sidepanel) sidepanel.height(winHeight);
  297. }else{
  298. if($("[data-separate-control-height]").length > 0){
  299. $("[data-separate-control-height]").css({"height":"auto"});
  300. }
  301. sidebars.each(function(){
  302. if($(this).attr("data-control-height") === 'true'){
  303. $(this).height(app.settings.sidebarMobileHeight);
  304. }else{
  305. $(this).css({"height":"auto"});
  306. }
  307. });
  308. if(sidepanel)
  309. sidepanel.height($(window).height());
  310. //sidepanel.height(app.settings.sidepanelMobileHeight);
  311. }
  312. if($(".app-content .container-full-size").length > 0){
  313. $(".app-content .container-full-size").height(winHeight - $(".app-content .app-header").height() - 1);
  314. }
  315. if($(".block-flying").length > 0){
  316. $(".block-flying").height($(".block-flying").height());
  317. $(".block-flying .block-flying-content").height($(".block-flying").height() - app._getTotalHeight($(".block-flying > div").not(".block-flying-content")));
  318. if($(window).width() < app.settings.screen_md){
  319. $(".block-flying").width($(".app-container").width() - 30);
  320. }
  321. }
  322. return false;
  323. },
  324. /* block predefined functions */
  325. block: {
  326. delete: function(elm, fn){
  327. elm = $(elm);
  328. elm.fadeOut(200,function(){
  329. $(this).remove();
  330. });
  331. if(typeof fn === "function") fn();
  332. app.spy();
  333. return false;
  334. },
  335. toggle: function(elm, fn){
  336. elm = $(elm);
  337. elm.toggleClass("block-toggled");
  338. if(typeof fn === "function") fn();
  339. app.spy();
  340. return false;
  341. },
  342. expand: function(elm, fn){
  343. elm = $(elm);
  344. elm.toggleClass("block-expanded");
  345. if(typeof fn === "function") fn();
  346. return false;
  347. },
  348. loading: {
  349. start: function(elm){
  350. $(elm).append("<div class=\"block-loading-layer\"><div class=\"app-spinner loading loading-primary\"></div></div>");
  351. return true;
  352. },
  353. finish: function(elm){
  354. $(elm).find(".block-loading-layer").remove();
  355. return true;
  356. }
  357. }
  358. },
  359. panel: {
  360. delete: function(elm, fn){
  361. elm = $(elm);
  362. elm.fadeOut(200,function(){
  363. $(this).remove();
  364. });
  365. if(typeof fn === "function") fn();
  366. app.spy();
  367. return false;
  368. },
  369. toggle: function(elm, fn){
  370. elm = $(elm);
  371. elm.toggleClass("panel-toggled");
  372. if(typeof fn === "function") fn();
  373. app.spy();
  374. return false;
  375. },
  376. expand: function(elm, fn){
  377. elm = $(elm);
  378. elm.toggleClass("panel-expanded");
  379. if(typeof fn === "function") fn();
  380. return false;
  381. }
  382. },
  383. /* end block predefined functions */
  384. /* resizable layout */
  385. resizableLayout: function(){
  386. if($(".app-content-resizable").length === 0) return false;
  387. var minWidth = 300,
  388. wrapper = $(".app-content-resizable"),
  389. columns = wrapper.children(".app-content-resizable-column");
  390. $(".app-content-resizable-column").not(":last-child").resizable({
  391. handles: "e",
  392. minWidth: minWidth,
  393. start: function(e, ui) {
  394. columns.each(function(){
  395. $(this).width($(this).width());
  396. });
  397. },
  398. resize: function(e, ui){
  399. var next = $(this).next(".app-content-resizable-column"),
  400. otherElements = $(".app-content-resizable-column").not(next).not($(this)),
  401. otherWidth = app._getMaxWidth(otherElements),
  402. newWidth = wrapper.width() - otherWidth - ui.size.width;
  403. if(newWidth < minWidth){
  404. newWidth = minWidth;
  405. $(this).width(wrapper.width() - otherWidth - minWidth);
  406. next.width(newWidth);
  407. return false;
  408. }
  409. next.width(newWidth);
  410. },
  411. stop: function(e, ui) {
  412. columns.each(function(){
  413. $(this).width( Math.round(($(this).width() / wrapper.width()) * 100) + "%" );
  414. });
  415. }
  416. });//.on('resize', function (e) {
  417. //e.stopPropagation();
  418. //});
  419. },
  420. /* end resizable layout */
  421. /* features */
  422. features: {
  423. gallery: {
  424. init: function(){
  425. this.controlHeight();
  426. $(".app-feature-gallery").on("click","> li:first",function(){
  427. var gallery = $(this).parents(".app-feature-gallery");
  428. $(this).appendTo(gallery);
  429. });
  430. },
  431. controlHeight: function(){
  432. $(".app-feature-gallery").each(function(){
  433. var felm = $(this).find("> li:first");
  434. $(this).height(app._getTotalHeight(felm.children()));
  435. });
  436. }
  437. },
  438. preview: {
  439. init: function(){
  440. var preview = $("#preview"),
  441. dialog = preview.find(".modal-dialog"),
  442. content = preview.find(".modal-body");
  443. $(".preview").on("click",function(){
  444. content.html("");
  445. dialog.removeClass("modal-lg modal-sm modal-fw");
  446. if($(this).data("preview-image"))
  447. content.append(app.features.preview.build.image($(this).data("preview-image")));
  448. if($(this).data("preview-video"))
  449. content.append(app.features.preview.build.video($(this).data("preview-video")));
  450. if($(this).data("preview-href")){
  451. content.html(app.features.preview.build.href($(this).data("preview-href")));
  452. app_plugins.loaded();
  453. }
  454. if($(this).data("preview-size"))
  455. dialog.addClass($(this).data("preview-size"));
  456. if($(this).data("preview-title") && $(this).data("preview-description"))
  457. content.prepend(app.features.preview.build.text($(this).data("preview-title"),$(this).data("preview-description")));
  458. preview.modal("show");
  459. return false;
  460. });
  461. preview.on('hidden.bs.modal',function(){
  462. content.html("");
  463. });
  464. },
  465. build: {
  466. image: function(src){
  467. return $("<img>").attr("src",src).addClass("img-responsive");
  468. },
  469. video: function(src){
  470. return $("<div class=\"app-preview-video\"><iframe src=\""+src+"\" width=\"100%\" frameborder=\"0\" allowfullscreen></iframe></div>");
  471. },
  472. href: function(path){
  473. var result = null;
  474. $.ajax({url: path,type: 'get',dataType: 'html',async: false,
  475. success: function(data) {
  476. result = data;
  477. }
  478. });
  479. return result;
  480. },
  481. text: function(title,description){
  482. return $("<div></div>").addClass("app-heading app-heading-small app-heading-condensed").append( $("<div></div>").addClass("title").html("<h5>"+title+"</h5><p>"+description+"</p>") );
  483. }
  484. }
  485. }
  486. },
  487. /* end features */
  488. /* accordion feature */
  489. accordion: function(){
  490. if($(".app-accordion").length > 0){
  491. $(".app-accordion").each(function(){
  492. var app_accordion = $(this);
  493. app_accordion.find(".item").each(function(){
  494. var app_accordion_item = $(this);
  495. if(!app_accordion.data("type"))
  496. app_accordion.addClass("app-accordion-simple");
  497. app_accordion_item.find(".heading").on("click",function(){
  498. if(app_accordion_item.hasClass("open"))
  499. app_accordion_item.removeClass("open").removeAttr("style");
  500. else
  501. app_accordion_item.addClass("open");
  502. if(app_accordion.data("open") === "close-other"){
  503. app_accordion.find(".item").not(app_accordion_item).removeClass("open").removeAttr("style");
  504. }
  505. if(app_accordion.data("type") === "full-height"){
  506. app.accordionFullHeight(app_accordion);
  507. }
  508. });
  509. });
  510. });
  511. }
  512. },
  513. accordionFullHeight: function(accordion){
  514. if(accordion.hasClass("app-accordion-simple")) return false;
  515. var wrapper = accordion.parent("div"),
  516. items = accordion.find(".item"),
  517. itemsCount = items.length,
  518. openItemsCount = items.filter(".open").length;
  519. accordion.height(wrapper.height());
  520. var items = items.filter(".open");
  521. items.removeAttr("style");
  522. var freeHeight = wrapper.height() - (itemsCount - openItemsCount) * app.accordion_settings.titleHeight;
  523. var height = Math.floor(freeHeight / openItemsCount);
  524. items.each(function(){
  525. $(this).height(height);
  526. $(this).find(".content").height(height - app.accordion_settings.titleHeight);
  527. });
  528. },
  529. accordionFullHeightSpy: function(){
  530. $(".app-accordion").each(function(){
  531. app.accordionFullHeight($(this));
  532. });
  533. },
  534. accordionFullHeightResize: function(){
  535. $(".app-accordion").removeAttr("style").find(".item.open").removeAttr("style");
  536. delayBeforeFire(function(){
  537. app.accordionFullHeightSpy();
  538. },200);
  539. },
  540. /* end accordion feature */
  541. /* content tabs */
  542. contentTabs: function(){
  543. if($(".app-content-tabs").length > 0){
  544. $(".app-content-tabs a .close-tab").on("click",function(e){
  545. e.stopPropagation();
  546. var act = $(this).parents(".app-content-tabs");
  547. $($(this).parent("a").attr("href")).remove();
  548. $(this).parents("li").remove();
  549. act.find("li:first > a").trigger("click");
  550. });
  551. $(".app-content-tabs a").on("click",function(){
  552. $(".app-content-tabs a, .app-content-tab").removeClass("active");
  553. $(this).addClass("active");
  554. $($(this).attr("href")).addClass("active");
  555. return false;
  556. });
  557. }
  558. },
  559. /* end content tabs */
  560. /* features */
  561. showOverlay: function(func){
  562. $(".app-overlay").addClass("show");
  563. if(typeof func === "function") func();
  564. },
  565. hideOverlay: function(){
  566. $(".app-overlay").removeClass("show");
  567. },
  568. formsFile: function(){
  569. $("input.file").each(function(){
  570. var if_title = typeof $(this).attr("title") === "undefined" ? "Browse" : $(this).attr("title");
  571. var if_class = $(this).attr("class").replace("file","");
  572. if_class = if_class === "" ? " btn-default" : if_class;
  573. if_class = $(this).is(":disabled") ? if_class+" disabled" : if_class;
  574. $(this).wrap("<a href=\"#\" class=\"file-input btn"+if_class+"\"></a>").parent("a").append(if_title);
  575. $(this).parent("a").after("<span class=\"file-input-name\"></span>");
  576. });
  577. $("input.file").on("change",function(){
  578. var files = $(this)[0].files,
  579. text = "",
  580. divider = files.length > 1 ? divider = ", " : "";
  581. for (var i = 0; i < files.length; i++)
  582. text += files[i].name.split('/').pop().split('\\').pop() + (i !== (files.length - 1) ? divider : "");
  583. $(this).parent("a").next(".file-input-name").html(text);
  584. });
  585. },
  586. misc: function(){
  587. /* avoid dropdown close inside header */
  588. $(document).on('click', '.app-header .dropdown-menu', function (e) {
  589. e.stopPropagation();
  590. });
  591. /* end */
  592. /* fix height after shown */
  593. $(".panel-collapse").on("shown.bs.collapse", function(){
  594. $(window).resize();
  595. });
  596. /* end */
  597. /* fix height after alert hidden */
  598. $(".alert-dismissible").on("closed.bs.alert", function(){
  599. $(window).resize();
  600. });
  601. /* end */
  602. /* fix height after tab shown */
  603. $("a[data-toggle='tab']").on("shown.bs.tab", function(){
  604. $(window).resize();
  605. });
  606. /* end */
  607. /* icon preview */
  608. $(".icons-preview > li").on("click",function(){
  609. var icon = $(this).find(".name").html();
  610. $("#modal-icon-preview .modal-icon-preview-name").html(icon);
  611. $("#modal-icon-preview .modal-icon-preview-span").val("<span class=\""+icon+"\"></span>");
  612. $("#modal-icon-preview .modal-icon-preview-value").val(icon);
  613. $("#modal-icon-preview .modal-icon-preview-icon span").removeAttr("class").addClass(icon);
  614. $("#modal-icon-preview").modal("show");
  615. });
  616. $(".modal-icon-preview-value, .modal-icon-preview-span").on("click",function(){
  617. $(this).select();
  618. });
  619. /* end icon preview */
  620. /* lock screen */
  621. $(".app-lock .app-lock-user").on("click",function(){
  622. $(".app-lock").addClass("app-lock-open");
  623. $(".app-lock .app-lock-form").show().addClass("animated bounceIn");
  624. $(".app-lock .app-lock-form .form-control").focus();
  625. });
  626. /* ./lock screen */
  627. // New selector case insensivity
  628. $.expr[':'].containsi = function(a, i, m) {
  629. return jQuery(a).text().toUpperCase().indexOf(m[3].toUpperCase()) >= 0;
  630. };
  631. },
  632. doc_nav: function(){
  633. var wH = $(window).height(),
  634. nav = $(".doc_fix_nav"),
  635. pdw = nav.parent("div").width() - 27;
  636. if(nav.length > 0){
  637. nav.width(pdw);
  638. if(nav.height() > wH){
  639. nav.height(wH - 60);
  640. nav.mCustomScrollbar({axis:"y", autoHideScrollbar: true, scrollInertia: 200, advanced: {autoScrollOnFocus: false}});
  641. }
  642. $(window).scroll(function(){
  643. var wp = $(window).scrollTop();
  644. var point = $(document).height() - 397 - nav.outerHeight(true);
  645. if(wp > 175){
  646. nav.addClass("fixed");
  647. if(wp > point)
  648. nav.addClass("stack");
  649. else
  650. nav.removeClass("stack");
  651. }else{
  652. nav.removeClass("fixed");
  653. }
  654. });
  655. }
  656. },
  657. loading: function(action,options){
  658. var settings = $.extend({
  659. state: '',
  660. value: [0,0],
  661. position: '',
  662. speed: 20,
  663. complete: null
  664. },options);
  665. if(action == 'show' || action == 'update'){
  666. if(action == 'show'){
  667. $(".app-loading").remove();
  668. var loading = '<div class="app-loading '+settings.position+'">\n\
  669. <div class="app-loading-progress'+(settings.state != '' ? ' app-loading-'+settings.state: '')+'" style="width:'+settings.value[0]+'%;"></div>\n\
  670. </div>';
  671. $('body').append(loading);
  672. }
  673. var i = $.isArray(settings.value) ? settings.value[0] : $(".app-loading .app-loading-progress").width();
  674. var to = $.isArray(settings.value) ? settings.value[1] : settings.value;
  675. var timer = setInterval(function(){
  676. $(".app-loading .app-loading-progress").css('width',i+'%'); i++;
  677. if(i > to){
  678. clearInterval(timer);
  679. if($.isFunction(settings.complete)){
  680. settings.complete.call(this);
  681. }
  682. }
  683. }, settings.speed);
  684. }
  685. if(action == 'destroy'){
  686. $(".app-loading").remove();
  687. }
  688. },
  689. statusbar: {
  690. init: function(){
  691. $(".app-statusbar-open, .app-statusbar-close").on("click",function () {
  692. app.statusbar.open($(this).attr('href'));
  693. return false;
  694. });
  695. },
  696. open: function(id){
  697. $(".app-statusbar").hide();
  698. if($(id).is(":hidden")) $(id).fadeIn();
  699. }
  700. },
  701. search: function(){
  702. $(".app-header-search").on("click",function(){
  703. $(".app-header-search > input").focus();
  704. });
  705. },
  706. /* table checkall */
  707. checkAll: function(){
  708. $("table .checkall").on("change", function(){
  709. var state = $(this).is(":checked") ? true : false;
  710. var tbody = $(this).parents("table").find("tbody");
  711. tbody.find("tr").each(function(){
  712. $(this).find("input:checkbox").prop("checked",state).attr("checked",state);
  713. });
  714. });
  715. },
  716. /* eof table checkall */
  717. _getTotalHeight: function(elm){
  718. var totalHeight = 0;
  719. elm.each(function(){
  720. totalHeight += $(this).outerHeight(true);
  721. });
  722. return totalHeight;
  723. },
  724. _getMaxHeight: function(elm){
  725. var maxHeight = 0;
  726. elm.each(function(){
  727. maxHeight = $(this).height() > maxHeight ? $(this).height() : maxHeight;
  728. });
  729. return maxHeight;
  730. },
  731. _getMaxWidth: function(elm){
  732. var maxWidth = 0;
  733. elm.each(function(){
  734. maxWidth = $(this).width() > maxWidth ? $(this).width() : maxWidth;
  735. });
  736. return maxWidth;
  737. },
  738. _getHeaderHeight: function(){
  739. return this.header ? this.header.outerHeight(true) : 0;
  740. },
  741. _getFooterHeight: function(){
  742. return this.footer ? this.footer.outerHeight(true) : 0;
  743. },
  744. _getCustomOffset: function(){
  745. return this.app.data("offset-height") ? this.app.data("offset-height") : 0;
  746. },
  747. _delayBeforeFire: function(){
  748. var timer = 0;
  749. return function (callback, ms) {
  750. clearTimeout(timer);
  751. timer = setTimeout(callback, ms);
  752. };
  753. },
  754. _toggleClass: function(container,cl){
  755. $(container).toggleClass(cl);
  756. // spy height changes
  757. app.spy();
  758. return false;
  759. },
  760. _addClass: function(container,cl){
  761. $(container).addClass(cl);
  762. // spy height changes
  763. app.spy();
  764. return false;
  765. },
  766. _removeClass: function(container,cl){
  767. $(container).removeClass(cl);
  768. // spy height changes
  769. app.spy();
  770. return false;
  771. },
  772. loaded: function(){
  773. app.spy();
  774. app.app.addClass("app-loaded");
  775. app.accordion();
  776. app.accordionFullHeightSpy();
  777. setTimeout(function(){
  778. $("body").scrollTop(0);
  779. },500);
  780. app.isloaded = true;
  781. }
  782. };
  783. $(function(){
  784. app.init();
  785. app.layout();
  786. app.resizableLayout();
  787. app.navigation();
  788. app.navigationMobile();
  789. app.contentTabs();
  790. app.formsFile();
  791. app.checkAll();
  792. app.features.gallery.init();
  793. app.features.preview.init();
  794. app.statusbar.init();
  795. app.search();
  796. app.misc();
  797. app.doc_nav();
  798. });
  799. $(window).resize(function(){
  800. delayBeforeFire(function(){
  801. app.accordionFullHeightResize();
  802. app.features.gallery.controlHeight();
  803. app.spy();
  804. },100);
  805. });
  806. var delayBeforeFire = (function(){
  807. var timer = 0;
  808. return function (callback, ms) {
  809. clearTimeout(timer);
  810. timer = setTimeout(callback, ms);
  811. };
  812. })();