aioseop_module.js
11.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
if ( typeof aiosp_data != 'undefined' ) {
jQuery.each( aiosp_data, function( index, value ) {
// aiosp_data[index] = value.json.replace(/"/g, '"');
// aiosp_data[index] = jQuery.parseJSON( value );
if ( index == 0 ) {
if ( typeof value.condshow == 'undefined' ) {
aiosp_data[index].condshow = [];
}
} else {
if ( typeof value.condshow != 'undefined' ) {
aiosp_data[0].condshow = jQuery.merge( aiosp_data[0].condshow, value.condshow );
}
}
});
aiosp_data = aiosp_data[0];
}
function toggleVisibility(id) {
var e = document.getElementById(id);
if (e.style.display == 'block')
e.style.display = 'none';
else
e.style.display = 'block';
}
function countChars(field,cntfield) {
var extra = 0;
if ( ( field.name == 'aiosp_title' ) && ( typeof aiosp_title_extra !== 'undefined' ) ) {
extra = aiosp_title_extra;
}
cntfield.value = field.value.length + extra;
}
function aioseop_get_field_value( field ) {
if ( field.length == 0 ) return field;
cur = jQuery('[name=' + field + ']');
if ( cur.length == 0 ) return field;
type = cur.attr('type');
if ( type == "checkbox" || type == "radio" )
cur = jQuery('input[name=' + field + ']:checked');
return cur.val();
}
function aioseop_get_field_values( field ) {
arr = [];
cur = jQuery('[name=' + field + ']');
if ( cur.length == 0 ) return field;
type = cur.attr('type');
if ( type == "checkbox" || type == "radio" )
jQuery('input[name=' + field + ']:checked').each(function() {
arr.push(jQuery(this).val());
});
if ( arr.length <= 0 )
arr.push(cur.val());
return arr;
}
function aioseop_eval_condshow_logic( statement ) {
var lhs, rhs;
if ( ( typeof statement ) == 'object' ) {
lhs = statement['lhs'];
rhs = statement['rhs'];
if ( lhs !== null && ( ( typeof lhs ) == 'object' ) )
lhs = aioseop_eval_condshow_logic( statement['lhs'] );
if ( rhs !== null && ( typeof rhs ) == 'object' )
rhs = aioseop_eval_condshow_logic( statement['rhs'] );
lhs = aioseop_get_field_value( lhs );
rhs = aioseop_get_field_value( rhs );
switch ( statement['op'] ) {
case 'NOT': return ( ! lhs );
case 'AND': return ( lhs && rhs );
case 'OR' : return ( lhs || rhs );
case '==' : return ( lhs == rhs );
case '!=' : return ( lhs != rhs );
default : return null;
}
}
return statement;
}
function aioseop_do_condshow_match( index, value ) {
if ( typeof value != 'undefined' ) {
matches = true;
jQuery.each(value, function(subopt, setting) {
var statement;
if ( ( typeof setting ) == 'object' ) {
statement = aioseop_eval_condshow_logic( setting );
if ( !statement ) {
matches = false;
}
} else {
if ( subopt.match(/\\\[\\\]/) ) { // special case for these -- pdb
cur = aioseop_get_field_values( subopt );
if ( jQuery.inArray( setting, cur, 0 ) < 0 ) {
matches = false;
}
} else {
cur = aioseop_get_field_value( subopt );
if ( cur != setting ) {
matches = false;
}
}
}
});
if ( matches ) {
jQuery('#' + index + '_wrapper' ).show();
} else {
jQuery('#' + index + '_wrapper' ).hide();
}
return matches;
}
return false;
}
function aioseop_add_condshow_handlers( index, value ) {
if ( typeof value != 'undefined' ) {
jQuery.each(value, function(subopt, setting) {
jQuery('[name=' + subopt + ']').bind( "change keyup", function() {
aioseop_do_condshow_match( index, value );
});
});
}
}
function aioseop_do_condshow( condshow ) {
if ( typeof aiosp_data.condshow != 'undefined' ) {
jQuery.each(aiosp_data.condshow, function(index, value) {
aioseop_do_condshow_match( index, value );
aioseop_add_condshow_handlers( index, value );
});
}
}
jQuery(document).ready(function(){
if (typeof aiosp_data != 'undefined') {
if ( typeof aiosp_data.condshow != 'undefined' ) {
aioseop_do_condshow( aiosp_data.condshow );
}
}
});
jQuery(document).ready(function() {
var image_field;
jQuery('.aioseop_upload_image_button').click(function() {
window.send_to_editor = aioseopNewSendToEditor;
image_field = jQuery(this).next();
formfield = image_field.attr('name');
tb_show('', 'media-upload.php?type=image&TB_iframe=true');
return false;
});
aioseopStoreSendToEditor = window.send_to_editor;
aioseopNewSendToEditor = function(html) {
imgurl = jQuery('img',html).attr('src');
if ( typeof(imgurl) !== undefined )
image_field.val(imgurl);
tb_remove();
window.send_to_editor = aioseopStoreSendToEditor;
};
});
// props to commentluv for this fix
// workaround for bug that causes radio inputs to lose settings when meta box is dragged.
// http://core.trac.wordpress.org/ticket/16972
jQuery(document).ready(function(){
// listen for drag drop of metaboxes , bind mousedown to .hndle so it only fires when starting to drag
jQuery('.hndle').mousedown(function(){
// set live event listener for mouse up on the content .wrap and wait a tick to give the dragged div time to settle before firing the reclick function
jQuery('.wrap').mouseup(function(){store_radio(); setTimeout('reclick_radio();',50);});
})
});
/**
* stores object of all radio buttons that are checked for entire form
*/
if(typeof store_radio != 'function') {
function store_radio(){
var radioshack = {};
jQuery('input[type="radio"]').each(function(){
if(jQuery(this).is(':checked')){
radioshack[jQuery(this).attr('name')] = jQuery(this).val();
}
jQuery(document).data('radioshack',radioshack);
});
}
}
/**
* detect mouseup and restore all radio buttons that were checked
*/
if(typeof reclick_radio != 'function') {
function reclick_radio(){
// get object of checked radio button names and values
var radios = jQuery(document).data('radioshack');
//step thru each object element and trigger a click on it's corresponding radio button
for(key in radios){
jQuery('input[name="'+key+'"]').filter('[value="'+radios[key]+'"]').trigger('click');
}
// unbind the event listener on .wrap (prevents clicks on inputs from triggering function)
jQuery('.wrap').unbind('mouseup');
}
}
function aioseop_handle_ajax_call( action, settings, options, success) {
var aioseop_sack = new sack(ajaxurl);
aioseop_sack.execute = 1;
aioseop_sack.method = 'POST';
aioseop_sack.setVar( "action", action );
aioseop_sack.setVar( "settings", settings );
aioseop_sack.setVar( "options", options );
if ( typeof success != 'undefined' ) {
aioseop_sack.onCompletion = success;
}
aioseop_sack.setVar( "nonce-aioseop", jQuery('input[name="nonce-aioseop"]').val() );
aioseop_sack.onError = function() {alert('Ajax error on saving.'); };
aioseop_sack.runAJAX();
}
function aioseop_handle_post_url( action, settings, options, success) {
jQuery("div#aiosp_"+settings).fadeOut('fast', function() {
var loading = '<label class="aioseop_loading aioseop_'+settings+'_loading"></label> Please wait...';
jQuery("div#aiosp_"+settings).fadeIn('fast', function() {
aioseop_handle_ajax_call( action, settings, options, success);
});
jQuery("div#aiosp_"+settings).html(loading);
})
};
function aioseop_is_overflowed(element) {
return element.scrollHeight > element.clientHeight || element.scrollWidth > element.clientWidth;
}
function aioseop_overflow_border( el ) {
if ( aioseop_is_overflowed(el) ) {
el.className = 'aioseop_option_div aioseop_overflowed';
} else {
el.className = 'aioseop_option_div';
}
}
jQuery(document).ready(function() {
jQuery("#poststuff .aioseop_radio_type input[type='radio']").on( 'click', function() {
var previousValue = jQuery(this).attr('previousValue');
var name = jQuery(this).attr('name');
if ( typeof previousValue == 'undefined' ) {
if ( jQuery(this).prop( "checked" ) ) {
jQuery(this).prop( 'checked', true );
jQuery(this).attr('previousValue', 'checked' );
} else {
jQuery(this).prop( 'checked', false );
jQuery(this).attr('previousValue', false );
}
return;
}
if (previousValue == 'checked') {
jQuery(this).prop('checked', false);
jQuery(this).attr('previousValue', false);
} else {
jQuery("input[name="+name+"]:radio").attr('previousValue', false);
jQuery(this).attr('previousValue', 'checked');
}
});
if ( typeof aiosp_data.pointers != 'undefined' ) {
jQuery.each(aiosp_data.pointers, function(index, value) {
if ( value != 'undefined' && value.pointer_text != '' ) {
aioseop_show_pointer( index, value );
}
});
}
/*
jQuery("#aiosp_settings_form").delegate("input[name='Submit']", "click", function() {
aioseop_handle_post_url('aioseop_ajax_save_settings', 'ajax_settings_message', jQuery('form#aiosp_settings_form').serialize() );
return false;
});
*/
jQuery(".all-in-one-seo_page_all-in-one-seo-pack-pro-aioseop_feature_manager #aiosp_settings_form .aioseop_settings_left").delegate("input[name='Submit']", "click", function(e) {
e.preventDefault();
return false;
});
jQuery(".all-in-one-seo_page_all-in-one-seo-pack-pro-aioseop_feature_manager #aiosp_settings_form").delegate("input[name='Submit']", "click", function(e) {
e.preventDefault();
aioseop_handle_post_url('aioseop_ajax_save_settings', 'ajax_settings_message', jQuery('form#aiosp_settings_form').serialize(),
function() {
jQuery('.wp-has-current-submenu').fadeIn('fast', function() {
aioseop_handle_ajax_call('aioseop_ajax_get_menu_links', 'ajax_settings_message', jQuery.param( {target: '.wp-has-current-submenu > ul'} ) );
});
} );
return false;
});
var selectors = "div.aioseop_multicheckbox_type div.aioseop_option_div, #aiosp_sitemap_debug div.aioseop_option_div, #aiosp_performance_status div.aioseop_option_div";
/*
jQuery(selectors).each(function() {
aioseop_overflow_border(this);
});
var resizeTimer;
jQuery(window).resize(function() {
clearTimeout(resizeTimer);
resizeTimer = setTimeout(jQuery(selectors).each(function() {
aioseop_overflow_border(this);
}), 250);
});
*/
jQuery("div#aiosp_sitemap_addl_pages_metabox").delegate("input[name='Submit']", "click", function() {
aioseop_handle_post_url('aioseop_ajax_save_url', 'sitemap_addl_pages', jQuery('div#aiosp_sitemap_addl_pages_metabox input, div#aiosp_sitemap_addl_pages_metabox select').serialize() );
return false;
});
jQuery("div#aiosp_sitemap_addl_pages_metabox").delegate("a.aiosp_delete_url", "click", function(e) {
e.preventDefault();
aioseop_handle_post_url('aioseop_ajax_delete_url', 'sitemap_addl_pages', jQuery(this).attr("title") );
return false;
});
jQuery("div#aiosp_opengraph_scan_header").delegate("input[name='aiosp_opengraph_scan_header']", "click", function(e) {
e.preventDefault();
aioseop_handle_post_url('aioseop_ajax_scan_header', 'opengraph_scan_header', jQuery('div#aiosp_opengraph_scan_header').serialize() );
return false;
});
jQuery( 'input[name="aiosp_sitemap_posttypes[]"][value="all"]', 'input[name="aiosp_sitemap_taxonomies[]"][value="all"]' ).click(function () {
jQuery(this).parents('div:eq(0)').find(':checkbox').attr('checked', this.checked);
});
jQuery( 'input[name="aiosp_sitemap_posttypes[]"][value!="all"]', 'input[name="aiosp_sitemap_taxonomies[]"][value!="all"]' ).click(function () {
if ( !this.checked )
jQuery(this).parents('div:eq(0)').find('input[value="all"]:checkbox').attr('checked', this.checked);
});
jQuery(".aioseop_tab:not(:first)").hide();
jQuery(".aioseop_tab:first").show();
jQuery("a.aioseop_header_tab").click(function(){
var stringref = jQuery(this).attr("href").split('#')[1];
jQuery('.aioseop_tab:not(#'+stringref+')').hide('slow');
jQuery('.aioseop_tab#' + stringref).show('slow');
jQuery('.aioseop_header_tab[href!=#'+stringref+']').removeClass('active');
jQuery('.aioseop_header_tab[href=#' + stringref+']').addClass('active');
return false;
});
});