jquery.app.js 12 KB

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