PageRenderTime 24ms CodeModel.GetById 34ms RepoModel.GetById 0ms app.codeStats 0ms

/assets/js/jquery.app.js

https://gitlab.com/Dewapura/SoftPro_R
JavaScript | 318 lines | 236 code | 50 blank | 32 comment | 47 complexity | 59982fad9801460c616f587ca2ed02c1 MD5 | raw file
  1. /**
  2. * Theme: Ubold 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. }
  34. if(!$(this).hasClass("subdrop")) {
  35. // hide any open menus and remove all other classes
  36. $("ul",$(this).parents("ul:first")).slideUp(350);
  37. $("a",$(this).parents("ul:first")).removeClass("subdrop");
  38. $("#sidebar-menu .pull-right i").removeClass("md-remove").addClass("md-add");
  39. // open our new menu and add the open class
  40. $(this).next("ul").slideDown(350);
  41. $(this).addClass("subdrop");
  42. $(".pull-right i",$(this).parents(".has_sub:last")).removeClass("md-add").addClass("md-remove");
  43. $(".pull-right i",$(this).siblings("ul")).removeClass("md-remove").addClass("md-add");
  44. }else if($(this).hasClass("subdrop")) {
  45. $(this).removeClass("subdrop");
  46. $(this).next("ul").slideUp(350);
  47. $(".pull-right i",$(this).parent()).removeClass("md-remove").addClass("md-add");
  48. }
  49. }
  50. },
  51. //init sidemenu
  52. Sidemenu.prototype.init = function() {
  53. var $this = this;
  54. var ua = navigator.userAgent,
  55. event = (ua.match(/iP/i)) ? "touchstart" : "click";
  56. //bind on click
  57. this.$openLeftBtn.on(event, function(e) {
  58. e.stopPropagation();
  59. $this.openLeftBar();
  60. });
  61. // LEFT SIDE MAIN NAVIGATION
  62. $this.$menuItem.on(event, $this.menuItemClick);
  63. // NAVIGATION HIGHLIGHT & OPEN PARENT
  64. $("#sidebar-menu ul li.has_sub a.active").parents("li:last").children("a:first").addClass("active").trigger("click");
  65. },
  66. //init Sidemenu
  67. $.Sidemenu = new Sidemenu, $.Sidemenu.Constructor = Sidemenu
  68. }(window.jQuery),
  69. function($) {
  70. "use strict";
  71. var FullScreen = function() {
  72. this.$body = $("body"),
  73. this.$fullscreenBtn = $("#btn-fullscreen")
  74. };
  75. //turn on full screen
  76. // Thanks to http://davidwalsh.name/fullscreen
  77. FullScreen.prototype.launchFullscreen = function(element) {
  78. if(element.requestFullscreen) {
  79. element.requestFullscreen();
  80. } else if(element.mozRequestFullScreen) {
  81. element.mozRequestFullScreen();
  82. } else if(element.webkitRequestFullscreen) {
  83. element.webkitRequestFullscreen();
  84. } else if(element.msRequestFullscreen) {
  85. element.msRequestFullscreen();
  86. }
  87. },
  88. FullScreen.prototype.exitFullscreen = function() {
  89. if(document.exitFullscreen) {
  90. document.exitFullscreen();
  91. } else if(document.mozCancelFullScreen) {
  92. document.mozCancelFullScreen();
  93. } else if(document.webkitExitFullscreen) {
  94. document.webkitExitFullscreen();
  95. }
  96. },
  97. //toggle screen
  98. FullScreen.prototype.toggle_fullscreen = function() {
  99. var $this = this;
  100. var fullscreenEnabled = document.fullscreenEnabled || document.mozFullScreenEnabled || document.webkitFullscreenEnabled;
  101. if(fullscreenEnabled) {
  102. if(!document.fullscreenElement && !document.mozFullScreenElement && !document.webkitFullscreenElement && !document.msFullscreenElement) {
  103. $this.launchFullscreen(document.documentElement);
  104. } else{
  105. $this.exitFullscreen();
  106. }
  107. }
  108. },
  109. //init sidemenu
  110. FullScreen.prototype.init = function() {
  111. var $this = this;
  112. //bind
  113. $this.$fullscreenBtn.on('click', function() {
  114. $this.toggle_fullscreen();
  115. });
  116. },
  117. //init FullScreen
  118. $.FullScreen = new FullScreen, $.FullScreen.Constructor = FullScreen
  119. }(window.jQuery),
  120. //main app module
  121. function($) {
  122. "use strict";
  123. var App = function() {
  124. this.VERSION = "1.6.0",
  125. this.AUTHOR = "Coderthemes",
  126. this.SUPPORT = "coderthemes@gmail.com",
  127. this.pageScrollElement = "html, body",
  128. this.$body = $("body")
  129. };
  130. //on doc load
  131. App.prototype.onDocReady = function(e) {
  132. FastClick.attach(document.body);
  133. resizefunc.push("initscrolls");
  134. resizefunc.push("changeptype");
  135. $('.animate-number').each(function(){
  136. $(this).animateNumbers($(this).attr("data-value"), true, parseInt($(this).attr("data-duration")));
  137. });
  138. //RUN RESIZE ITEMS
  139. $(window).resize(debounce(resizeitems,100));
  140. $("body").trigger("resize");
  141. // right side-bar toggle
  142. $('.right-bar-toggle').on('click', function(e){
  143. $('#wrapper').toggleClass('right-bar-enabled');
  144. });
  145. },
  146. //initilizing
  147. App.prototype.init = function() {
  148. var $this = this;
  149. //document load initialization
  150. $(document).ready($this.onDocReady);
  151. //init side bar - left
  152. $.Sidemenu.init();
  153. //init fullscreen
  154. $.FullScreen.init();
  155. },
  156. $.App = new App, $.App.Constructor = App
  157. }(window.jQuery),
  158. //initializing main application module
  159. function($) {
  160. "use strict";
  161. $.App.init();
  162. }(window.jQuery);
  163. /* ------------ some utility functions ----------------------- */
  164. //this full screen
  165. var toggle_fullscreen = function () {
  166. }
  167. function executeFunctionByName(functionName, context /*, args */) {
  168. var args = [].slice.call(arguments).splice(2);
  169. var namespaces = functionName.split(".");
  170. var func = namespaces.pop();
  171. for(var i = 0; i < namespaces.length; i++) {
  172. context = context[namespaces[i]];
  173. }
  174. return context[func].apply(this, args);
  175. }
  176. var w,h,dw,dh;
  177. var changeptype = function(){
  178. w = $(window).width();
  179. h = $(window).height();
  180. dw = $(document).width();
  181. dh = $(document).height();
  182. if(jQuery.browser.mobile === true){
  183. $("body").addClass("mobile").removeClass("fixed-left");
  184. }
  185. if(!$("#wrapper").hasClass("forced")){
  186. if(w > 990){
  187. $("body").removeClass("smallscreen").addClass("widescreen");
  188. $("#wrapper").removeClass("enlarged");
  189. }else{
  190. $("body").removeClass("widescreen").addClass("smallscreen");
  191. $("#wrapper").addClass("enlarged");
  192. $(".left ul").removeAttr("style");
  193. }
  194. if($("#wrapper").hasClass("enlarged") && $("body").hasClass("fixed-left")){
  195. $("body").removeClass("fixed-left").addClass("fixed-left-void");
  196. }else if(!$("#wrapper").hasClass("enlarged") && $("body").hasClass("fixed-left-void")){
  197. $("body").removeClass("fixed-left-void").addClass("fixed-left");
  198. }
  199. }
  200. toggle_slimscroll(".slimscrollleft");
  201. }
  202. var debounce = function(func, wait, immediate) {
  203. var timeout, result;
  204. return function() {
  205. var context = this, args = arguments;
  206. var later = function() {
  207. timeout = null;
  208. if (!immediate) result = func.apply(context, args);
  209. };
  210. var callNow = immediate && !timeout;
  211. clearTimeout(timeout);
  212. timeout = setTimeout(later, wait);
  213. if (callNow) result = func.apply(context, args);
  214. return result;
  215. };
  216. }
  217. function resizeitems(){
  218. if($.isArray(resizefunc)){
  219. for (i = 0; i < resizefunc.length; i++) {
  220. window[resizefunc[i]]();
  221. }
  222. }
  223. }
  224. function initscrolls(){
  225. if(jQuery.browser.mobile !== true){
  226. //SLIM SCROLL
  227. $('.slimscroller').slimscroll({
  228. height: 'auto',
  229. size: "5px"
  230. });
  231. $('.slimscrollleft').slimScroll({
  232. height: 'auto',
  233. position: 'right',
  234. size: "5px",
  235. color: '#98a6ad',
  236. wheelStep: 5
  237. });
  238. }
  239. }
  240. function toggle_slimscroll(item){
  241. if($("#wrapper").hasClass("enlarged")){
  242. $(item).css("overflow","inherit").parent().css("overflow","inherit");
  243. $(item). siblings(".slimScrollBar").css("visibility","hidden");
  244. }else{
  245. $(item).css("overflow","hidden").parent().css("overflow","hidden");
  246. $(item). siblings(".slimScrollBar").css("visibility","visible");
  247. }
  248. }
  249. var wow = new WOW(
  250. {
  251. boxClass: 'wow', // animated element css class (default is wow)
  252. animateClass: 'animated', // animation css class (default is animated)
  253. offset: 50, // distance to the element when triggering the animation (default is 0)
  254. mobile: false // trigger animations on mobile devices (true is default)
  255. }
  256. );
  257. wow.init();
  258. // === following js will activate the menu in left side bar based on url ====
  259. $(document).ready(function() {
  260. $("#sidebar-menu a").each(function() {
  261. if (this.href == window.location.href) {
  262. $(this).addClass("active");
  263. $(this).parent().addClass("active"); // add active to li of the current link
  264. $(this).parent().parent().prev().addClass("active"); // add active class to an anchor
  265. $(this).parent().parent().prev().click(); // click the item to make it drop
  266. }
  267. });
  268. });