PageRenderTime 59ms CodeModel.GetById 11ms RepoModel.GetById 1ms app.codeStats 0ms

/site/CGControlPanel/js/custom/general.js

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