PluginProbe
FeedWordPress / 2020.0818
FeedWordPress v2020.0818
trunk 0.8 0.9 0.91 0.95 0.96 0.97 0.98 0.981 0.99 0.991 0.992 0.993 2008.1030 2008.1101 2008.1105 2008.1214 2009.0612 2009.0613 2009.0618 2009.0707 2009.1111 2009.1112 2010.0127 2010.0528 All 65 releases
feedwordpress / feedwordpress-elements.js

feedwordpress-elements.js in FeedWordPress 2020.0818, at feedwordpress-elements.js

786 lines 25.1 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 (function($) {
2 var fs = {add:'ajaxAdd',del:'ajaxDel',dim:'ajaxDim',process:'process',recolor:'recolor'}, fwpList;
3
4 fwpList = {
5 settings: {
6 url: ajaxurl, type: 'POST',
7 response: 'ajax-response',
8
9 what: '',
10 alt: 'alternate', altOffset: 0,
11 addColor: null, delColor: null, dimAddColor: null, dimDelColor: null,
12
13 confirm: null,
14 addBefore: null, addAfter: null,
15 delBefore: null, delAfter: null,
16 dimBefore: null, dimAfter: null
17 },
18
19 nonce: function(e,s) {
20 var url = wpAjax.unserialize(e.attr('href'));
21 return s.nonce || url._ajax_nonce || $('#' + s.elementbox + ' input[name=_ajax_nonce]').val() || url._wpnonce || $('#' + s.element + ' input[name=_wpnonce]').val() || 0;
22 },
23
24 parseClass: function(e,t) {
25 var c = [], cl;
26 try {
27 cl = $(e).attr('class') || '';
28 cl = cl.match(new RegExp(t+':[\\S]+'));
29 if ( cl ) { c = cl[0].split(':'); }
30 } catch(r) {}
31 return c;
32 },
33
34 pre: function(e,s,a) {
35 var bg, r;
36 s = $.extend( {}, this.fwpList.settings, {
37 element: null,
38 nonce: 0,
39 target: e.get(0)
40 }, s || {} );
41 if ( $.isFunction( s.confirm ) ) {
42 if ( 'add' != a ) {
43 bg = $('#' + s.element).css('backgroundColor');
44 $('#' + s.element).css('backgroundColor', '#FF9966');
45 }
46 r = s.confirm.call(this,e,s,a,bg);
47 if ( 'add' != a ) { $('#' + s.element).css('backgroundColor', bg ); }
48 if ( !r ) { return false; }
49 }
50 return s;
51 },
52
53 ajaxAdd: function( e, s ) {
54 e = $(e);
55 s = s || {};
56 var list = this, cls = fwpList.parseClass(e,'add'), es, valid, formData;
57 s = fwpList.pre.call( list, e, s, 'add' );
58
59 s.element = cls[2] || e.attr( 'id' ) || s.element || null;
60 if ( cls[3] ) { s.addColor = '#' + cls[3]; }
61 else { s.addColor = s.addColor || '#FFFF33'; }
62
63 if ( !s ) { return false; }
64
65 if ( !e.is('[class^="add:' + list.id + ':"]') ) { return !fwpList.add.call( list, e, s ); }
66
67 if ( !s.element ) { return true; }
68
69 s.action = 'add-' + s.what;
70
71 s.nonce = fwpList.nonce(e,s);
72
73 es = $('#' + s.elementbox + ' :input').not('[name=_ajax_nonce], [name=_wpnonce], [name=action]');
74 valid = wpAjax.validateForm( '#' + s.element );
75 if ( !valid ) { return false; }
76
77 s.data = $.param( $.extend( { _ajax_nonce: s.nonce, action: s.action }, wpAjax.unserialize( cls[4] || '' ) ) );
78 formData = $.isFunction(es.fieldSerialize) ? es.fieldSerialize() : es.serialize();
79 if ( formData ) { s.data += '&' + formData; }
80
81 if ( $.isFunction(s.addBefore) ) {
82 s = s.addBefore( s );
83 if ( !s ) { return true; }
84 }
85 if ( !s.data.match(/_ajax_nonce=[a-f0-9]+/) ) { return true; }
86
87 s.success = function(r) {
88 var res = wpAjax.parseAjaxResponse(r, s.response, s.element), o;
89 if ( !res || res.errors ) { return false; }
90
91 if ( true === res ) { return true; }
92
93 jQuery.each( res.responses, function() {
94 // FIXME: Causes ownerDocument is undefined breakage in WP3.2
95 fwpList.add.call( list, this.data, $.extend( {}, s, { // this.firstChild.nodevalue
96 pos: this.position || 0,
97 id: this.id || 0,
98 oldId: this.oldId || null
99 } ) );
100 } );
101
102 if ( $.isFunction(s.addAfter) ) {
103 o = this.complete;
104 this.complete = function(x,st) {
105 var _s = $.extend( { xml: x, status: st, parsed: res }, s );
106 s.addAfter( r, _s );
107 if ( $.isFunction(o) ) { o(x,st); }
108 };
109 }
110 list.fwpList.recolor();
111 $(list).trigger( 'fwpListAddEnd', [ s, list.fwpList ] );
112 fwpList.clear.call(list,'#' + s.element);
113 };
114
115 $.ajax( s );
116 return false;
117 },
118
119 ajaxDel: function( e, s ) {
120 e = $(e); s = s || {};
121 var list = this, cls = fwpList.parseClass(e,'delete'), element;
122 s = fwpList.pre.call( list, e, s, 'delete' );
123
124 s.element = cls[2] || s.element || null;
125 if ( cls[3] ) { s.delColor = '#' + cls[3]; }
126 else { s.delColor = s.delColor || '#faa'; }
127
128 if ( !s || !s.element ) { return false; }
129
130 s.action = 'delete-' + s.what;
131
132 s.nonce = fwpList.nonce(e,s);
133
134 s.data = $.extend(
135 { action: s.action, id: s.element.split('-').pop(), _ajax_nonce: s.nonce },
136 wpAjax.unserialize( cls[4] || '' )
137 );
138
139 if ( $.isFunction(s.delBefore) ) {
140 s = s.delBefore( s, list );
141 if ( !s ) { return true; }
142 }
143 if ( !s.data._ajax_nonce ) { return true; }
144
145 element = $('#' + s.element);
146
147 if ( 'none' != s.delColor ) {
148 element.css( 'backgroundColor', s.delColor ).fadeOut( 350, function(){
149 list.fwpList.recolor();
150 $(list).trigger( 'fwpListDelEnd', [ s, list.fwpList ] );
151 });
152 } else {
153 list.fwpList.recolor();
154 $(list).trigger( 'fwpListDelEnd', [ s, list.fwpList ] );
155 }
156
157 s.success = function(r) {
158 var res = wpAjax.parseAjaxResponse(r, s.response, s.element), o;
159 if ( !res || res.errors ) {
160 element.stop().stop().css( 'backgroundColor', '#faa' ).show().queue( function() { list.fwpList.recolor(); $(this).dequeue(); } );
161 return false;
162 }
163 if ( $.isFunction(s.delAfter) ) {
164 o = this.complete;
165 this.complete = function(x,st) {
166 element.queue( function() {
167 var _s = $.extend( { xml: x, status: st, parsed: res }, s );
168 s.delAfter( r, _s );
169 if ( $.isFunction(o) ) { o(x,st); }
170 } ).dequeue();
171 };
172 }
173 };
174 $.ajax( s );
175 return false;
176 },
177
178 ajaxDim: function( e, s ) {
179 if ( $(e).parent().css('display') == 'none' ) // Prevent hidden links from being clicked by hotkeys
180 return false;
181 e = $(e); s = s || {};
182 var list = this, cls = fwpList.parseClass(e,'dim'), element, isClass, color, dimColor;
183 s = fwpList.pre.call( list, e, s, 'dim' );
184
185 s.element = cls[2] || s.element || null;
186 s.dimClass = cls[3] || s.dimClass || null;
187 if ( cls[4] ) { s.dimAddColor = '#' + cls[4]; }
188 else { s.dimAddColor = s.dimAddColor || '#FFFF33'; }
189 if ( cls[5] ) { s.dimDelColor = '#' + cls[5]; }
190 else { s.dimDelColor = s.dimDelColor || '#FF3333'; }
191
192 if ( !s || !s.element || !s.dimClass ) { return true; }
193
194 s.action = 'dim-' + s.what;
195
196 s.nonce = fwpList.nonce(e,s);
197
198 s.data = $.extend(
199 { action: s.action, id: s.element.split('-').pop(), dimClass: s.dimClass, _ajax_nonce : s.nonce },
200 wpAjax.unserialize( cls[6] || '' )
201 );
202
203 if ( $.isFunction(s.dimBefore) ) {
204 s = s.dimBefore( s );
205 if ( !s ) { return true; }
206 }
207
208 element = $('#' + s.element);
209 isClass = element.toggleClass(s.dimClass).is('.' + s.dimClass);
210 color = fwpList.getColor( element );
211 element.toggleClass( s.dimClass )
212 dimColor = isClass ? s.dimAddColor : s.dimDelColor;
213 if ( 'none' != dimColor ) {
214 element
215 .animate( { backgroundColor: dimColor }, 'fast' )
216 .queue( function() { element.toggleClass(s.dimClass); $(this).dequeue(); } )
217 .animate( { backgroundColor: color }, { complete: function() { $(this).css( 'backgroundColor', '' ); $(list).trigger( 'fwpListDimEnd', [ s, list.fwpList ] ); } } );
218 } else {
219 $(list).trigger( 'fwpListDimEnd', [ s, list.fwpList ] );
220 }
221
222 if ( !s.data._ajax_nonce ) { return true; }
223
224 s.success = function(r) {
225 var res = wpAjax.parseAjaxResponse(r, s.response, s.element), o;
226 if ( !res || res.errors ) {
227 element.stop().stop().css( 'backgroundColor', '#FF3333' )[isClass?'removeClass':'addClass'](s.dimClass).show().queue( function() { list.fwpList.recolor(); $(this).dequeue(); } );
228 return false;
229 }
230 if ( $.isFunction(s.dimAfter) ) {
231 o = this.complete;
232 this.complete = function(x,st) {
233 element.queue( function() {
234 var _s = $.extend( { xml: x, status: st, parsed: res }, s );
235 s.dimAfter( r, _s );
236 if ( $.isFunction(o) ) { o(x,st); }
237 } ).dequeue();
238 };
239 }
240 };
241
242 $.ajax( s );
243 return false;
244 },
245
246 // From jquery.color.js: jQuery Color Animation by John Resig
247 getColor: function( el ) {
248 if ( el.constructor == Object )
249 el = el.get(0);
250 var elem = el, color, rgbaTrans = new RegExp( "rgba\\(\\s*0,\\s*0,\\s*0,\\s*0\\s*\\)", "i" );
251 do {
252 color = jQuery(elem).css('backgroundColor');
253 if ( color != '' && color != 'transparent' && !color.match(rgbaTrans) || jQuery.nodeName(elem, "body") )
254 break;
255 } while ( elem = elem.parentNode );
256 return color || '#ffffff';
257 },
258
259 add: function( e, s ) {
260 e = $(e);
261 var list = $(this),
262 old = false,
263 _s = { pos: 0, id: 0, oldId: null },
264 ba, ref, color;
265
266 if ( 'string' == typeof s ) {
267 s = { what: s };
268 }
269
270 s = $.extend(_s, this.fwpList.settings, s);
271 if ( !e.size() || !s.what ) { return false; }
272 if ( s.oldId ) { old = $('#' + s.what + '-' + s.oldId); }
273 if ( s.id && ( s.id != s.oldId || !old || !old.size() ) ) { $('#' + s.what + '-' + s.id).remove(); }
274
275 if ( old && old.size() ) {
276 old.before(e);
277 old.remove();
278 } else if ( isNaN(s.pos) ) {
279 ba = 'after';
280 if ( '-' == s.pos.substr(0,1) ) {
281 s.pos = s.pos.substr(1);
282 ba = 'before';
283 }
284 ref = list.find( '#' + s.pos );
285 if ( 1 === ref.size() ) { ref[ba](e); }
286 else { list.append(e); }
287 } else if ( s.pos < 0 ) {
288 list.prepend(e);
289 } else {
290 list.append(e);
291 }
292
293 if ( s.alt ) {
294 if ( ( list.children(':visible').index( e[0] ) + s.altOffset ) % 2 ) { e.removeClass( s.alt ); }
295 else { e.addClass( s.alt ); }
296 }
297
298 if ( 'none' != s.addColor ) {
299 color = fwpList.getColor( e );
300 e.css( 'backgroundColor', s.addColor ).animate( { backgroundColor: color }, { complete: function() { $(this).css( 'backgroundColor', '' ); } } );
301 }
302 list.each( function() { this.fwpList.process( e ); } );
303 return e;
304 },
305
306 clear: function(e) {
307 var list = this, t, tag;
308 e = $(e);
309 if ( list.fwpList && e.parents( '#' + list.id ).size() ) { return; }
310 e.find(':input').each( function() {
311 if ( $(this).parents('.form-no-clear').size() )
312 return;
313 t = this.type.toLowerCase();
314 tag = this.tagName.toLowerCase();
315 if ( 'text' == t || 'password' == t || 'textarea' == tag ) { this.value = ''; }
316 else if ( 'checkbox' == t || 'radio' == t ) { this.checked = false; }
317 else if ( 'select' == tag ) { this.selectedIndex = null; }
318 });
319 },
320
321 process: function(el) {
322 var list = this;
323
324 $('[class^="add:' + list.id + ':"]', el || null)
325 .filter('form').submit( function() { return list.fwpList.add(this); } ).end()
326 .not('form').click( function() { return list.fwpList.add(this); } );
327 $('[class^="delete:' + list.id + ':"]', el || null).click( function() { return list.fwpList.del(this); } );
328 $('[class^="dim:' + list.id + ':"]', el || null).click( function() { return list.fwpList.dim(this); } );
329 },
330
331 recolor: function() {
332 var list = this, items, eo;
333 if ( !list.fwpList.settings.alt ) { return; }
334 items = $('.list-item:visible', list);
335 if ( !items.size() ) { items = $(list).children(':visible'); }
336 eo = [':even',':odd'];
337 if ( list.fwpList.settings.altOffset % 2 ) { eo.reverse(); }
338 items.filter(eo[0]).addClass(list.fwpList.settings.alt).end().filter(eo[1]).removeClass(list.fwpList.settings.alt);
339 },
340
341 init: function() {
342 var lists = this;
343
344 lists.fwpList.process = function(a) {
345 lists.each( function() {
346 this.fwpList.process(a);
347 } );
348 };
349 lists.fwpList.recolor = function() {
350 lists.each( function() {
351 this.fwpList.recolor();
352 } );
353 };
354 }
355 };
356
357 $.fn.fwpList = function( settings ) {
358 this.each( function() {
359 var _this = this;
360 this.fwpList = { settings: $.extend( {}, fwpList.settings, { what: fwpList.parseClass(this,'list')[1] || '' }, settings ) };
361 $.each( fs, function(i,f) { _this.fwpList[i] = function( e, s ) { return fwpList[f].call( _this, e, s ); }; } );
362 } );
363 fwpList.init.call(this);
364 this.fwpList.process();
365 return this;
366 };
367
368 })(jQuery);
369
370 /**
371 * Admin interface: Uses Username/Parameter UI for Feed Settings.
372 *
373 */
374 function feedAuthenticationMethodPress (params) {
375 feedAuthenticationMethod({value: 'basic', node: jQuery(this)});
376 return false;
377 }
378 function feedAuthenticationMethodUnPress (params) {
379 feedAuthenticationMethod({value: '-', node: jQuery(this)});
380 return false;
381 }
382 function feedAuthenticationMethod (params) {
383 var s = jQuery.extend({}, {
384 init: false,
385 value: null,
386 node: jQuery(this)
387 }, params);
388
389 var speed = (s.init ? 0 : 'slow');
390
391 var elDiv = jQuery(s.node).closest('.link-rss-authentication');
392 var elTable = elDiv.find('table');
393 var elMethod = elTable.find('.link-rss-auth-method');
394 var elLink = elDiv.find('.link-rss-userpass-use');
395
396 // Set.
397 if (s.value != null) {
398 elMethod.val(s.value);
399 }
400
401 if (elMethod.val()=='-') {
402 elTable.hide(speed, function () {
403 // Just in case. Make sure that we don't duplicate.
404 elLink.remove();
405
406 jQuery('<a style="display: none" class="add-remove link-rss-userpass-use" href="#">+ Uses username/password</a>')
407 .insertAfter(elTable)
408 .click(feedAuthenticationMethodPress)
409 .show(speed);
410 });
411 } else {
412 elLink.hide(speed, function () { jQuery(this).remove(); } );
413 elTable.show(speed);
414 } /* if */
415 } /* function feedAuthenticationMethod () */
416
417 /**
418 * Admin interface: Live category and tag boxes
419 */
420
421 jQuery(document).ready( function($) {
422 // Category boxes
423 $('.feedwordpress-category-div').each( function () {
424 var this_id = $(this).attr('id');
425 var catAddBefore, catAddAfter;
426 var taxonomyParts, taxonomy, settingName;
427
428 taxonomyParts = this_id.split('-');
429 taxonomyParts.shift(); taxonomyParts.shift();
430 taxonomy = taxonomyParts.join('-');
431
432 settingName = taxonomy + '_tab';
433 if ( taxonomy == 'category' )
434 settingName = 'cats';
435
436 // No need to worry about tab stuff for our purposes
437
438 // Ajax Cat
439 var containerId = $(this).attr('id');
440 var checkboxId = $(this).find('.categorychecklist').attr('id');
441 var newCatId = $(this).find('.new'+taxonomy).attr('id');
442 var responseId = $(this).find('.'+taxonomy+'-ajax-response').attr('id');
443 var taxAdderId = $(this).find('.'+taxonomy+'-adder').attr('id');
444
445 $(this).find('.new'+taxonomy).one( 'focus', function () { $(this).val('').removeClass('form-input-tip'); } );
446 $(this).find('.add-categorychecklist-category-add').click( function() {
447 $(this).parent().children('.new'+taxonomy).focus();
448 } );
449
450 catAddBefore = function (s) {
451 if ( !$('#'+newCatId).val() )
452 return false;
453 s.data += '&' + $( ':checked', '#'+checkboxId ).serialize();
454 return s;
455 }
456 catAddAfter = function (r, s) {
457 // Clear out input box
458 $('.new' + taxonomy, '#'+this_id).val('');
459
460 // Clear out parent dropbox
461 var sup, drop = $('.new' + taxonomy + '-parent', '#'+this_id);
462 var keep = $('.new' + taxonomy, '#'+this_id);
463
464 if ( 'undefined' != s.parsed.responses[0] && (sup = s.parsed.responses[0].supplemental.newcat_parent) ) {
465 sup = sup.replace(/id=['"]new[^'"]*_parent['"]/g, 'id="' + keep.attr('id') + '-parent"');
466 drop.before(sup);
467 $('#'+keep.attr('id')+'-parent').addClass('new' + taxonomy + '-parent');
468 drop.remove();
469 }
470 };
471
472 $('#' + checkboxId).fwpList({
473 alt: '',
474 elementbox: taxAdderId,
475 response: responseId,
476 addBefore: catAddBefore,
477 addAfter: catAddAfter
478 });
479
480 $(this).find('.category-add-toggle').click( function () {
481 $('#' + taxAdderId).toggleClass('wp-hidden-children');
482 $('#' + newCatId).focus();
483 return false;
484 } ); /* $(this).find('.category-add-toggle').click() */
485
486 } ); /* $('.feedwordpress-category-div').each() */
487 } ); /* jQuery(document).ready() */
488
489
490 function fwp_feedspiper () {
491 var data = {
492 action: 'fwp_feeds'
493 };
494
495 return jQuery.ajax({
496 type: "POST",
497 url: ajaxurl,
498 data: data
499 });
500 }
501
502 function fwp_feedcontentspiper (feed_id, callbackOK, callbackFail) {
503 var data = {
504 action: 'fwp_feedcontents',
505 feed_id: feed_id
506 };
507
508 jQuery.ajax({
509 type: "POST",
510 url: ajaxurl,
511 data: data
512 })
513 .done(function (response) { callbackOK(response); })
514 .fail(function (response) { callbackFail(response); });
515 }
516
517 function fwp_feedcontentspicker (feed_id, destination, pickCallback, closeCallback) {
518 var picker_id = 'fwp-feed-contents-picker-' + feed_id;
519
520 jQuery('<div class="fwp-feed-contents-picker" style="display: none;" id="'+picker_id+'"><p>Loading...</p></div>').insertAfter(destination);
521 jQuery('#'+picker_id).show(500);
522
523 fwp_feedcontentspiper(feed_id, function (response) {
524 var ul = '<h4>Using post...</h4><ul>';
525 for (var i=0; i < response.length; i++) {
526 ul += '<li><a class="fwp-feed-contents-picker-pick-'+feed_id+'" href="'
527 +response[i].guid
528 +'">' + response[i].post_title + '</a></li>';
529 }
530 ul += '</ul>';
531 ul += '<a class="fwp-feed-contents-picker-close" href="#" id="fwp-feed-contents-picker-' + feed_id + '-close">x</a>';
532
533 jQuery('#fwp-feed-contents-picker-' + feed_id).html(ul);
534
535 // Set up event handlers.
536 jQuery('#fwp-feed-contents-picker-' + feed_id + '-close').click(function (e) {
537 jQuery('#fwp-feed-contents-picker-' + feed_id).hide(500, function () { jQuery('#fwp-feed-contents-picker-' + feed_id).remove(); });
538 if (typeof(closeCallback)=='function') {
539 closeCallback(feed_id);
540 }
541 e.preventDefault();
542 return false;
543 });
544 jQuery('.fwp-feed-contents-picker-pick-' + feed_id).click(function (e) {
545 jQuery('#fwp-feed-contents-picker-' + feed_id).hide(500, function () { jQuery('#fwp-feed-contents-picker-' + feed_id).remove(); });
546 if (typeof(pickCallback)=='function') {
547 pickCallback(feed_id, jQuery(this).attr('href'));
548 }
549 e.preventDefault();
550 return false;
551 });
552 },
553 function (response) {
554 jQuery('#' + picker_id).addClass('error').html('There was a problem getting a listing of the feed. Sorry!').delay(5000).hide(500, function () { jQuery(this).remove(); });
555 });
556 }
557
558 function fwp_feedspicker (destination, pickCallback, closeCallback) {
559 var dabber = jQuery(destination).attr('id');
560 var picker_id = 'fwp-feeds-picker-' + dabber;
561
562 jQuery('<div class="fwp-feeds-picker" style="display: none;" id="'+picker_id+'"><p>Loading...</p></div>').insertAfter(destination);
563 jQuery('#'+picker_id).show(500);
564
565 fwp_feedspiper()
566 .done(function (response) {
567 var ul = '<h4>Using subscription...</h4><ul>';
568 for (var i=0; i < response.length; i++) {
569 ul += '<li><a class="fwp-feeds-picker-pick-'+dabber+'" href="#feed-'
570 +response[i].id
571 +'">' + response[i].name + '</a></li>';
572 }
573 ul += '</ul>';
574 ul += '<a class="fwp-feeds-picker-close" href="#" id="fwp-feeds-picker-' + dabber + '-close">x</a>';
575
576 jQuery('#fwp-feeds-picker-' + dabber).html(ul);;
577
578 // Set up event handlers.
579 jQuery('#fwp-feeds-picker-' + dabber + '-close').click(function (e) {
580 jQuery('#fwp-feeds-picker-' + dabber).hide(500, function () { jQuery('#fwp-feeds-picker-' + dabber).remove(); });
581 if (typeof(closeCallback)=='function') {
582 closeCallback(destination);
583 }
584 e.preventDefault();
585 return false;
586 });
587 jQuery('.fwp-feeds-picker-pick-' + dabber).click(function (e) {
588 jQuery('#fwp-feeds-picker-' + dabber).hide(500, function () {
589 jQuery('#fwp-feeds-picker-' + dabber).remove();
590 });
591
592 var feed_id = jQuery(this).attr('href').replace(/^#feed-/, '');
593
594 if (typeof(pickCallback)=='function') {
595 pickCallback(feed_id, jQuery(this));
596 }
597 e.preventDefault();
598 return false;
599 });
600 })
601 .fail(function (response) {
602 jQuery('#' + picker_id).addClass('error').html('There was a problem getting a listing of your subscriptions. Sorry!').delay(5000).hide(500, function () { jQuery(this).remove(); });
603 });
604 }
605
606 function fwp_xpathtest_ajax (expression, feed_id, post_id) {
607 var data = {
608 action: 'fwp_xpathtest',
609 xpath: expression,
610 feed_id: feed_id,
611 post_id: post_id
612 };
613
614 return jQuery.ajax({
615 type: "GET",
616 url: ajaxurl,
617 data: data
618 });
619 }
620
621 function fwp_xpathtest_fail (response, result_id, destination) {
622 jQuery('<div class="fwp-xpath-test-results error" style="display: none;" id="'+result_id+'">There was a problem communicating with the server.<p>result = <code>'+response+'</code></p></div>').insertAfter(destination);
623 jQuery('#'+result_id).show(500).delay(3000).hide(500, function () { jQuery(this).remove(); });
624 }
625
626 function fwp_xpathtest_ok (response, result_id, destination) {
627 var dabber = jQuery(destination).attr('id');
628 var resultsHtml = '<ul>';
629
630 if (response.results instanceof Array) {
631 for (var i = 0; i < response.results.length; i++) {
632 resultsHtml += '<li>result['+(i+1).toString()+'] = <code>'+response.results[i]+'</code></li>';
633 }
634 } else {
635 resultsHtml += '<li>result = <code>' + response.results + '</code></li>';
636 } /* if */
637 resultsHtml += '</ul>';
638
639 jQuery('<div class="fwp-xpath-test-results" style="display: none;" id="'+result_id+'"><h4>'+response.expression+'</h4>'+resultsHtml+'</code> <a class="fwp-xpath-test-results-close">x</a></div>').insertAfter(destination);
640
641 var link_id = 'fwp-xpath-test-results-post-'+dabber;
642 if (jQuery('#'+link_id).length > 0) {
643 jQuery('#'+link_id).attr('href', response.guid).html(response.post_title);
644 } else {
645 jQuery('<div id="contain-'+link_id+'" class="fwp-xpath-test-results-post fwp-xpath-test-setting">Using post: <a id="'+link_id+'" href="'+response.guid+'"> '+response.post_title+'</a> (<a href="#" class="fwp-xpath-test-results-post-change">reset</a>)</div>').insertAfter('#'+result_id);
646 } /* if */
647
648 jQuery('#'+result_id).find('.fwp-xpath-test-results-close').click(function (e) {
649 e.preventDefault();
650
651 jQuery('#'+result_id).hide(500, function () { jQuery(this).remove(); });
652 return false;
653 });
654 jQuery('#contain-'+link_id).find('.fwp-xpath-test-results-post-change').click(function (e) {
655 e.preventDefault();
656 jQuery('#contain-'+link_id).remove();
657
658 return false;
659 });
660 jQuery('#'+result_id).show(500);
661 }
662
663 function fwp_xpathtest (expression, destination, feed_id) {
664 var dabber = jQuery(destination).attr('id');
665 var result_id = 'fwp-xpath-test-results-'+dabber;
666 var preset_post_id = 'fwp-xpath-test-results-post-'+dabber;
667 var post_id = jQuery('#'+preset_post_id).attr('href');
668
669 // Clear out any previous results.
670 jQuery('#'+result_id).remove();
671
672 if (jQuery('#xpath-test-feed-id-'+dabber).length > 0) {
673 feed_id = jQuery('#xpath-test-feed-id-'+dabber).val();
674 }
675
676 if ('*' == feed_id) {
677
678 fwp_feedspicker(destination, function (feed_id, a) {
679 var href = a.attr('href');
680 var text = a.text();
681
682 jQuery('<div class="fwp-xpath-test-feed-id fwp-xpath-test-setting" id="contain-xpath-test-feed-id-'+dabber+'">Using sub: <a href="'+href+'">'+text+'</a><input type="hidden" id="xpath-test-feed-id-'+dabber+'" name="xpath_test_feed_id" value="'+feed_id+'" /> (<a href="#" class="fwp-xpath-test-feed-id-change">reset</a>)</div>').insertAfter(destination);
683
684 jQuery('#contain-xpath-test-feed-id-'+dabber).find('.fwp-xpath-test-feed-id-change').click(function (e) {
685 e.preventDefault();
686
687 // If there is a post set, we need to reset that
688 console.log(('#contain-fwp-xpath-test-results-post-'+dabber), jQuery('#contain-fwp-xpath-test-results-post-'+dabber));
689 jQuery('#contain-fwp-xpath-test-results-post-'+dabber).remove();
690
691 // Show yourself out.
692 jQuery('#contain-xpath-test-feed-id-'+dabber).remove();
693 return false;
694 });
695
696 // Now recursively call the function in order to force
697 // a post-picker.
698 fwp_xpathtest(expression, destination, feed_id);
699 });
700 }
701
702 // Check for a pre-selected post GUID.
703 else if (post_id) {
704 fwp_xpathtest_ajax(expression, feed_id, post_id)
705 .done( function (response) { fwp_xpathtest_ok(response, result_id, destination); } )
706 .fail( function (response) { fwp_xpathtest_fail(response, result_id, destination); } );
707 }
708 else {
709 // Pop up the feed content picker
710 fwp_feedcontentspicker(feed_id, destination, function (feed_id, post_id) {
711 fwp_xpathtest_ajax(expression, feed_id, post_id)
712 .done( function (response) { fwp_xpathtest_ok(response, result_id, destination); } )
713 .fail( function (response) { fwp_xpathtest_fail(response, result_id, destination); } );
714 });
715 }
716
717 }
718
719 jQuery(document).ready(function($){
720 if ( $('.xpath-test').length ) {
721 $('.xpath-test').click ( function (e) {
722 e.preventDefault();
723
724 // Pull the local expression from the text box
725 var expr = jQuery(this).closest('tr').find('textarea').val();
726
727 // Check to see if we are on a Feed settings page or
728 // on the global settings page;
729 var feed_id = jQuery('input[name="save_link_id"]').val();
730
731 fwp_xpathtest(expr, jQuery(this), feed_id);
732 return false;
733 });
734 }
735 if ( $('.jaxtag').length ) {
736 tagBox.init();
737 }
738
739 /*$('.fwpfs').toggle(
740 function(){$('.fwpfs').removeClass('slideUp').addClass('slideDown'); setTimeout(function(){if ( $('.fwpfs').hasClass('slideDown') ) { $('.fwpfs').addClass('slide-down'); }}, 10) },
741 function(){$('.fwpfs').removeClass('slideDown').addClass('slideUp'); setTimeout(function(){if ( $('.fwpfs').hasClass('slideUp') ) { $('.fwpfs').removeClass('slide-down'); }}, 10) }
742 );*/
743 $('.fwpfs').bind(
744 'change',
745 function () { this.form.submit(); }
746 );
747 $('#fwpfs-button').css( 'display', 'none' );
748
749 $('table.twofer td.active input[type="radio"], table.twofer td.inactive input[type="radio"]').each( function () {
750 $(this).click( function () {
751 var name = $(this).attr('name');
752 var table = $(this).closest('table');
753 table.find('td').removeClass('active').addClass('inactive');
754 table.find('td:has(input[name="'+name+'"]:checked)').removeClass('inactive').addClass('active');
755 } );
756
757 var name = $(this).attr('name');
758 var table = $(this).closest('table');
759 table.find('td').removeClass('active').addClass('inactive');
760 table.find('td:has(input[name="'+name+'"]:checked)').removeClass('inactive').addClass('active');
761 } );
762
763 $('#turn-on-multiple-sources').click ( function () {
764 $('#add-single-uri').hide();
765 $('#add-multiple-uri').show(600);
766 return false;
767 ;
768 } );
769 $('#turn-off-multiple-sources').click ( function () {
770 $('#add-multiple-uri').hide(600);
771 $('#add-single-uri').show();
772 return false;
773 } );
774 $('#turn-on-opml-upload').click ( function () {
775 $('#add-single-uri').hide();
776 $('#upload-opml').show(600);
777 return false;
778 } );
779 $('#turn-off-opml-upload').click ( function () {
780 $('#upload-opml').hide(600);
781 $('#add-single-uri').show();
782 return false;
783 } );
784 });
785
786