PluginProbe
FeedWordPress / 2012.1212
FeedWordPress v2012.1212
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 2012.1212, at feedwordpress-elements.js

550 lines 16.6 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.curCSS(elem, '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
303 list.each( function() { this.fwpList.process( e ); } );
304 return e;
305 },
306
307 clear: function(e) {
308 var list = this, t, tag;
309 e = $(e);
310 if ( list.fwpList && e.parents( '#' + list.id ).size() ) { return; }
311 e.find(':input').each( function() {
312 if ( $(this).parents('.form-no-clear').size() )
313 return;
314 t = this.type.toLowerCase();
315 tag = this.tagName.toLowerCase();
316 if ( 'text' == t || 'password' == t || 'textarea' == tag ) { this.value = ''; }
317 else if ( 'checkbox' == t || 'radio' == t ) { this.checked = false; }
318 else if ( 'select' == tag ) { this.selectedIndex = null; }
319 });
320 },
321
322 process: function(el) {
323 var list = this;
324
325 $('[class^="add:' + list.id + ':"]', el || null)
326 .filter('form').submit( function() { return list.fwpList.add(this); } ).end()
327 .not('form').click( function() { return list.fwpList.add(this); } );
328 $('[class^="delete:' + list.id + ':"]', el || null).click( function() { return list.fwpList.del(this); } );
329 $('[class^="dim:' + list.id + ':"]', el || null).click( function() { return list.fwpList.dim(this); } );
330 },
331
332 recolor: function() {
333 var list = this, items, eo;
334 if ( !list.fwpList.settings.alt ) { return; }
335 items = $('.list-item:visible', list);
336 if ( !items.size() ) { items = $(list).children(':visible'); }
337 eo = [':even',':odd'];
338 if ( list.fwpList.settings.altOffset % 2 ) { eo.reverse(); }
339 items.filter(eo[0]).addClass(list.fwpList.settings.alt).end().filter(eo[1]).removeClass(list.fwpList.settings.alt);
340 },
341
342 init: function() {
343 var lists = this;
344
345 lists.fwpList.process = function(a) {
346 lists.each( function() {
347 this.fwpList.process(a);
348 } );
349 };
350 lists.fwpList.recolor = function() {
351 lists.each( function() {
352 this.fwpList.recolor();
353 } );
354 };
355 }
356 };
357
358 $.fn.fwpList = function( settings ) {
359 this.each( function() {
360 var _this = this;
361 this.fwpList = { settings: $.extend( {}, fwpList.settings, { what: fwpList.parseClass(this,'list')[1] || '' }, settings ) };
362 $.each( fs, function(i,f) { _this.fwpList[i] = function( e, s ) { return fwpList[f].call( _this, e, s ); }; } );
363 } );
364 fwpList.init.call(this);
365 this.fwpList.process();
366 return this;
367 };
368
369 })(jQuery);
370
371 /**
372 * Admin interface: Uses Username/Parameter UI for Feed Settings.
373 *
374 */
375 function feedAuthenticationMethodPress (params) {
376 feedAuthenticationMethod({value: 'basic', node: jQuery(this)});
377 return false;
378 }
379 function feedAuthenticationMethodUnPress (params) {
380 feedAuthenticationMethod({value: '-', node: jQuery(this)});
381 return false;
382 }
383 function feedAuthenticationMethod (params) {
384 var s = jQuery.extend({}, {
385 init: false,
386 value: null,
387 node: jQuery(this)
388 }, params);
389
390 var speed = (s.init ? 0 : 'slow');
391
392 var elDiv = jQuery(s.node).closest('.link-rss-authentication');
393 var elTable = elDiv.find('table');
394 var elMethod = elTable.find('.link-rss-auth-method');
395 var elLink = elDiv.find('.link-rss-userpass-use');
396
397 console.log('--- ---');
398 console.log(s.node);
399 console.log(elDiv);
400 console.log(elTable);
401 console.log(elMethod);
402 console.log(elLink);
403 console.log(elMethod.val());
404
405 // Set.
406 if (s.value != null) {
407 elMethod.val(s.value);
408 }
409
410 if (elMethod.val()=='-') {
411 elTable.hide(speed, function () {
412 // Just in case. Make sure that we don't duplicate.
413 elLink.remove();
414
415 jQuery('<a style="display: none" class="add-remove link-rss-userpass-use" href="#">+ Uses username/password</a>')
416 .insertAfter(elTable)
417 .click(feedAuthenticationMethodPress)
418 .show(speed);
419 });
420 } else {
421 elLink.hide(speed, function () { jQuery(this).remove(); } );
422 elTable.show(speed);
423 } /* if */
424 } /* function feedAuthenticationMethod () */
425
426 /**
427 * Admin interface: Live category and tag boxes
428 */
429
430 jQuery(document).ready( function($) {
431 // Category boxes
432 $('.feedwordpress-category-div').each( function () {
433 var this_id = $(this).attr('id');
434 var catAddBefore, catAddAfter;
435 var taxonomyParts, taxonomy, settingName;
436
437 taxonomyParts = this_id.split('-');
438 taxonomyParts.shift(); taxonomyParts.shift();
439 taxonomy = taxonomyParts.join('-');
440
441 settingName = taxonomy + '_tab';
442 if ( taxonomy == 'category' )
443 settingName = 'cats';
444
445 // No need to worry about tab stuff for our purposes
446
447 // Ajax Cat
448 var containerId = $(this).attr('id');
449 var checkboxId = $(this).find('.categorychecklist').attr('id');
450 var newCatId = $(this).find('.new'+taxonomy).attr('id');
451 var responseId = $(this).find('.'+taxonomy+'-ajax-response').attr('id');
452 var taxAdderId = $(this).find('.'+taxonomy+'-adder').attr('id');
453
454 $(this).find('.new'+taxonomy).one( 'focus', function () { $(this).val('').removeClass('form-input-tip'); } );
455 $(this).find('.add-categorychecklist-category-add').click( function() {
456 $(this).parent().children('.new'+taxonomy).focus();
457 } );
458
459 catAddBefore = function (s) {
460 if ( !$('#'+newCatId).val() )
461 return false;
462 s.data += '&' + $( ':checked', '#'+checkboxId ).serialize();
463 return s;
464 }
465 catAddAfter = function (r, s) {
466 // Clear out input box
467 $('.new' + taxonomy, '#'+this_id).val('');
468
469 // Clear out parent dropbox
470 var sup, drop = $('.new' + taxonomy + '-parent', '#'+this_id);
471 var keep = $('.new' + taxonomy, '#'+this_id);
472
473 if ( 'undefined' != s.parsed.responses[0] && (sup = s.parsed.responses[0].supplemental.newcat_parent) ) {
474 sup = sup.replace(/id=['"]new[^'"]*_parent['"]/g, 'id="' + keep.attr('id') + '-parent"');
475 drop.before(sup);
476 $('#'+keep.attr('id')+'-parent').addClass('new' + taxonomy + '-parent');
477 drop.remove();
478 }
479 };
480
481 $('#' + checkboxId).fwpList({
482 alt: '',
483 elementbox: taxAdderId,
484 response: responseId,
485 addBefore: catAddBefore,
486 addAfter: catAddAfter
487 });
488
489 $(this).find('.category-add-toggle').click( function () {
490 $('#' + taxAdderId).toggleClass('wp-hidden-children');
491 $('#' + newCatId).focus();
492 return false;
493 } ); /* $(this).find('.category-add-toggle').click() */
494
495 } ); /* $('.feedwordpress-category-div').each() */
496 } ); /* jQuery(document).ready() */
497
498 jQuery(document).ready(function($){
499 if ( $('.jaxtag').length ) {
500 tagBox.init();
501 }
502
503 $('.fwpfs').toggle(
504 function(){$('.fwpfs').removeClass('slideUp').addClass('slideDown'); setTimeout(function(){if ( $('.fwpfs').hasClass('slideDown') ) { $('.fwpfs').addClass('slide-down'); }}, 10) },
505 function(){$('.fwpfs').removeClass('slideDown').addClass('slideUp'); setTimeout(function(){if ( $('.fwpfs').hasClass('slideUp') ) { $('.fwpfs').removeClass('slide-down'); }}, 10) }
506 );
507 $('.fwpfs').bind(
508 'change',
509 function () { this.form.submit(); }
510 );
511 $('#fwpfs-button').css( 'display', 'none' );
512
513 $('table.twofer td.active input[type="radio"], table.twofer td.inactive input[type="radio"]').each( function () {
514 $(this).click( function () {
515 var name = $(this).attr('name');
516 var table = $(this).closest('table');
517 table.find('td').removeClass('active').addClass('inactive');
518 table.find('td:has(input[name="'+name+'"]:checked)').removeClass('inactive').addClass('active');
519 } );
520
521 var name = $(this).attr('name');
522 var table = $(this).closest('table');
523 table.find('td').removeClass('active').addClass('inactive');
524 table.find('td:has(input[name="'+name+'"]:checked)').removeClass('inactive').addClass('active');
525 } );
526
527 $('#turn-on-multiple-sources').click ( function () {
528 $('#add-single-uri').hide();
529 $('#add-multiple-uri').show(600);
530 return false;
531 ;
532 } );
533 $('#turn-off-multiple-sources').click ( function () {
534 $('#add-multiple-uri').hide(600);
535 $('#add-single-uri').show();
536 return false;
537 } );
538 $('#turn-on-opml-upload').click ( function () {
539 $('#add-single-uri').hide();
540 $('#upload-opml').show(600);
541 return false;
542 } );
543 $('#turn-off-opml-upload').click ( function () {
544 $('#upload-opml').hide(600);
545 $('#add-single-uri').show();
546 return false;
547 } );
548 });
549
550