PageRenderTime 45ms CodeModel.GetById 14ms RepoModel.GetById 1ms app.codeStats 0ms

/wp-admin/js/common.dev.js

https://github.com/jao/jpcamargo
JavaScript | 292 lines | 244 code | 40 blank | 8 comment | 58 complexity | 7fa31a8f765adf779e1460c95432450e MD5 | raw file
  1. var showNotice, adminMenu, columns, validateForm;
  2. (function($){
  3. // sidebar admin menu
  4. adminMenu = {
  5. init : function() {
  6. var menu = $('#adminmenu');
  7. $('.wp-menu-toggle', menu).each( function() {
  8. var t = $(this), sub = t.siblings('.wp-submenu');
  9. if ( sub.length )
  10. t.click(function(){ adminMenu.toggle( sub ); });
  11. else
  12. t.hide();
  13. });
  14. this.favorites();
  15. $('.separator', menu).click(function(){
  16. if ( $('body').hasClass('folded') ) {
  17. adminMenu.fold(1);
  18. deleteUserSetting( 'mfold' );
  19. } else {
  20. adminMenu.fold();
  21. setUserSetting( 'mfold', 'f' );
  22. }
  23. return false;
  24. });
  25. if ( $('body').hasClass('folded') )
  26. this.fold();
  27. this.restoreMenuState();
  28. },
  29. restoreMenuState : function() {
  30. $('li.wp-has-submenu', '#adminmenu').each(function(i, e) {
  31. var v = getUserSetting( 'm'+i );
  32. if ( $(e).hasClass('wp-has-current-submenu') )
  33. return true; // leave the current parent open
  34. if ( 'o' == v )
  35. $(e).addClass('wp-menu-open');
  36. else if ( 'c' == v )
  37. $(e).removeClass('wp-menu-open');
  38. });
  39. },
  40. toggle : function(el) {
  41. el['slideToggle'](150, function() {
  42. el.css('display','');
  43. }).parent().toggleClass( 'wp-menu-open' );
  44. $('.wp-has-submenu', '#adminmenu').each(function(i, e) {
  45. var v = $(e).hasClass('wp-menu-open') ? 'o' : 'c';
  46. setUserSetting( 'm'+i, v );
  47. });
  48. return false;
  49. },
  50. fold : function(off) {
  51. if (off) {
  52. $('body').removeClass('folded');
  53. $('#adminmenu li.wp-has-submenu').unbind();
  54. } else {
  55. $('body').addClass('folded');
  56. $('#adminmenu li.wp-has-submenu').hoverIntent({
  57. over: function(e){
  58. var m, b, h, o, f;
  59. m = $(this).find('.wp-submenu');
  60. b = $(this).offset().top + m.height() + 1; // Bottom offset of the menu
  61. h = $('#wpwrap').height(); // Height of the entire page
  62. o = 60 + b - h;
  63. f = $(window).height() + $(window).scrollTop() - 15; // The fold
  64. if ( f < (b - o) ) {
  65. o = b - f;
  66. }
  67. if ( o > 1 ) {
  68. m.css({'marginTop':'-'+o+'px'});
  69. } else if ( m.css('marginTop') ) {
  70. m.css({'marginTop':''});
  71. }
  72. m.addClass('sub-open');
  73. },
  74. out: function(){ $(this).find('.wp-submenu').removeClass('sub-open').css({'marginTop':''}); },
  75. timeout: 220,
  76. sensitivity: 8,
  77. interval: 100
  78. });
  79. }
  80. },
  81. favorites : function() {
  82. $('#favorite-inside').width( $('#favorite-actions').width() - 4 );
  83. $('#favorite-toggle, #favorite-inside').bind('mouseenter', function() {
  84. $('#favorite-inside').removeClass('slideUp').addClass('slideDown');
  85. setTimeout(function() {
  86. if ( $('#favorite-inside').hasClass('slideDown') ) {
  87. $('#favorite-inside').slideDown(100);
  88. $('#favorite-first').addClass('slide-down');
  89. }
  90. }, 200);
  91. }).bind('mouseleave', function() {
  92. $('#favorite-inside').removeClass('slideDown').addClass('slideUp');
  93. setTimeout(function() {
  94. if ( $('#favorite-inside').hasClass('slideUp') ) {
  95. $('#favorite-inside').slideUp(100, function() {
  96. $('#favorite-first').removeClass('slide-down');
  97. });
  98. }
  99. }, 300);
  100. });
  101. }
  102. };
  103. $(document).ready(function(){ adminMenu.init(); });
  104. // show/hide/save table columns
  105. columns = {
  106. init : function() {
  107. $('.hide-column-tog', '#adv-settings').click( function() {
  108. var column = $(this).val();
  109. if ( $(this).attr('checked') )
  110. $('.column-' + column).show();
  111. else
  112. $('.column-' + column).hide();
  113. columns.save_manage_columns_state();
  114. });
  115. },
  116. save_manage_columns_state : function() {
  117. var hidden = $('.manage-column').filter(':hidden').map(function() { return this.id; }).get().join(',');
  118. $.post(ajaxurl, {
  119. action: 'hidden-columns',
  120. hidden: hidden,
  121. screenoptionnonce: $('#screenoptionnonce').val(),
  122. page: pagenow
  123. });
  124. }
  125. }
  126. $(document).ready(function(){columns.init();});
  127. validateForm = function( form ) {
  128. return !$( form ).find('.form-required').filter( function() { return $('input:visible', this).val() == ''; } ).addClass( 'form-invalid' ).change( function() { $(this).removeClass( 'form-invalid' ); } ).size();
  129. }
  130. })(jQuery);
  131. // stub for doing better warnings
  132. showNotice = {
  133. warn : function() {
  134. var msg = commonL10n.warnDelete || '';
  135. if ( confirm(msg) ) {
  136. return true;
  137. }
  138. return false;
  139. },
  140. note : function(text) {
  141. alert(text);
  142. }
  143. };
  144. jQuery(document).ready( function($) {
  145. var lastClicked = false, checks, first, last, checked;
  146. // pulse
  147. $('div.fade').animate( { opacity: .5 }, 400)
  148. .animate( { opacity: 1 }, 400)
  149. .animate( { opacity: .5 }, 400)
  150. .animate( { opacity: 1 }, 400);
  151. // Move .updated and .error alert boxes
  152. $('div.wrap h2:first').nextAll('div.updated, div.error').addClass('below-h2');
  153. $('div.updated, div.error').not('.below-h2').insertAfter( $('div.wrap h2:first') );
  154. // screen settings tab
  155. $('#show-settings-link').click(function () {
  156. if ( ! $('#screen-options-wrap').hasClass('screen-options-open') )
  157. $('#contextual-help-link-wrap').css('visibility', 'hidden');
  158. $('#screen-options-wrap').slideToggle('fast', function(){
  159. if ( $(this).hasClass('screen-options-open') ) {
  160. $('#show-settings-link').css({'backgroundImage':'url("images/screen-options-right.gif")'});
  161. $('#contextual-help-link-wrap').css('visibility', '');
  162. $(this).removeClass('screen-options-open');
  163. } else {
  164. $('#show-settings-link').css({'backgroundImage':'url("images/screen-options-right-up.gif")'});
  165. $(this).addClass('screen-options-open');
  166. }
  167. });
  168. return false;
  169. });
  170. // help tab
  171. $('#contextual-help-link').click(function () {
  172. if ( ! $('#contextual-help-wrap').hasClass('contextual-help-open') )
  173. $('#screen-options-link-wrap').css('visibility', 'hidden');
  174. $('#contextual-help-wrap').slideToggle('fast', function() {
  175. if ( $(this).hasClass('contextual-help-open') ) {
  176. $('#contextual-help-link').css({'backgroundImage':'url("images/screen-options-right.gif")'});
  177. $('#screen-options-link-wrap').css('visibility', '');
  178. $(this).removeClass('contextual-help-open');
  179. } else {
  180. $('#contextual-help-link').css({'backgroundImage':'url("images/screen-options-right-up.gif")'});
  181. $(this).addClass('contextual-help-open');
  182. }
  183. });
  184. return false;
  185. });
  186. // check all checkboxes
  187. $('tbody').children().children('.check-column').find(':checkbox').click( function(e) {
  188. if ( 'undefined' == e.shiftKey ) { return true; }
  189. if ( e.shiftKey ) {
  190. if ( !lastClicked ) { return true; }
  191. checks = $( lastClicked ).closest( 'form' ).find( ':checkbox' );
  192. first = checks.index( lastClicked );
  193. last = checks.index( this );
  194. checked = $(this).attr('checked');
  195. if ( 0 < first && 0 < last && first != last ) {
  196. checks.slice( first, last ).attr( 'checked', function(){
  197. if ( $(this).closest('tr').is(':visible') )
  198. return checked ? 'checked' : '';
  199. return '';
  200. });
  201. }
  202. }
  203. lastClicked = this;
  204. return true;
  205. });
  206. $('thead, tfoot').find(':checkbox').click( function(e) {
  207. var c = $(this).attr('checked'),
  208. kbtoggle = 'undefined' == typeof toggleWithKeyboard ? false : toggleWithKeyboard,
  209. toggle = e.shiftKey || kbtoggle;
  210. $(this).closest( 'table' ).children( 'tbody' ).filter(':visible')
  211. .children().children('.check-column').find(':checkbox')
  212. .attr('checked', function() {
  213. if ( $(this).closest('tr').is(':hidden') )
  214. return '';
  215. if ( toggle )
  216. return $(this).attr( 'checked' ) ? '' : 'checked';
  217. else if (c)
  218. return 'checked';
  219. return '';
  220. });
  221. $(this).closest('table').children('thead, tfoot').filter(':visible')
  222. .children().children('.check-column').find(':checkbox')
  223. .attr('checked', function() {
  224. if ( toggle )
  225. return '';
  226. else if (c)
  227. return 'checked';
  228. return '';
  229. });
  230. });
  231. $('#default-password-nag-no').click( function() {
  232. setUserSetting('default_password_nag', 'hide');
  233. $('div.default-password-nag').hide();
  234. return false;
  235. });
  236. });
  237. jQuery(document).ready( function($){
  238. var turboNag = $('span.turbo-nag', '#user_info');
  239. if ( !turboNag.length || ('undefined' != typeof(google) && google.gears) )
  240. return;
  241. if ( 'undefined' != typeof GearsFactory ) {
  242. return;
  243. } else {
  244. try {
  245. if ( ( 'undefined' != typeof window.ActiveXObject && ActiveXObject('Gears.Factory') ) ||
  246. ( 'undefined' != typeof navigator.mimeTypes && navigator.mimeTypes['application/x-googlegears'] ) ) {
  247. return;
  248. }
  249. } catch(e){}
  250. }
  251. turboNag.show();
  252. });