| 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://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( // DOM ready handler. |
| 22 |
function($ /* jQuery passed through this arg. */) |
| 23 |
{ |
| 24 |
$(window).resize(window.tb_position = function() |
| 25 |
{ |
| 26 |
var w = ($(window).width() > 720) ? 720 : $(window).width(), h = $(window).height(), admin_bar_h = ($('body.admin-bar').length) ? 28 : 0; |
| 27 |
$('#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'}); |
| 28 |
$('#TB_ajaxContent').css({'width': w - 50 + 'px', 'height': h - 75 - admin_bar_h + 'px', 'margin': 0, 'padding': 0}); |
| 29 |
}); |
| 30 |
var $rs = $('table.ws-menu-page-table td.ws-menu-page-table-r'), |
| 31 |
$rsToggler = $('> .toggler', $rs), $rsWrapper = $('> .wrapper', $rs); |
| 32 |
|
| 33 |
var $groups = $('div.ws-menu-page-group'/* Query groups. */); |
| 34 |
$groups.each(function(index/* Go through each group, one at a time. */) |
| 35 |
{ |
| 36 |
var $this = $(this), $group = $this, |
| 37 |
title = $.trim($group.attr('title')), |
| 38 |
$header = $('<div class="ws-menu-page-group-header">' + title + '</div>'); |
| 39 |
|
| 40 |
$header.css({'z-index': 1}), $header.insertBefore($group), |
| 41 |
$header.click(function() |
| 42 |
{ |
| 43 |
var $this = $(this), |
| 44 |
$group = $this.next(); |
| 45 |
|
| 46 |
if($this.hasClass('open')) |
| 47 |
$this.add($group).removeClass('open'); |
| 48 |
else $this.add($group).addClass('open'); |
| 49 |
|
| 50 |
return false; |
| 51 |
}); |
| 52 |
if($groups.length > 1 && index === 0) |
| 53 |
{ |
| 54 |
$('<div class="ws-menu-page-groups-hide"><i class="fa fa-chevron-up"></i></div>') |
| 55 |
.insertBefore('div.ws-menu-page-toolbox') |
| 56 |
.click(function(/* Toggle all closed. */) |
| 57 |
{ |
| 58 |
$('div.ws-menu-page-group-header') |
| 59 |
.each(function() |
| 60 |
{ |
| 61 |
var $this = $(this), $group = $this.next(); |
| 62 |
$this.add($group).removeClass('open'); |
| 63 |
}); |
| 64 |
return false; |
| 65 |
}); |
| 66 |
$('<div class="ws-menu-page-groups-show"><i class="fa fa-chevron-down"></i></div>') |
| 67 |
.insertBefore('div.ws-menu-page-toolbox') |
| 68 |
.click(function(/* Toggle all open. */) |
| 69 |
{ |
| 70 |
$('div.ws-menu-page-group-header') |
| 71 |
.each(function() |
| 72 |
{ |
| 73 |
var $this = $(this), $group = $this.next(); |
| 74 |
$this.add($group).addClass('open'); |
| 75 |
}); |
| 76 |
return false; |
| 77 |
}); |
| 78 |
} |
| 79 |
if($group.attr('default-state') === 'open') |
| 80 |
$header.trigger('click'); |
| 81 |
}); |
| 82 |
$rsToggler.click(function() |
| 83 |
{ |
| 84 |
if($rs.hasClass('open')) |
| 85 |
$rsWrapper.hide(), $rs.removeClass('open'); |
| 86 |
else $rsWrapper.show(), $rs.addClass('open'); |
| 87 |
}); |
| 88 |
if($rsToggler.attr('default-state') === 'open') $rsToggler.click(); |
| 89 |
|
| 90 |
$('div.ws-menu-page-r-group-header') |
| 91 |
.click(function(/* Toggle groups in sidebar. */) |
| 92 |
{ |
| 93 |
var $this = $(this), |
| 94 |
$group = $this.next(); |
| 95 |
|
| 96 |
if($this.hasClass('open')) |
| 97 |
$this.add($group).removeClass('open'); |
| 98 |
else $this.add($group).addClass('open'); |
| 99 |
|
| 100 |
return false; |
| 101 |
}); |
| 102 |
$('div.ws-menu-page-group-header:first, div.ws-menu-page-r-group-header:first').css({'margin-top': '0'}); |
| 103 |
$('div.ws-menu-page-group-header:last, div.ws-menu-page-r-group-header:last, div.ws-menu-page-group:last').css({'margin-bottom': '0'}); |
| 104 |
|
| 105 |
$('input.ws-menu-page-media-btn').filter(function(){ return ($(this).attr('rel')) ? true : false; }) |
| 106 |
.click(function() |
| 107 |
{ |
| 108 |
var $this = $(this); |
| 109 |
|
| 110 |
window.send_to_editor = function(html) |
| 111 |
{ |
| 112 |
var $inp, $txt, rel = $.trim($this.attr('rel')), oBg, src; |
| 113 |
|
| 114 |
if(rel && ($inp = $('input#' + rel)).length > 0) |
| 115 |
{ |
| 116 |
oBg = $inp.css('background-color'), |
| 117 |
src = $.trim($(html).attr('src')); |
| 118 |
src = (!src) ? $.trim($('img', html).attr('src')) : src; |
| 119 |
|
| 120 |
$inp.val(src), |
| 121 |
$inp.css({'background-color': '#485230'}), |
| 122 |
setTimeout(function() |
| 123 |
{ |
| 124 |
$inp.css({'background-color': oBg}); |
| 125 |
}, 2000); |
| 126 |
tb_remove(); |
| 127 |
} |
| 128 |
else if(rel && ($txt = $('textarea#' + rel)).length > 0) |
| 129 |
{ |
| 130 |
oBg = $txt.css('background-color'), |
| 131 |
src = $.trim($(html).attr('src')); |
| 132 |
src = (!src) ? $.trim($('img', html).attr('src')) : src; |
| 133 |
|
| 134 |
$txt.val($.trim($txt.val()) + '\n' + src), |
| 135 |
$txt.css({'background-color': '#485230'}), |
| 136 |
setTimeout(function() |
| 137 |
{ |
| 138 |
$txt.css({'background-color': oBg}); |
| 139 |
}, 2000); |
| 140 |
tb_remove(); |
| 141 |
} |
| 142 |
}; |
| 143 |
tb_show('', './media-upload.php?type=image&TB_iframe=true'); |
| 144 |
|
| 145 |
return false; |
| 146 |
}); |
| 147 |
$('form#ws-updates-form') |
| 148 |
.submit(function(/* MailChimp validation. */) |
| 149 |
{ |
| 150 |
var errors = ''; // Initialize. |
| 151 |
|
| 152 |
if(!$.trim($('input#ws-updates-fname').val())) |
| 153 |
errors += 'First Name missing, please try again.\n\n'; |
| 154 |
|
| 155 |
if(!$.trim($('input#ws-updates-lname').val())) |
| 156 |
errors += 'Last Name missing, please try again.\n\n'; |
| 157 |
|
| 158 |
if(!$.trim($('input#ws-updates-email').val())) |
| 159 |
errors += 'Email missing, please try again.\n\n'; |
| 160 |
|
| 161 |
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)) |
| 162 |
errors += 'Invalid email address, please try again.\n\n'; |
| 163 |
|
| 164 |
if(errors = $.trim(errors)) |
| 165 |
{ |
| 166 |
alert('— Oops, you missed something: —\n\n' + errors); |
| 167 |
return false; |
| 168 |
} |
| 169 |
return true; |
| 170 |
}); |
| 171 |
}); |
| 172 |
|