PageRenderTime 23ms CodeModel.GetById 14ms RepoModel.GetById 0ms app.codeStats 0ms

/tools/CGControlPanel-Styles/Template/js/custom/general.js

https://bitbucket.org/pampero/cgcontrolpanel
JavaScript | 365 lines | 257 code | 72 blank | 36 comment | 67 complexity | 98325f3385d20e7dd6944485119932fd MD5 | raw file
  1. /*
  2. * Additional function for this template
  3. * Written by ThemePixels
  4. * http://themepixels.com/
  5. *
  6. * Copyright (c) 2012 ThemePixels (http://themepixels.com)
  7. *
  8. * Built for Amanda Premium Responsive Admin Template
  9. * http://themeforest.net/category/site-templates/admin-templates
  10. */
  11. jQuery.noConflict();
  12. jQuery(document).ready(function () {
  13. ///// SHOW/HIDE USERDATA WHEN USERINFO IS CLICKED /////
  14. jQuery('.userinfo').click(function () {
  15. if (!jQuery(this).hasClass('active')) {
  16. jQuery('.userinfodrop').show();
  17. jQuery(this).addClass('active');
  18. } else {
  19. jQuery('.userinfodrop').hide();
  20. jQuery(this).removeClass('active');
  21. }
  22. //remove notification box if visible
  23. jQuery('.notification').removeClass('active');
  24. jQuery('.noticontent').remove();
  25. return false;
  26. });
  27. ///// SHOW/HIDE NOTIFICATION /////
  28. jQuery('.notification a').click(function () {
  29. var t = jQuery(this);
  30. var url = t.attr('href');
  31. if (!jQuery('.noticontent').is(':visible')) {
  32. jQuery.post(url, function (data) {
  33. t.parent().append('<div class="noticontent">' + data + '</div>');
  34. });
  35. //this will hide user info drop down when visible
  36. jQuery('.userinfo').removeClass('active');
  37. jQuery('.userinfodrop').hide();
  38. } else {
  39. t.parent().removeClass('active');
  40. jQuery('.noticontent').hide();
  41. }
  42. return false;
  43. });
  44. ///// SHOW/HIDE BOTH NOTIFICATION & USERINFO WHEN CLICKED OUTSIDE OF THIS ELEMENT /////
  45. jQuery(document).click(function (event) {
  46. var ud = jQuery('.userinfodrop');
  47. var nb = jQuery('.noticontent');
  48. //hide user drop menu when clicked outside of this element
  49. if (!jQuery(event.target).is('.userinfodrop')
  50. && !jQuery(event.target).is('.userdata')
  51. && ud.is(':visible')) {
  52. ud.hide();
  53. jQuery('.userinfo').removeClass('active');
  54. }
  55. //hide notification box when clicked outside of this element
  56. if (!jQuery(event.target).is('.noticontent') && nb.is(':visible')) {
  57. nb.remove();
  58. jQuery('.notification').removeClass('active');
  59. }
  60. });
  61. ///// NOTIFICATION CONTENT /////
  62. jQuery('.notitab a').live('click', function () {
  63. var id = jQuery(this).attr('href');
  64. jQuery('.notitab li').removeClass('current'); //reset current
  65. jQuery(this).parent().addClass('current');
  66. if (id == '#messages')
  67. jQuery('#activities').hide();
  68. else
  69. jQuery('#messages').hide();
  70. jQuery(id).show();
  71. return false;
  72. });
  73. ///// SHOW/HIDE VERTICAL SUB MENU /////
  74. jQuery('.vernav > ul li a, .vernav2 > ul li a').each(function () {
  75. var url = jQuery(this).attr('href');
  76. jQuery(this).click(function () {
  77. if (jQuery(url).length > 0) {
  78. if (jQuery(url).is(':visible')) {
  79. if (!jQuery(this).parents('div').hasClass('menucoll') &&
  80. !jQuery(this).parents('div').hasClass('menucoll2'))
  81. jQuery(url).slideUp();
  82. } else {
  83. jQuery('.vernav ul ul, .vernav2 ul ul').each(function () {
  84. jQuery(this).slideUp();
  85. });
  86. if (!jQuery(this).parents('div').hasClass('menucoll') &&
  87. !jQuery(this).parents('div').hasClass('menucoll2'))
  88. jQuery(url).slideDown();
  89. }
  90. return false;
  91. }
  92. });
  93. });
  94. ///// SHOW/HIDE SUB MENU WHEN MENU COLLAPSED /////
  95. jQuery('.menucoll > ul > li, .menucoll2 > ul > li').live('mouseenter mouseleave', function (e) {
  96. if (e.type == 'mouseenter') {
  97. jQuery(this).addClass('hover');
  98. jQuery(this).find('ul').show();
  99. } else {
  100. jQuery(this).removeClass('hover').find('ul').hide();
  101. }
  102. });
  103. ///// HORIZONTAL NAVIGATION (AJAX/INLINE DATA) /////
  104. jQuery('.hornav a').click(function () {
  105. //this is only applicable when window size below 450px
  106. if (jQuery(this).parents('.more').length == 0)
  107. jQuery('.hornav li.more ul').hide();
  108. //remove current menu
  109. jQuery('.hornav li').each(function () {
  110. jQuery(this).removeClass('current');
  111. });
  112. jQuery(this).parent().addClass('current'); // set as current menu
  113. var url = jQuery(this).attr('href');
  114. if (jQuery(url).length > 0) {
  115. jQuery('.contentwrapper .subcontent').hide();
  116. jQuery(url).show();
  117. } else {
  118. jQuery.post(url, function (data) {
  119. jQuery('#contentwrapper').html(data);
  120. jQuery('.stdtable input:checkbox').uniform(); //restyling checkbox
  121. });
  122. }
  123. return false;
  124. });
  125. ///// SEARCH BOX WITH AUTOCOMPLETE /////
  126. var availableTags = [
  127. "ActionScript",
  128. "AppleScript",
  129. "Asp",
  130. "BASIC",
  131. "C",
  132. "C++",
  133. "Clojure",
  134. "COBOL",
  135. "ColdFusion",
  136. "Erlang",
  137. "Fortran",
  138. "Groovy",
  139. "Haskell",
  140. "Java",
  141. "JavaScript",
  142. "Lisp",
  143. "Perl",
  144. "PHP",
  145. "Python",
  146. "Ruby",
  147. "Scala",
  148. "Scheme"
  149. ];
  150. jQuery('#keyword').autocomplete({
  151. source: availableTags
  152. });
  153. ///// SEARCH BOX ON FOCUS /////
  154. jQuery('#keyword').bind('focusin focusout', function (e) {
  155. var t = jQuery(this);
  156. if (e.type == 'focusin' && t.val() == 'Enter keyword(s)') {
  157. t.val('');
  158. } else if (e.type == 'focusout' && t.val() == '') {
  159. t.val('Enter keyword(s)');
  160. }
  161. });
  162. ///// NOTIFICATION CLOSE BUTTON /////
  163. jQuery('.notibar .close').click(function () {
  164. jQuery(this).parent().fadeOut(function () {
  165. jQuery(this).remove();
  166. });
  167. });
  168. ///// COLLAPSED/EXPAND LEFT MENU /////
  169. jQuery('.togglemenu').click(function () {
  170. if (!jQuery(this).hasClass('togglemenu_collapsed')) {
  171. //if(jQuery('.iconmenu').hasClass('vernav')) {
  172. if (jQuery('.vernav').length > 0) {
  173. if (jQuery('.vernav').hasClass('iconmenu')) {
  174. jQuery('body').addClass('withmenucoll');
  175. jQuery('.iconmenu').addClass('menucoll');
  176. } else {
  177. jQuery('body').addClass('withmenucoll');
  178. jQuery('.vernav').addClass('menucoll').find('ul').hide();
  179. }
  180. } else if (jQuery('.vernav2').length > 0) {
  181. //} else {
  182. jQuery('body').addClass('withmenucoll2');
  183. jQuery('.iconmenu').addClass('menucoll2');
  184. }
  185. jQuery('#datepicker').css('display', 'none');
  186. jQuery(this).addClass('togglemenu_collapsed');
  187. jQuery('.iconmenu > ul > li > a').each(function () {
  188. var label = jQuery(this).text();
  189. jQuery('<li><span>' + label + '</span></li>')
  190. .insertBefore(jQuery(this).parent().find('ul li:first-child'));
  191. });
  192. } else {
  193. //if(jQuery('.iconmenu').hasClass('vernav')) {
  194. if (jQuery('.vernav').length > 0) {
  195. if (jQuery('.vernav').hasClass('iconmenu')) {
  196. jQuery('body').removeClass('withmenucoll');
  197. jQuery('.iconmenu').removeClass('menucoll');
  198. } else {
  199. jQuery('body').removeClass('withmenucoll');
  200. jQuery('.vernav').removeClass('menucoll').find('ul').show();
  201. }
  202. } else if (jQuery('.vernav2').length > 0) {
  203. //} else {
  204. jQuery('body').removeClass('withmenucoll2');
  205. jQuery('.iconmenu').removeClass('menucoll2');
  206. }
  207. jQuery(this).removeClass('togglemenu_collapsed');
  208. jQuery('#datepicker').css('display', 'block');
  209. jQuery('.iconmenu ul ul li:first-child').remove();
  210. }
  211. });
  212. ///// RESPONSIVE /////
  213. if (jQuery(document).width() < 640) {
  214. jQuery('.togglemenu').addClass('togglemenu_collapsed');
  215. if (jQuery('.vernav').length > 0) {
  216. jQuery('.iconmenu').addClass('menucoll');
  217. jQuery('body').addClass('withmenucoll');
  218. jQuery('.centercontent').css({ marginLeft: '56px' });
  219. if (jQuery('.iconmenu').length == 0) {
  220. jQuery('.togglemenu').removeClass('togglemenu_collapsed');
  221. } else {
  222. jQuery('.iconmenu > ul > li > a').each(function () {
  223. var label = jQuery(this).text();
  224. jQuery('<li><span>' + label + '</span></li>')
  225. .insertBefore(jQuery(this).parent().find('ul li:first-child'));
  226. });
  227. }
  228. } else {
  229. jQuery('.iconmenu').addClass('menucoll2');
  230. jQuery('body').addClass('withmenucoll2');
  231. jQuery('.centercontent').css({ marginLeft: '36px' });
  232. jQuery('.iconmenu > ul > li > a').each(function () {
  233. var label = jQuery(this).text();
  234. jQuery('<li><span>' + label + '</span></li>')
  235. .insertBefore(jQuery(this).parent().find('ul li:first-child'));
  236. });
  237. }
  238. }
  239. jQuery('.searchicon').live('click', function () {
  240. jQuery('.searchinner').show();
  241. });
  242. jQuery('.searchcancel').live('click', function () {
  243. jQuery('.searchinner').hide();
  244. });
  245. ///// ON LOAD WINDOW /////
  246. function reposSearch() {
  247. if (jQuery(window).width() < 520) {
  248. if (jQuery('.searchinner').length == 0) {
  249. jQuery('.search').wrapInner('<div class="searchinner"></div>');
  250. jQuery('<a class="searchicon"></a>').insertBefore(jQuery('.searchinner'));
  251. jQuery('<a class="searchcancel"></a>').insertAfter(jQuery('.searchinner button'));
  252. }
  253. } else {
  254. if (jQuery('.searchinner').length > 0) {
  255. jQuery('.search form').unwrap();
  256. jQuery('.searchicon, .searchcancel').remove();
  257. }
  258. }
  259. }
  260. reposSearch();
  261. ///// ON RESIZE WINDOW /////
  262. jQuery(window).resize(function () {
  263. if (jQuery(window).width() > 640)
  264. jQuery('.centercontent').removeAttr('style');
  265. reposSearch();
  266. });
  267. ///// CHANGE THEME /////
  268. jQuery('.changetheme a').click(function () {
  269. var c = jQuery(this).attr('class');
  270. if (jQuery('#addonstyle').length == 0) {
  271. if (c != 'default') {
  272. jQuery('head').append('<link id="addonstyle" rel="stylesheet" href="css/style.' + c + '.css" type="text/css" />');
  273. jQuery.cookie("addonstyle", c, { path: '/' });
  274. }
  275. } else {
  276. if (c != 'default') {
  277. jQuery('#addonstyle').attr('href', 'css/style.' + c + '.css');
  278. jQuery.cookie("addonstyle", c, { path: '/' });
  279. } else {
  280. jQuery('#addonstyle').remove();
  281. jQuery.cookie("addonstyle", null);
  282. }
  283. }
  284. });
  285. ///// LOAD ADDON STYLE WHEN IT'S ALREADY SET /////
  286. if (jQuery.cookie('addonstyle')) {
  287. var c = jQuery.cookie('addonstyle');
  288. if (c != '') {
  289. jQuery('head').append('<link id="addonstyle" rel="stylesheet" href="css/style.' + c + '.css" type="text/css" />');
  290. jQuery.cookie("addonstyle", c, { path: '/' });
  291. }
  292. }
  293. });