jquery.app.js 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370
  1. /**
  2. * Theme: Montran Admin Template
  3. * Author: Coderthemes
  4. * Module/App: Main Js
  5. */
  6. !function($) {
  7. "use strict";
  8. var Sidemenu = function() {
  9. this.$body = $("body"),
  10. this.$openLeftBtn = $(".open-left"),
  11. this.$menuItem = $("#sidebar-menu a")
  12. };
  13. Sidemenu.prototype.openLeftBar = function() {
  14. $("#wrapper").toggleClass("enlarged");
  15. $("#wrapper").addClass("forced");
  16. if($("#wrapper").hasClass("enlarged") && $("body").hasClass("fixed-left")) {
  17. $("body").removeClass("fixed-left").addClass("fixed-left-void");
  18. } else if(!$("#wrapper").hasClass("enlarged") && $("body").hasClass("fixed-left-void")) {
  19. $("body").removeClass("fixed-left-void").addClass("fixed-left");
  20. }
  21. if($("#wrapper").hasClass("enlarged")) {
  22. //close
  23. $.cookie('left_menu', 'close');
  24. $(".left ul").removeAttr("style");
  25. } else {
  26. $.cookie('left_menu', 'open');
  27. $(".subdrop").siblings("ul:first").show();
  28. }
  29. toggle_slimscroll(".slimscrollleft");
  30. $("body").trigger("resize");
  31. },
  32. //menu item click
  33. Sidemenu.prototype.menuItemClick = function(e) {
  34. if(!$("#wrapper").hasClass("enlarged")){
  35. if($(this).parent().hasClass("has_sub")) {
  36. e.preventDefault();
  37. }
  38. if(!$(this).hasClass("subdrop")) {
  39. // hide any open menus and remove all other classes
  40. $("ul",$(this).parents("ul:first")).slideUp(350);
  41. $("a",$(this).parents("ul:first")).removeClass("subdrop");
  42. $("#sidebar-menu .pull-right i").removeClass("md-remove").addClass("md-add");
  43. // open our new menu and add the open class
  44. $(this).next("ul").slideDown(350);
  45. $(this).addClass("subdrop");
  46. $(".pull-right i",$(this).parents(".has_sub:last")).removeClass("md-add").addClass("md-remove");
  47. $(".pull-right i",$(this).siblings("ul")).removeClass("md-remove").addClass("md-add");
  48. }else if($(this).hasClass("subdrop")) {
  49. $(this).removeClass("subdrop");
  50. $(this).next("ul").slideUp(350);
  51. $(".pull-right i",$(this).parent()).removeClass("md-remove").addClass("md-add");
  52. }
  53. }
  54. },
  55. //init sidemenu
  56. Sidemenu.prototype.init = function() {
  57. var $this = this;
  58. //bind on click
  59. $(".open-left").click(function(e) {
  60. e.stopPropagation();
  61. $this.openLeftBar();
  62. });
  63. // LEFT SIDE MAIN NAVIGATION
  64. $this.$menuItem.on('click', $this.menuItemClick);
  65. // NAVIGATION HIGHLIGHT & OPEN PARENT
  66. $("#sidebar-menu ul li.has_sub a.active").parents("li:last").children("a:first").addClass("active").trigger("click");
  67. },
  68. //init Sidemenu
  69. $.Sidemenu = new Sidemenu, $.Sidemenu.Constructor = Sidemenu
  70. }(window.jQuery),
  71. function($) {
  72. "use strict";
  73. var FullScreen = function() {
  74. this.$body = $("body"),
  75. this.$fullscreenBtn = $("#btn-fullscreen")
  76. };
  77. //turn on full screen
  78. // Thanks to http://davidwalsh.name/fullscreen
  79. FullScreen.prototype.launchFullscreen = function(element) {
  80. if(element.requestFullscreen) {
  81. element.requestFullscreen();
  82. } else if(element.mozRequestFullScreen) {
  83. element.mozRequestFullScreen();
  84. } else if(element.webkitRequestFullscreen) {
  85. element.webkitRequestFullscreen();
  86. } else if(element.msRequestFullscreen) {
  87. element.msRequestFullscreen();
  88. }
  89. },
  90. FullScreen.prototype.exitFullscreen = function() {
  91. if(document.exitFullscreen) {
  92. document.exitFullscreen();
  93. } else if(document.mozCancelFullScreen) {
  94. document.mozCancelFullScreen();
  95. } else if(document.webkitExitFullscreen) {
  96. document.webkitExitFullscreen();
  97. }
  98. },
  99. //toggle screen
  100. FullScreen.prototype.toggle_fullscreen = function() {
  101. var $this = this;
  102. var fullscreenEnabled = document.fullscreenEnabled || document.mozFullScreenEnabled || document.webkitFullscreenEnabled;
  103. if(fullscreenEnabled) {
  104. if(!document.fullscreenElement && !document.mozFullScreenElement && !document.webkitFullscreenElement && !document.msFullscreenElement) {
  105. $this.launchFullscreen(document.documentElement);
  106. } else{
  107. $this.exitFullscreen();
  108. }
  109. }
  110. },
  111. //init sidemenu
  112. FullScreen.prototype.init = function() {
  113. var $this = this;
  114. //bind
  115. $this.$fullscreenBtn.on('click', function() {
  116. $this.toggle_fullscreen();
  117. });
  118. },
  119. //init FullScreen
  120. $.FullScreen = new FullScreen, $.FullScreen.Constructor = FullScreen
  121. }(window.jQuery),
  122. //portlets
  123. function($) {
  124. "use strict";
  125. /**
  126. Portlet Widget
  127. */
  128. var Portlet = function() {
  129. this.$body = $("body"),
  130. this.$portletIdentifier = ".portlet",
  131. this.$portletCloser = '.portlet a[data-toggle="remove"]',
  132. this.$portletRefresher = '.portlet a[data-toggle="reload"]'
  133. };
  134. //on init
  135. Portlet.prototype.init = function() {
  136. // Panel closest
  137. var $this = this;
  138. $(document).on("click",this.$portletCloser, function (ev) {
  139. ev.preventDefault();
  140. var $portlet = $(this).closest($this.$portletIdentifier);
  141. var $portlet_parent = $portlet.parent();
  142. $portlet.remove();
  143. if ($portlet_parent.children().length == 0) {
  144. $portlet_parent.remove();
  145. }
  146. });
  147. // Panel Reload
  148. $(document).on("click",this.$portletRefresher, function (ev) {
  149. ev.preventDefault();
  150. var $portlet = $(this).closest($this.$portletIdentifier);
  151. // This is just a simulation, nothing is going to be reloaded
  152. $portlet.append('<div class="panel-disabled"><div class="loader-1"></div></div>');
  153. var $pd = $portlet.find('.panel-disabled');
  154. setTimeout(function () {
  155. $pd.fadeOut('fast', function () {
  156. $pd.remove();
  157. });
  158. }, 500 + 300 * (Math.random() * 5));
  159. });
  160. },
  161. //
  162. $.Portlet = new Portlet, $.Portlet.Constructor = Portlet
  163. }(window.jQuery),
  164. //main app module
  165. function($) {
  166. "use strict";
  167. var MoltranApp = function() {
  168. this.VERSION = "1.1.0",
  169. this.AUTHOR = "Coderthemes",
  170. this.SUPPORT = "coderthemes@gmail.com",
  171. this.pageScrollElement = "html, body",
  172. this.$body = $("body")
  173. };
  174. //initializing tooltip
  175. MoltranApp.prototype.initTooltipPlugin = function() {
  176. $.fn.tooltip && $('[data-toggle="tooltip"]').tooltip()
  177. },
  178. //initializing popover
  179. MoltranApp.prototype.initPopoverPlugin = function() {
  180. $.fn.popover && $('[data-toggle="popover"]').popover()
  181. },
  182. //initializing nicescroll
  183. MoltranApp.prototype.initNiceScrollPlugin = function() {
  184. //You can change the color of scroll bar here
  185. $.fn.niceScroll && $(".nicescroll").niceScroll({ cursorcolor: '#9d9ea5', cursorborderradius: '0px'});
  186. },
  187. //on doc load
  188. MoltranApp.prototype.onDocReady = function(e) {
  189. FastClick.attach(document.body);
  190. resizefunc.push("initscrolls");
  191. resizefunc.push("changeptype");
  192. $('.animate-number').each(function(){
  193. $(this).animateNumbers($(this).attr("data-value"), true, parseInt($(this).attr("data-duration")));
  194. });
  195. //RUN RESIZE ITEMS
  196. $(window).resize(debounce(resizeitems,100));
  197. $("body").trigger("resize");
  198. // right side-bar toggle
  199. $('.right-bar-toggle').on('click', function(e){
  200. e.preventDefault();
  201. $('#wrapper').toggleClass('right-bar-enabled');
  202. });
  203. },
  204. //initilizing
  205. MoltranApp.prototype.init = function() {
  206. var $this = this;
  207. this.initTooltipPlugin(),
  208. this.initPopoverPlugin(),
  209. this.initNiceScrollPlugin(),
  210. //document load initialization
  211. $(document).ready($this.onDocReady);
  212. //creating portles
  213. $.Portlet.init();
  214. //init side bar - left
  215. $.Sidemenu.init();
  216. //init fullscreen
  217. $.FullScreen.init();
  218. },
  219. $.MoltranApp = new MoltranApp, $.MoltranApp.Constructor = MoltranApp
  220. }(window.jQuery),
  221. //initializing main application module
  222. function($) {
  223. "use strict";
  224. $.MoltranApp.init();
  225. }(window.jQuery);
  226. /* ------------ some utility functions ----------------------- */
  227. //this full screen
  228. var toggle_fullscreen = function () {
  229. }
  230. function executeFunctionByName(functionName, context /*, args */) {
  231. var args = [].slice.call(arguments).splice(2);
  232. var namespaces = functionName.split(".");
  233. var func = namespaces.pop();
  234. for(var i = 0; i < namespaces.length; i++) {
  235. context = context[namespaces[i]];
  236. }
  237. return context[func].apply(this, args);
  238. }
  239. var w,h,dw,dh;
  240. var changeptype = function(){
  241. w = $(window).width();
  242. h = $(window).height();
  243. dw = $(document).width();
  244. dh = $(document).height();
  245. if(jQuery.browser.mobile === true){
  246. $("body").addClass("mobile").removeClass("fixed-left");
  247. }
  248. if(!$("#wrapper").hasClass("forced")){
  249. if(w > 990){
  250. $("body").removeClass("smallscreen").addClass("widescreen");
  251. $("#wrapper").removeClass("enlarged");
  252. }else{
  253. $("body").removeClass("widescreen").addClass("smallscreen");
  254. $("#wrapper").addClass("enlarged");
  255. $(".left ul").removeAttr("style");
  256. }
  257. if($("#wrapper").hasClass("enlarged") && $("body").hasClass("fixed-left")){
  258. $("body").removeClass("fixed-left").addClass("fixed-left-void");
  259. }else if(!$("#wrapper").hasClass("enlarged") && $("body").hasClass("fixed-left-void")){
  260. $("body").removeClass("fixed-left-void").addClass("fixed-left");
  261. }
  262. }
  263. toggle_slimscroll(".slimscrollleft");
  264. }
  265. var debounce = function(func, wait, immediate) {
  266. var timeout, result;
  267. return function() {
  268. var context = this, args = arguments;
  269. var later = function() {
  270. timeout = null;
  271. if (!immediate) result = func.apply(context, args);
  272. };
  273. var callNow = immediate && !timeout;
  274. clearTimeout(timeout);
  275. timeout = setTimeout(later, wait);
  276. if (callNow) result = func.apply(context, args);
  277. return result;
  278. };
  279. }
  280. function resizeitems(){
  281. if($.isArray(resizefunc)){
  282. for (i = 0; i < resizefunc.length; i++) {
  283. window[resizefunc[i]]();
  284. }
  285. }
  286. }
  287. function initscrolls(){
  288. if(jQuery.browser.mobile !== true){
  289. //SLIM SCROLL
  290. $('.slimscroller').slimscroll({
  291. height: 'auto',
  292. size: "5px"
  293. });
  294. $('.slimscrollleft').slimScroll({
  295. height: 'auto',
  296. position: 'right',
  297. size: "5px",
  298. color: '#7A868F',
  299. wheelStep: 5
  300. });
  301. }
  302. }
  303. function toggle_slimscroll(item){
  304. if($("#wrapper").hasClass("enlarged")){
  305. $(item).css("overflow","inherit").parent().css("overflow","inherit");
  306. $(item). siblings(".slimScrollBar").css("visibility","hidden");
  307. }else{
  308. $(item).css("overflow","hidden").parent().css("overflow","hidden");
  309. $(item). siblings(".slimScrollBar").css("visibility","visible");
  310. }
  311. }
  312. var wow = new WOW(
  313. {
  314. boxClass: 'wow', // animated element css class (default is wow)
  315. animateClass: 'animated', // animation css class (default is animated)
  316. offset: 50, // distance to the element when triggering the animation (default is 0)
  317. mobile: false // trigger animations on mobile devices (true is default)
  318. }
  319. );
  320. wow.init();