Source Code Documentation


s2member\includes\menu-pages\menu-pages.js


  1. /**
  2. * Core JavaScript routines for administrative menu pages.
  3. *
  4. * This is the development version of the code.
  5. * Which ultimately produces menu-pages-min.js.
  6. *
  7. * This file is included with all WordPress® themes/plugins by WebSharks, Inc.
  8. *
  9. * Copyright: © 2009-2011
  10. * {@link http://www.websharks-inc.com/ WebSharks, Inc.}
  11. * (coded in the USA)
  12. *
  13. * Released under the terms of the GNU General Public License.
  14. * You should have received a copy of the GNU General Public License,
  15. * along with this software. In the main directory, see: /licensing/
  16. * If not, see: {@link http://www.gnu.org/licenses/}.
  17. *
  18. * @package WebSharks\Menu Pages
  19. * @since x.xx
  20. */
  21. jQuery(document).ready (function($)
  22. {
  23. $('div#ws-menu-page-js-c-w').hide /* Hide JavaScript conflict warning. */ ();
  24.  
  25. $(window).resize ( /* Global function. */tb_position /* Thickbox resizer/positioner. */ = function()
  26. {
  27. var w = ($(window).width () > 720) ? 720 : $(window).width (), h = $(window).height (), admin_bar_h = ($('body.admin-bar').length) ? 28 : 0;
  28. $('#TB_window').css ({'width': w - 50 + 'px', 'height': h - 45 - admin_bar_h + 'px', 'top': 25 + admin_bar_h + 'px', 'margin-top': 0, 'margin-left': '-' + parseInt(((w - 50) / 2), 10) + 'px'});
  29. $('#TB_ajaxContent').css ({'width': w - 50 + 'px', 'height': h - 75 - admin_bar_h + 'px', 'margin': 0, 'padding': 0});
  30. });
  31.  
  32. var $groups = /* Query groups. */ $('div.ws-menu-page-group');
  33. $groups.each ( /* Go through each group, one at a time. */function(index)
  34. {
  35. var $this = $(this), ins = '<ins>+</ins>', $group = $this, title = $.trim ($group.attr ('title'));
  36.  
  37. var $header = $('<div class="ws-menu-page-group-header">' + ins + title + '</div>');
  38.  
  39. $header.css /* Stack them sequentially, top to bottom. */ ({'z-index': 100 - index});
  40.  
  41. $header.insertBefore ($group), $group.hide (), $header.click (function()
  42. {
  43. var $this = $(this), $ins = $('ins', $this), $group = $this.next ();
  44.  
  45. if ($group.css ('display') === 'none')
  46. $this.addClass ('open'), $ins.html ('-'), $group.show ();
  47.  
  48. else // Else remove open class and hide group.
  49. $this.removeClass ('open'), $ins.html ('+'), $group.hide ();
  50.  
  51. return /* Return. */ false;
  52. });
  53. if /* These are the buttons for showing/hiding all groups. */ ($groups.length > 1 && index === 0)
  54. {
  55. $('<div class="ws-menu-page-groups-show">+</div>').insertBefore ($header).click (function()
  56. {
  57. $('div.ws-menu-page-group-header').each (function()
  58. {
  59. var $this = $(this), $ins = $('ins', $this), $group = $this.next ();
  60.  
  61. $this.addClass ('open'), $ins.html ('-'), $group.show ();
  62.  
  63. return; // Return.
  64. });
  65. return /* Return. */ false;
  66. });
  67. $('<div class="ws-menu-page-groups-hide">-</div>').insertBefore ($header).click (function()
  68. {
  69. $('div.ws-menu-page-group-header').each (function()
  70. {
  71. var $this = $(this), $ins = $('ins', $this), $group = $this.next ();
  72.  
  73. $this.removeClass ('open'), $ins.html ('+'), $group.hide ();
  74.  
  75. return; // Return.
  76. });
  77. return /* Return. */ false;
  78. });
  79. }
  80. if ($group.attr ('default-state') === 'open')
  81. $header.trigger ('click');
  82.  
  83. return; // Return.
  84. });
  85. if /* We only apply these special margins when there are multiple groups. */ ($groups.length > 1)
  86. {
  87. $('div.ws-menu-page-group-header:first').css ({'margin-right': '140px'});
  88. $('div.ws-menu-page-group:first').css ({'margin-right': '145px'});
  89. }
  90. $('div.ws-menu-page-r-group-header').click (function()
  91. {
  92. var $this = $(this), $group = $this.next ('div.ws-menu-page-r-group');
  93.  
  94. if ($group.css ('display') === 'none')
  95. $('ins', $this).html ('-'), $this.addClass ('open'), $group.show ();
  96.  
  97. else // Otherwise, we hide this group.
  98. {
  99. $('ins', $this).html ('+'), $this.removeClass ('open');
  100. $group.hide ();
  101. }
  102. return /* Return. */ false;
  103. });
  104. $('div.ws-menu-page-group-header:first, div.ws-menu-page-r-group-header:first').css ({'margin-top': '0'});
  105. $('div.ws-menu-page-group > div.ws-menu-page-section:first-child > h3').css ({'margin-top': '0'});
  106. $('div.ws-menu-page-readme > div.readme > div.section:last-child').css ({'border-bottom-width': '0'});
  107.  
  108. $('input.ws-menu-page-media-btn').filter ( /* Only those that have a rel attribute. */function()
  109. {
  110. return /* Must have rel targeting an input id. */ ($(this).attr ('rel')) ? true : false;
  111. })
  112. .click ( /* Attach click events to media buttons with send_to_editor(). */function()
  113. {
  114. var $this = /* Record a reference to the media button here. */ $(this);
  115.  
  116. window.send_to_editor = /* Works with Thickbox. */ function(html)
  117. {
  118. var $inp, $txt, rel = $.trim ($this.attr ('rel'));
  119.  
  120. if /* An input field? */ (rel && ($inp = $('input#' + rel)).length > 0)
  121. {
  122. var oBg = $inp.css ('background-color'), src = $.trim ($(html).attr ('src'));
  123. src = (!src) ? $.trim ($('img', html).attr ('src')) : src;
  124.  
  125. $inp.val (src), $inp.css ({'background-color': '#FFFFCC'}), setTimeout(function()
  126. {
  127. $inp.css ({'background-color': oBg});
  128. }, 2000);
  129.  
  130. tb_remove /* Close. */ ();
  131.  
  132. return; // Return.
  133. }
  134. else if /* Textarea? */ (rel && ($txt = $('textarea#' + rel)).length > 0)
  135. {
  136. var oBg = $txt.css ('background-color'), src = $.trim ($(html).attr ('src'));
  137. src = (!src) ? $.trim ($('img', html).attr ('src')) : src;
  138.  
  139. $txt.val ($.trim ($txt.val ()) + '\n' + src), $txt.css ({'background-color': '#FFFFCC'}), setTimeout(function()
  140. {
  141. $txt.css ({'background-color': oBg});
  142. }, 2000);
  143.  
  144. tb_remove /* Close. */ ();
  145.  
  146. return; // Return.
  147. }
  148. };
  149. tb_show('', './media-upload.php?type=image&TB_iframe=true');
  150.  
  151. return /* Return. */ false;
  152. });
  153. $('form#ws-updates-form').submit (function()
  154. {
  155. var errors = /* Intialize string of errors. */ '';
  156.  
  157. if (!$.trim ($('input#ws-updates-fname').val ()))
  158. errors += 'First Name missing, please try again.\n\n';
  159.  
  160. if (!$.trim ($('input#ws-updates-lname').val ()))
  161. errors += 'Last Name missing, please try again.\n\n';
  162.  
  163. if (!$.trim ($('input#ws-updates-email').val ()))
  164. errors += 'Email missing, please try again.\n\n';
  165.  
  166. else if (!$('input#ws-updates-email').val ().match (/^([a-z_~0-9\+\-]+)(((\.?)([a-z_~0-9\+\-]+))*)(@)([a-z0-9]+)(((-*)([a-z0-9]+))*)(((\.)([a-z0-9]+)(((-*)([a-z0-9]+))*))*)(\.)([a-z]{2,6})$/i))
  167. errors += 'Invalid email address, please try again.\n\n';
  168.  
  169. if (errors = $.trim (errors))
  170. {
  171. alert('— Oops, you missed something: —\n\n' + errors);
  172.  
  173. return false;
  174. }
  175. return true;
  176. });
  177. });

s2member\includes\menu-pages\menu-pages.js

Source Code Documentation