PluginProbe
FeedWordPress / 2011.0512
FeedWordPress v2011.0512
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 2011.0512, at feedwordpress-elements.js

490 lines 15.0 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 fwpList.add.call( list, this.data, $.extend( {}, s, { // this.firstChild.nodevalue
95 pos: this.position || 0,
96 id: this.id || 0,
97 oldId: this.oldId || null
98 } ) );
99 } );
100
101 if ( $.isFunction(s.addAfter) ) {
102 o = this.complete;
103 this.complete = function(x,st) {
104 var _s = $.extend( { xml: x, status: st, parsed: res }, s );
105 s.addAfter( r, _s );
106 if ( $.isFunction(o) ) { o(x,st); }
107 };
108 }
109 list.fwpList.recolor();
110 $(list).trigger( 'fwpListAddEnd', [ s, list.fwpList ] );
111 fwpList.clear.call(list,'#' + s.element);
112 };
113
114 $.ajax( s );
115 return false;
116 },
117
118 ajaxDel: function( e, s ) {
119 e = $(e); s = s || {};
120 var list = this, cls = fwpList.parseClass(e,'delete'), element;
121 s = fwpList.pre.call( list, e, s, 'delete' );
122
123 s.element = cls[2] || s.element || null;
124 if ( cls[3] ) { s.delColor = '#' + cls[3]; }
125 else { s.delColor = s.delColor || '#faa'; }
126
127 if ( !s || !s.element ) { return false; }
128
129 s.action = 'delete-' + s.what;
130
131 s.nonce = fwpList.nonce(e,s);
132
133 s.data = $.extend(
134 { action: s.action, id: s.element.split('-').pop(), _ajax_nonce: s.nonce },
135 wpAjax.unserialize( cls[4] || '' )
136 );
137
138 if ( $.isFunction(s.delBefore) ) {
139 s = s.delBefore( s, list );
140 if ( !s ) { return true; }
141 }
142 if ( !s.data._ajax_nonce ) { return true; }
143
144 element = $('#' + s.element);
145
146 if ( 'none' != s.delColor ) {
147 element.css( 'backgroundColor', s.delColor ).fadeOut( 350, function(){
148 list.fwpList.recolor();
149 $(list).trigger( 'fwpListDelEnd', [ s, list.fwpList ] );
150 });
151 } else {
152 list.fwpList.recolor();
153 $(list).trigger( 'fwpListDelEnd', [ s, list.fwpList ] );
154 }
155
156 s.success = function(r) {
157 var res = wpAjax.parseAjaxResponse(r, s.response, s.element), o;
158 if ( !res || res.errors ) {
159 element.stop().stop().css( 'backgroundColor', '#faa' ).show().queue( function() { list.fwpList.recolor(); $(this).dequeue(); } );
160 return false;
161 }
162 if ( $.isFunction(s.delAfter) ) {
163 o = this.complete;
164 this.complete = function(x,st) {
165 element.queue( function() {
166 var _s = $.extend( { xml: x, status: st, parsed: res }, s );
167 s.delAfter( r, _s );
168 if ( $.isFunction(o) ) { o(x,st); }
169 } ).dequeue();
170 };
171 }
172 };
173 $.ajax( s );
174 return false;
175 },
176
177 ajaxDim: function( e, s ) {
178 if ( $(e).parent().css('display') == 'none' ) // Prevent hidden links from being clicked by hotkeys
179 return false;
180 e = $(e); s = s || {};
181 var list = this, cls = fwpList.parseClass(e,'dim'), element, isClass, color, dimColor;
182 s = fwpList.pre.call( list, e, s, 'dim' );
183
184 s.element = cls[2] || s.element || null;
185 s.dimClass = cls[3] || s.dimClass || null;
186 if ( cls[4] ) { s.dimAddColor = '#' + cls[4]; }
187 else { s.dimAddColor = s.dimAddColor || '#FFFF33'; }
188 if ( cls[5] ) { s.dimDelColor = '#' + cls[5]; }
189 else { s.dimDelColor = s.dimDelColor || '#FF3333'; }
190
191 if ( !s || !s.element || !s.dimClass ) { return true; }
192
193 s.action = 'dim-' + s.what;
194
195 s.nonce = fwpList.nonce(e,s);
196
197 s.data = $.extend(
198 { action: s.action, id: s.element.split('-').pop(), dimClass: s.dimClass, _ajax_nonce : s.nonce },
199 wpAjax.unserialize( cls[6] || '' )
200 );
201
202 if ( $.isFunction(s.dimBefore) ) {
203 s = s.dimBefore( s );
204 if ( !s ) { return true; }
205 }
206
207 element = $('#' + s.element);
208 isClass = element.toggleClass(s.dimClass).is('.' + s.dimClass);
209 color = fwpList.getColor( element );
210 element.toggleClass( s.dimClass )
211 dimColor = isClass ? s.dimAddColor : s.dimDelColor;
212 if ( 'none' != dimColor ) {
213 element
214 .animate( { backgroundColor: dimColor }, 'fast' )
215 .queue( function() { element.toggleClass(s.dimClass); $(this).dequeue(); } )
216 .animate( { backgroundColor: color }, { complete: function() { $(this).css( 'backgroundColor', '' ); $(list).trigger( 'fwpListDimEnd', [ s, list.fwpList ] ); } } );
217 } else {
218 $(list).trigger( 'fwpListDimEnd', [ s, list.fwpList ] );
219 }
220
221 if ( !s.data._ajax_nonce ) { return true; }
222
223 s.success = function(r) {
224 var res = wpAjax.parseAjaxResponse(r, s.response, s.element), o;
225 if ( !res || res.errors ) {
226 element.stop().stop().css( 'backgroundColor', '#FF3333' )[isClass?'removeClass':'addClass'](s.dimClass).show().queue( function() { list.fwpList.recolor(); $(this).dequeue(); } );
227 return false;
228 }
229 if ( $.isFunction(s.dimAfter) ) {
230 o = this.complete;
231 this.complete = function(x,st) {
232 element.queue( function() {
233 var _s = $.extend( { xml: x, status: st, parsed: res }, s );
234 s.dimAfter( r, _s );
235 if ( $.isFunction(o) ) { o(x,st); }
236 } ).dequeue();
237 };
238 }
239 };
240
241 $.ajax( s );
242 return false;
243 },
244
245 // From jquery.color.js: jQuery Color Animation by John Resig
246 getColor: function( el ) {
247 if ( el.constructor == Object )
248 el = el.get(0);
249 var elem = el, color, rgbaTrans = new RegExp( "rgba\\(\\s*0,\\s*0,\\s*0,\\s*0\\s*\\)", "i" );
250 do {
251 color = jQuery.curCSS(elem, 'backgroundColor');
252 if ( color != '' && color != 'transparent' && !color.match(rgbaTrans) || jQuery.nodeName(elem, "body") )
253 break;
254 } while ( elem = elem.parentNode );
255 return color || '#ffffff';
256 },
257
258 add: function( e, s ) {
259 e = $(e);
260 var list = $(this),
261 old = false,
262 _s = { pos: 0, id: 0, oldId: null },
263 ba, ref, color;
264
265 if ( 'string' == typeof s ) {
266 s = { what: s };
267 }
268
269 s = $.extend(_s, this.fwpList.settings, s);
270 if ( !e.size() || !s.what ) { return false; }
271 if ( s.oldId ) { old = $('#' + s.what + '-' + s.oldId); }
272 if ( s.id && ( s.id != s.oldId || !old || !old.size() ) ) { $('#' + s.what + '-' + s.id).remove(); }
273
274 if ( old && old.size() ) {
275 old.before(e);
276 old.remove();
277 } else if ( isNaN(s.pos) ) {
278 ba = 'after';
279 if ( '-' == s.pos.substr(0,1) ) {
280 s.pos = s.pos.substr(1);
281 ba = 'before';
282 }
283 ref = list.find( '#' + s.pos );
284 if ( 1 === ref.size() ) { ref[ba](e); }
285 else { list.append(e); }
286 } else if ( s.pos < 0 ) {
287 list.prepend(e);
288 } else {
289 list.append(e);
290 }
291
292 if ( s.alt ) {
293 if ( ( list.children(':visible').index( e[0] ) + s.altOffset ) % 2 ) { e.removeClass( s.alt ); }
294 else { e.addClass( s.alt ); }
295 }
296
297 if ( 'none' != s.addColor ) {
298 color = fwpList.getColor( e );
299 e.css( 'backgroundColor', s.addColor ).animate( { backgroundColor: color }, { complete: function() { $(this).css( 'backgroundColor', '' ); } } );
300 }
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 jQuery(document).ready( function($) {
371 // Category boxes
372 $('.feedwordpress-category-div').each( function () {
373 var this_id = $(this).attr('id');
374 var catAddBefore, catAddAfter;
375 var taxonomyParts, taxonomy, settingName;
376
377 taxonomyParts = this_id.split('-');
378 taxonomyParts.shift(); taxonomyParts.shift();
379 taxonomy = taxonomyParts.join('-');
380
381 settingName = taxonomy + '_tab';
382 if ( taxonomy == 'category' )
383 settingName = 'cats';
384
385 // No need to worry about tab stuff for our purposes
386
387 // Ajax Cat
388 var containerId = $(this).attr('id');
389 var checkboxId = $(this).find('.categorychecklist').attr('id');
390 var newCatId = $(this).find('.new'+taxonomy).attr('id');
391 var responseId = $(this).find('.'+taxonomy+'-ajax-response').attr('id');
392 var taxAdderId = $(this).find('.'+taxonomy+'-adder').attr('id');
393
394 $(this).find('.new'+taxonomy).one( 'focus', function () { $(this).val('').removeClass('form-input-tip'); } );
395 $(this).find('.add-categorychecklist-category-add').click( function() {
396 $(this).parent().children('.new'+taxonomy).focus();
397 } );
398
399 catAddBefore = function (s) {
400 if ( !$('#'+newCatId).val() )
401 return false;
402 s.data += '&' + $( ':checked', '#'+checkboxId ).serialize();
403 return s;
404 }
405 catAddAfter = function (r, s) {
406 // Clear out input box
407 $('.new' + taxonomy, '#'+this_id).val('');
408
409 // Clear out parent dropbox
410 var sup, drop = $('.new' + taxonomy + '-parent', '#'+this_id);
411 var keep = $('.new' + taxonomy, '#'+this_id);
412
413 if ( 'undefined' != s.parsed.responses[0] && (sup = s.parsed.responses[0].supplemental.newcat_parent) ) {
414 sup = sup.replace(/id=['"]new[^'"]*_parent['"]/g, 'id="' + keep.attr('id') + '-parent"');
415 drop.before(sup);
416 $('#'+keep.attr('id')+'-parent').addClass('new' + taxonomy + '-parent');
417 drop.remove();
418 }
419 };
420
421 $('#' + checkboxId).fwpList({
422 alt: '',
423 elementbox: taxAdderId,
424 response: responseId,
425 addBefore: catAddBefore,
426 addAfter: catAddAfter
427 });
428
429 $(this).find('.category-add-toggle').click( function () {
430 $('#' + taxAdderId).toggleClass('wp-hidden-children');
431 $('#' + newCatId).focus();
432 return false;
433 } ); /* $(this).find('.category-add-toggle').click() */
434
435 } ); /* $('.feedwordpress-category-div').each() */
436 } ); /* jQuery(document).ready() */
437
438 jQuery(document).ready(function($){
439 if ( $('.jaxtag').length ) {
440 tagBox.init();
441 }
442
443 $('.fwpfs').toggle(
444 function(){$('.fwpfs').removeClass('slideUp').addClass('slideDown'); setTimeout(function(){if ( $('.fwpfs').hasClass('slideDown') ) { $('.fwpfs').addClass('slide-down'); }}, 10) },
445 function(){$('.fwpfs').removeClass('slideDown').addClass('slideUp'); setTimeout(function(){if ( $('.fwpfs').hasClass('slideUp') ) { $('.fwpfs').removeClass('slide-down'); }}, 10) }
446 );
447 $('.fwpfs').bind(
448 'change',
449 function () { this.form.submit(); }
450 );
451 $('#fwpfs-button').css( 'display', 'none' );
452
453 $('table.twofer td.active input[type="radio"], table.twofer td.inactive input[type="radio"]').each( function () {
454 $(this).click( function () {
455 var name = $(this).attr('name');
456 var table = $(this).closest('table');
457 table.find('td').removeClass('active').addClass('inactive');
458 table.find('td:has(input[name="'+name+'"]:checked)').removeClass('inactive').addClass('active');
459 } );
460
461 var name = $(this).attr('name');
462 var table = $(this).closest('table');
463 table.find('td').removeClass('active').addClass('inactive');
464 table.find('td:has(input[name="'+name+'"]:checked)').removeClass('inactive').addClass('active');
465 } );
466
467 $('#turn-on-multiple-sources').click ( function () {
468 $('#add-single-uri').hide();
469 $('#add-multiple-uri').show(600);
470 return false;
471 ;
472 } );
473 $('#turn-off-multiple-sources').click ( function () {
474 $('#add-multiple-uri').hide(600);
475 $('#add-single-uri').show();
476 return false;
477 } );
478 $('#turn-on-opml-upload').click ( function () {
479 $('#add-single-uri').hide();
480 $('#upload-opml').show(600);
481 return false;
482 } );
483 $('#turn-off-opml-upload').click ( function () {
484 $('#upload-opml').hide(600);
485 $('#add-single-uri').show();
486 return false;
487 } );
488 });
489
490