| [ Index ] |
PHP Cross Reference of zeList |
[Summary view] [Print] [Text view]
1 // this file contains all the scripts used in the link edit page 2 3 4 5 function new_tag_remove_tag() { 6 var id = jQuery(this).attr('id'); 7 var num = id.substr(10); 8 var current_tags = jQuery('#tags-input').val().split(','); 9 delete current_tags[num]; 10 var new_tags = []; 11 jQuery.each(current_tags, function(key, val) { 12 if (val && !val.match(/^\s+$/) && '' != val) { 13 new_tags = new_tags.concat(val); 14 } 15 }); 16 jQuery('#tags-input').val( 17 new_tags.join(',').replace(/\s*,+\s*/, ',').replace(/,+/, ',') 18 .replace(/,+\s+,+/, ',').replace(/,+\s*$/, '').replace( 19 /^\s*,+/, '')); 20 tag_update_quickclicks(); 21 jQuery('#newtag').focus(); 22 return false; 23 } 24 25 function tag_update_quickclicks() { 26 if (jQuery('#tags-input').length == 0) 27 return; 28 var current_tags = jQuery('#tags-input').val().split(','); 29 jQuery('#tagchecklist').empty(); 30 shown = false; 31 // jQuery.merge( current_tags, current_tags ); // this doesn't work anymore, 32 // need something to array_unique 33 jQuery.each(current_tags, function(key, val) { 34 val = val.replace(/^\s+/, '').replace(/\s+$/, ''); // trim 35 if (!val.match(/^\s+$/) && '' != val) { 36 txt = '<span><a id="tag-check-' + key 37 + '" class="ntdelbutton">X</a> ' + val 38 + '</span> '; 39 jQuery('#tagchecklist').append(txt); 40 jQuery('#tag-check-' + key).click(new_tag_remove_tag); 41 shown = true; 42 } 43 }); 44 if (shown) 45 jQuery('#tagchecklist').prepend( 46 '<strong>' + linkL10n.tagsUsed + '</strong><br />'); 47 } 48 49 function tag_flush_to_text(e, a) { 50 a = a || false; 51 var text = a ? jQuery(a).text() : jQuery('#newtag').val(); 52 var newtags = jQuery('#tags-input').val(); 53 54 var t = text.replace(/\s*([^,]+).*/, '$1,'); 55 newtags += ',' 56 57 if (newtags.indexOf(t) != -1) 58 return false; 59 60 newtags += text; 61 62 // massage 63 newtags = newtags.replace(/\s+,+\s*/g, ',').replace(/,+/g, ',').replace( 64 /,+\s+,+/g, ',').replace(/,+\s*$/g, '').replace(/^\s*,+/g, ''); 65 jQuery('#tags-input').val(newtags); 66 tag_update_quickclicks(); 67 if (!a) { 68 jQuery('#newtag').val(''); 69 jQuery('#newtag').focus(); 70 } 71 return false; 72 } 73 74 function tag_save_on_publish() { 75 if (jQuery('#newtag').val() != linkL10n.addTag) 76 tag_flush_to_text(); 77 } 78 79 function tag_press_key(e) { 80 if (13 == e.keyCode) { 81 tag_flush_to_text(); 82 return false; 83 } 84 }; 85 86 function wordCount(txt) { 87 var tc = 0; 88 txt = txt.replace( /<.[^<>]*?>/g, ' ' ).replace( / /gi, ' ' ); 89 txt = txt.replace( /[0-9.(),;:!?%#$¿'"_+=\\/-]*/g, ''); 90 txt.replace( /\S\s+/g, function(){tc++;} ); 91 return tc; 92 } 93 94 95 jQuery(document).ready( function(e) { 96 97 // add owner on the fly 98 jQuery('#owner_add_toggle').click(function() { jQuery('#owner_add').toggle(); return false; }); 99 jQuery('#owner_add_email').one('focus',function() { jQuery('#owner_add_email').val('');}); 100 jQuery('#owner_add_submit').click(function(e) { 101 var owner_add_email = jQuery('#owner_add_email').val(); 102 if(!owner_add_email.length) return false; 103 jQuery.ajax({ 104 type: 'POST', 105 url: linkL10n.ajax_submit, 106 data: { 107 action : 'instant_create_owner', 108 _ajax_nonce : jQuery('#owner_add_nonce').val(), 109 email : owner_add_email, 110 link_id : jQuery('#link_id').val() 111 }, 112 success: function(response) { 113 jQuery('#linkownerdiv .inside').html(response); 114 }, 115 error: function(response) { 116 if(response && response.responseText) jQuery('#owner_add_response').html(response.responseText); 117 } 118 }); 119 return false; 120 }); 121 122 123 jQuery('#tagcloud-link').click(function() { 124 jQuery.ajax({ 125 type: 'POST', 126 url: 'admin-ajax.php', 127 data: { 128 action : 'get-linktagcloud', 129 }, 130 dataType: 'json', 131 success: function(response) { 132 if(response.ok) { 133 html = '<p id="the-tagcloud">' + response.data + '</p>'; 134 jQuery('#tagcloud-link').after(html); 135 jQuery('#the-tagcloud a').click( function() { 136 tag_flush_to_text(0, this); 137 return false; 138 }); 139 } 140 }, 141 error: function(reponse) { 142 if(response.responseText) jQuery('#tagcloud-link').after('<p id="the-tagcloud">' + response.data + '</p>'); 143 } 144 }); 145 return false; 146 }); 147 148 function doSuccess(element) { 149 jQuery('#' + element + '_response').html(''); 150 jQuery('#' + element + '_response').addClass('success'); 151 jQuery('#' + element + '_response').append('<img src="' + linkL10n.admin_images + '/yes.png" />'); 152 jQuery('#' + element + '_response').show(); 153 } 154 function doError(element) { 155 jQuery('#' + element + '_response').html(''); 156 jQuery('#' + element + '_response').addClass('error'); 157 jQuery('#' + element + '_response').append('<img src="' + linkL10n.admin_images + '/no.png" />'); 158 jQuery('#' + element + '_response').show(); 159 } 160 function doLoading(element) { 161 jQuery('#' + element + '_response').html(''); 162 jQuery('#' + element + '_response').removeClass('success'); 163 jQuery('#' + element + '_response').removeClass('error'); 164 jQuery('#' + element + '_response').append('<img src="' + linkL10n.admin_images + '/loading.gif" />'); 165 jQuery('#' + element + '_response').show(); 166 } 167 168 // close postboxes that should be closed 169 jQuery('.if-js-closed').removeClass('if-js-closed').addClass( 170 'closed'); 171 172 jQuery('#link_name').focus(); 173 // postboxes 174 postboxes.add_postbox_toggles('link'); 175 176 // Ajax Cat 177 var newCat = jQuery('#newcat').one('focus', function() { 178 jQuery(this).val('').removeClass('form-input-tip') 179 }); 180 jQuery('#category-add-submit').click( function() { 181 newCat.focus(); 182 }); 183 184 var noSyncChecks = false; // prophylactic. necessary? 185 var syncChecks = function() { 186 if (noSyncChecks) 187 return; 188 noSyncChecks = true; 189 var th = jQuery(this); 190 var c = th.is(':checked'); 191 var id = th.val().toString(); 192 jQuery('#in-category-' + id + ', #in-popular-category-'+ id).attr('checked', c); 193 noSyncChecks = false; 194 }; 195 196 var catAddAfter = function(r, s) { 197 jQuery(s.what + ' response_data', r).each( 198 function() { 199 var t = jQuery(jQuery(this).text()); 200 t.find('label').each( 201 function() { 202 var th = jQuery(this); 203 var val = th.find('input').val(); 204 var id = th.find('input')[0].id 205 jQuery('#' + id).change(syncChecks); 206 var name = jQuery.trim(th.text()); 207 var o = jQuery('<option value="' + parseInt( val, 10) + '"></option>').text(name); 208 }); 209 }); 210 }; 211 jQuery('#categorychecklist').wpList( { 212 alt : '', 213 what : 'zelist-link-category', 214 response : 'category-ajax-response', 215 addAfter : catAddAfter 216 }); 217 218 jQuery('a[href="#categories-all"]').click( function() { 219 deleteUserSetting('cats'); 220 }); 221 jQuery('a[href="#categories-pop"]').click( function() { 222 setUserSetting('cats', 'pop'); 223 }); 224 if ('pop' == getUserSetting('cats')) 225 jQuery('a[href="#categories-pop"]').click(); 226 227 // category tabs 228 var categoryTabs = jQuery('#category-tabs').tabs(); 229 jQuery('#category-add-toggle').click( 230 function() { 231 jQuery(this).parents('div:first').toggleClass('wp-hidden-children'); 232 //categoryTabs.tabsClick(1); 233 return false; 234 }); 235 jQuery('.categorychecklist :checkbox').change(syncChecks).filter(':checked').change(); 236 237 // status inline edit 238 function updateText() { 239 jQuery('#link-status-display').html(jQuery('#link_status :selected').text()); 240 /* 241 * 242 * if (jQuery('#hidden_link_status').val() == 'draft') { if 243 * (jQuery('#link_status option[value=publish]').length != 0) { 244 * jQuery('#link_status option[value=publish]').remove(); 245 * jQuery('#link_status').val(jQuery('#hidden_link_status').val()); } } 246 * else { jQuery('#link_status 247 * option[value=publish]').html(linkL10n.published); } 248 * jQuery('.edit-link-status').show(); 249 * 250 * if (jQuery('#link_status :selected').val() == 'private' || 251 * jQuery('#link_status :selected').val() == 'publish') { 252 * jQuery('#save-link-status').hide(); } else { 253 * jQuery('#save-link-status').show(); if (jQuery('#link_status 254 * :selected').val() == 'pending') { 255 * jQuery('#save-link-status').show().val(linkL10n.savePending); } else { 256 * jQuery('#save-link-status').show().val(linkL10n.saveDraft); } } 257 */ 258 } 259 260 jQuery('.edit-link-status').click( function() { 261 if (jQuery('#link-status-select').is(":hidden")) { 262 jQuery('#link-status-select').slideDown("normal"); 263 jQuery(this).hide(); 264 } 265 return false; 266 }); 267 jQuery('.save-link-status').click( function() { 268 jQuery('#link-status-select').slideUp("normal"); 269 jQuery('.edit-link-status').show(); 270 updateText(); 271 return false; 272 }); 273 jQuery('.cancel-link-status').click( function() { 274 jQuery('#link-status-select').slideUp("normal"); 275 jQuery('#link_status').val(jQuery('#hidden_link_status').val()); 276 jQuery('.edit-link-status').show(); 277 updateText(); 278 return false; 279 }); 280 281 // show/hide ban reasons 282 jQuery('#link-banreason').hide(); 283 jQuery('select[name="link_status"]').change(function(e) { 284 var status = jQuery(this).val(); 285 if(status == 'deny') jQuery('#link-banreason').show(); 286 else jQuery('#link-banreason').hide(); 287 }); 288 289 290 // tags 291 jQuery('#tags-input').hide(); 292 tag_update_quickclicks(); 293 // add the quickadd form 294 jQuery('#jaxtag') 295 .prepend( 296 '<span id="ajaxtag"><input type="text" name="newtag" id="newtag" class="form-input-tip" size="16" autocomplete="off" value="' 297 + linkL10n.addTag 298 + '" /><input type="button" class="button" id="tagadd" value="' 299 + linkL10n.add 300 + '" tabindex="3" /><input type="hidden"/><input type="hidden"/><span class="howto">' 301 + linkL10n.separate + '</span></span>'); 302 jQuery('#tagadd').click(tag_flush_to_text); 303 jQuery('#newtag').focus( function() { 304 if (this.value == linkL10n.addTag) 305 jQuery(this).val('').removeClass('form-input-tip'); 306 }); 307 jQuery('#newtag').blur( 308 function() { 309 if (this.value == '') 310 jQuery(this).val(linkL10n.addTag).addClass( 311 'form-input-tip'); 312 }); 313 314 // auto-save tags on link save/publish 315 jQuery('#publish').click(tag_save_on_publish); 316 jQuery('#save-link').click(tag_save_on_publish); 317 318 jQuery('#newtag').suggest( 319 'admin-ajax.php?action=ajax-link-tag-search', { 320 delay : 500, 321 minchars : 2, 322 multiple : true, 323 multipleSep : ", " 324 }); 325 jQuery('#newtag').keypress(tag_press_key); 326 327 328 // image upload 329 jQuery('#link_image_iframe').hide(); 330 jQuery('#add_link_image').click(function(e) { 331 jQuery('#link_image_iframe').toggle(); 332 return false; 333 }); 334 335 jQuery('.response').hide(); 336 337 jQuery("#link_url").focus( function(e) { 338 jQuery('#link_url_response').hide(); 339 }); 340 jQuery("#link_name").focus( function(e) { 341 jQuery('#link_name_response').hide(); 342 }); 343 jQuery("#link_rss").focus( function(e) { 344 jQuery('#link_rss_response').hide(); 345 }); 346 // URL checking 347 348 jQuery(".check_url").blur( function(e) { 349 //if(jQuery('#editlink').length) return false; // no check on edit page 350 var skip_existing = false; 351 if(jQuery('#editlink').length) skip_existing = true; 352 353 var input_id = jQuery(this).attr('id'); 354 var input = jQuery(this); 355 if(!input.val().length) return false; 356 357 var nonce = jQuery('#check_url').val(); 358 359 var type = 'url'; 360 if(jQuery(this).hasClass('rss')) type = 'rss'; 361 362 doLoading(input_id); 363 jQuery('#'+ input_id + '_response').show(); 364 jQuery(input).attr('disabled', 'disabled'); 365 366 jQuery.ajax({ 367 type: 'POST', 368 url: linkL10n.ajax_submit, 369 data: { 370 action : 'check_url', 371 _ajax_nonce : nonce, 372 url : input.val(), 373 type : type, 374 skip_existing : skip_existing 375 376 }, 377 dataType: 'json', 378 success: function(response) { 379 if (response.ok) doSuccess(input_id); 380 else doError(input_id); 381 382 if(response.url) input.val(response.url); 383 if(response.data) jQuery('#' + input_id + '_response').html(response.data); 384 }, 385 error: function(response) { 386 if(response && response.responseText) jQuery('#' + input_id + '_response').html(response.responseText); 387 } 388 }); 389 jQuery(input).attr('disabled', ''); 390 }); 391 392 // pre submit check 393 var form_id = 'addlink'; 394 if(jQuery('#editlink')) form_id = 'editlink'; 395 jQuery('#' + form_id).submit(function() { 396 if(jQuery('#force_submit').attr('checked')) { 397 return true; 398 } 399 if(jQuery('#link_status').val() != 'publish') { 400 // only check when publishing 401 return true; 402 } 403 404 jQuery('#publish_response').html(''); 405 var form_ok = true; 406 var error_string = ''; 407 jQuery('.response').hide(); 408 409 if(!jQuery('#link_url').val()) { 410 form_ok = false; 411 doError('link_url'); 412 jQuery('#link_url_response').html(linkL10n.pre_submit_no_url); 413 } 414 if(!jQuery('#link_name').val()) { 415 form_ok = false; 416 doError('link_name'); 417 jQuery('#link_name_response').html(linkL10n.pre_submit_no_name); 418 } 419 420 if(!jQuery('[name="link_category[]"]').val()) { 421 form_ok = false; 422 doError('link_category'); 423 jQuery('#link_category_response').html(linkL10n.pre_submit_no_category); 424 } 425 426 if(jQuery('#content').val()) { 427 tc = wordCount(jQuery('#content').val()); 428 if(linkWordCountL10n && (tc < linkWordCountL10n.min_length || tc > linkWordCountL10n.max_length)) { 429 error_string = error_string + '<p class="warning">' + linkL10n.pre_submit_check_description + '</p>'; 430 form_ok = false; 431 doError('content'); 432 } 433 } 434 else { 435 error_string = error_string + '<p class="warning">' + linkL10n.pre_submit_check_description + '</p>'; 436 form_ok = false; 437 doError('content'); 438 jQuery('#link_content_response').html(linkL10n.pre_submit_check_description) 439 } 440 if(!form_ok) { 441 //error_string = error_string + '<p class="warning">' + linkL10n.pre_submit_wrong + '</p>'; 442 error_string += ' <input type="checkbox" id="force_submit" /> ' + linkL10n.force_submit; 443 jQuery('#publish_response').html(error_string); 444 jQuery('#publish_response').show(); 445 } 446 return form_ok; 447 }); 448 }); 449
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
| Generated: Sat May 30 23:51:06 2009 | Cross-referenced by PHPXref 0.7 |