diff options
author | donncha <donncha@7be80a69-a1ef-0310-a953-fb0f7c49ff36> | 2008-03-19 12:35:25 +0000 |
---|---|---|
committer | donncha <donncha@7be80a69-a1ef-0310-a953-fb0f7c49ff36> | 2008-03-19 12:35:25 +0000 |
commit | 50b00028bd207f461d6ed02f7868eccb5c6b8fe1 (patch) | |
tree | 003311f94f815dddbc39f91ba25b959f6ef18524 /wp-admin/js | |
parent | 63f0f49bde74f02cdfc79140a7f101173f33322b (diff) | |
download | wordpress-mu-50b00028bd207f461d6ed02f7868eccb5c6b8fe1.tar.gz wordpress-mu-50b00028bd207f461d6ed02f7868eccb5c6b8fe1.tar.xz wordpress-mu-50b00028bd207f461d6ed02f7868eccb5c6b8fe1.zip |
Add and delete WP 2.5 files. *DON'T SVN UPDATE!*
git-svn-id: http://svn.automattic.com/wordpress-mu/trunk@1214 7be80a69-a1ef-0310-a953-fb0f7c49ff36
Diffstat (limited to 'wp-admin/js')
-rw-r--r-- | wp-admin/js/comment.js | 12 | ||||
-rw-r--r-- | wp-admin/js/common.js | 12 | ||||
-rw-r--r-- | wp-admin/js/dbx-admin-key.js | 47 | ||||
-rw-r--r-- | wp-admin/js/editor.js | 153 | ||||
-rw-r--r-- | wp-admin/js/forms.js | 31 | ||||
-rw-r--r-- | wp-admin/js/link-cat.js | 10 | ||||
-rw-r--r-- | wp-admin/js/link.js | 48 | ||||
-rw-r--r-- | wp-admin/js/media-upload.js | 12 | ||||
-rw-r--r-- | wp-admin/js/page.js | 16 | ||||
-rw-r--r-- | wp-admin/js/password-strength-meter.js | 162 | ||||
-rw-r--r-- | wp-admin/js/post.js | 157 | ||||
-rw-r--r-- | wp-admin/js/postbox.js | 14 | ||||
-rw-r--r-- | wp-admin/js/slug.js | 48 | ||||
-rw-r--r-- | wp-admin/js/tags.js | 21 | ||||
-rw-r--r-- | wp-admin/js/widgets.js | 136 |
15 files changed, 822 insertions, 57 deletions
diff --git a/wp-admin/js/comment.js b/wp-admin/js/comment.js new file mode 100644 index 0000000..bde9b97 --- /dev/null +++ b/wp-admin/js/comment.js @@ -0,0 +1,12 @@ +addLoadEvent( function() { + add_postbox_toggles('comment'); + + jQuery('.edit-timestamp').click(function () { + if (jQuery('#timestampdiv').is(":hidden")) { + jQuery('#timestampdiv').slideDown("normal"); + } else { + jQuery('#timestampdiv').hide(); + } + return false; + }); +});
\ No newline at end of file diff --git a/wp-admin/js/common.js b/wp-admin/js/common.js new file mode 100644 index 0000000..9f05e55 --- /dev/null +++ b/wp-admin/js/common.js @@ -0,0 +1,12 @@ +addLoadEvent( function() { + // pulse + jQuery('.fade').animate( { backgroundColor: '#ffffe0' }, 300).animate( { backgroundColor: '#fffbcc' }, 300).animate( { backgroundColor: '#ffffe0' }, 300).animate( { backgroundColor: '#fffbcc' }, 300); + + // Reveal + jQuery('.wp-no-js-hidden').removeClass( 'wp-no-js-hidden' ); + + // Basic form validation + if ( ( 'undefined' != typeof wpAjax ) && jQuery.isFunction( wpAjax.validateForm ) ) { + jQuery('form').submit( function() { return wpAjax.validateForm( jQuery(this) ); } ); + } +}); diff --git a/wp-admin/js/dbx-admin-key.js b/wp-admin/js/dbx-admin-key.js deleted file mode 100644 index 3b3f7af..0000000 --- a/wp-admin/js/dbx-admin-key.js +++ /dev/null @@ -1,47 +0,0 @@ -addLoadEvent( function() {var manager = new dbxManager( dbxL10n.manager );} ); - -addLoadEvent( function() -{ - //create new docking boxes group - var meta = new dbxGroup( - 'grabit', // container ID [/-_a-zA-Z0-9/] - 'vertical', // orientation ['vertical'|'horizontal'] - '10', // drag threshold ['n' pixels] - 'no', // restrict drag movement to container axis ['yes'|'no'] - '10', // animate re-ordering [frames per transition, or '0' for no effect] - 'yes', // include open/close toggle buttons ['yes'|'no'] - 'closed', // default state ['open'|'closed'] - dbxL10n.open, // word for "open", as in "open this box" - dbxL10n.close, // word for "close", as in "close this box" - dbxL10n.moveMouse, // sentence for "move this box" by mouse - dbxL10n.toggleMouse, // pattern-match sentence for "(open|close) this box" by mouse - dbxL10n.moveKey, // sentence for "move this box" by keyboard - dbxL10n.toggleKey, // pattern-match sentence-fragment for "(open|close) this box" by keyboard - '%mytitle% [%dbxtitle%]' // pattern-match syntax for title-attribute conflicts - ); - - // Boxes are closed by default. Open the Category box if the cookie isn't already set. - var catdiv = document.getElementById('categorydiv'); - if ( catdiv ) { - var button = catdiv.getElementsByTagName('A')[0]; - if ( dbx.cookiestate == null && /dbx\-toggle\-closed/.test(button.className) ) - meta.toggleBoxState(button, true); - } - - var advanced = new dbxGroup( - 'advancedstuff', - 'vertical', - '10', - 'yes', // restrict drag movement to container axis ['yes'|'no'] - '10', - 'yes', - 'closed', - dbxL10n.open, - dbxL10n.close, - dbxL10n.moveMouse, - dbxL10n.toggleMouse, - dbxL10n.moveKey, - dbxL10n.toggleKey, - '%mytitle% [%dbxtitle%]' // pattern-match syntax for title-attribute conflicts - ); -}); diff --git a/wp-admin/js/editor.js b/wp-admin/js/editor.js new file mode 100644 index 0000000..a5500ec --- /dev/null +++ b/wp-admin/js/editor.js @@ -0,0 +1,153 @@ +wpEditorInit = function() { + // Activate tinyMCE if it's the user's default editor + if ( ( 'undefined' == typeof wpTinyMCEConfig ) || 'tinymce' == wpTinyMCEConfig.defaultEditor ) { + document.getElementById('editorcontainer').style.padding = '0px'; + tinyMCE.execCommand("mceAddControl", false, "content"); + } else { + var H; + if ( H = tinymce.util.Cookie.getHash("TinyMCE_content_size") ) + document.getElementById('content').style.height = H.ch - 30 + 'px'; + } +}; + +switchEditors = { + + saveCallback : function(el, content, body) { + + document.getElementById(el).style.color = '#fff'; + if ( tinyMCE.activeEditor.isHidden() ) + content = document.getElementById(el).value; + else + content = this.pre_wpautop(content); + + return content; + }, + + pre_wpautop : function(content) { + // We have a TON of cleanup to do. + + // Remove anonymous, empty paragraphs. + content = content.replace(new RegExp('<p>(\\s| |<br />)*</p>', 'mg'), ''); + + // Mark </p> if it has any attributes. + content = content.replace(new RegExp('(<p[^>]+>.*?)</p>', 'mg'), '$1</p#>'); + + // Get it ready for wpautop. + content = content.replace(new RegExp('\\s*<p>', 'mgi'), ''); + content = content.replace(new RegExp('\\s*</p>\\s*', 'mgi'), '\n\n'); + content = content.replace(new RegExp('\\n\\s*\\n', 'mgi'), '\n\n'); + content = content.replace(new RegExp('\\s*<br ?/?>\\s*', 'gi'), '\n'); + + // Fix some block element newline issues + var blocklist = 'blockquote|ul|ol|li|table|thead|tr|th|td|div|h\\d|pre'; + content = content.replace(new RegExp('\\s*<(('+blocklist+') ?[^>]*)\\s*>', 'mg'), '\n<$1>'); + content = content.replace(new RegExp('\\s*</('+blocklist+')>\\s*', 'mg'), '</$1>\n'); + content = content.replace(new RegExp('<li>', 'g'), '\t<li>'); + + if ( content.indexOf('<object') != -1 ) { + content = content.replace(new RegExp('\\s*<param([^>]*)>\\s*', 'g'), "<param$1>"); // no pee inside object/embed + content = content.replace(new RegExp('\\s*</embed>\\s*', 'g'), '</embed>'); + } + + // Unmark special paragraph closing tags + content = content.replace(new RegExp('</p#>', 'g'), '</p>\n'); + content = content.replace(new RegExp('\\s*(<p[^>]+>.*</p>)', 'mg'), '\n$1'); + + // Trim trailing whitespace + content = content.replace(new RegExp('\\s*$', ''), ''); + + // Hope. + return content; + }, + + go : function(id) { + var ed = tinyMCE.get(id); + var qt = document.getElementById('quicktags'); + var H = document.getElementById('edButtonHTML'); + var P = document.getElementById('edButtonPreview'); + var ta = document.getElementById(id); + var ec = document.getElementById('editorcontainer'); + + if ( ! ed || ed.isHidden() ) { + ta.style.color = '#fff'; + + this.edToggle(P, H); + edCloseAllTags(); // :-( + + qt.style.display = 'none'; + ec.style.padding = '0px'; + ta.style.padding = '0px'; + + ta.value = this.wpautop(ta.value); + + if ( ed ) ed.show(); + else tinyMCE.execCommand("mceAddControl", false, id); + + this.wpSetDefaultEditor('tinymce'); + } else { + this.edToggle(H, P); + ta.style.height = ed.getContentAreaContainer().offsetHeight + 6 + 'px'; + + ed.hide(); + qt.style.display = 'block'; + + if ( tinymce.isIE6 ) { + ta.style.width = '98%'; + ec.style.padding = '0px'; + ta.style.padding = '6px'; + } else { + ta.style.width = '100%'; + ec.style.padding = '6px'; + } + + ta.style.color = ''; + this.wpSetDefaultEditor('html'); + } + }, + + edToggle : function(A, B) { + A.className = 'active'; + B.className = ''; + + B.onclick = A.onclick; + A.onclick = null; + }, + + wpSetDefaultEditor : function(editor) { + try { + editor = escape( editor.toString() ); + } catch(err) { + editor = 'tinymce'; + } + + var userID = document.getElementById('user-id'); + var date = new Date(); + date.setTime(date.getTime()+(10*365*24*60*60*1000)); + document.cookie = "wordpress_editor_" + userID.value + "=" + editor + "; expires=" + date.toGMTString(); + }, + + wpautop : function(pee) { + var blocklist = 'table|thead|tfoot|caption|colgroup|tbody|tr|td|th|div|dl|dd|dt|ul|ol|li|pre|select|form|blockquote|address|math|p|h[1-6]'; + + pee = pee + "\n\n"; + pee = pee.replace(new RegExp('<br />\\s*<br />', 'gi'), "\n\n"); + pee = pee.replace(new RegExp('(<(?:'+blocklist+')[^>]*>)', 'gi'), "\n$1"); + pee = pee.replace(new RegExp('(</(?:'+blocklist+')>)', 'gi'), "$1\n\n"); + pee = pee.replace(new RegExp("\\r\\n|\\r", 'g'), "\n"); + pee = pee.replace(new RegExp("\\n\\s*\\n+", 'g'), "\n\n"); + pee = pee.replace(new RegExp('([\\s\\S]+?)\\n\\n', 'mg'), "<p>$1</p>\n"); + pee = pee.replace(new RegExp('<p>\\s*?</p>', 'gi'), ''); + pee = pee.replace(new RegExp('<p>\\s*(</?(?:'+blocklist+')[^>]*>)\\s*</p>', 'gi'), "$1"); + pee = pee.replace(new RegExp("<p>(<li.+?)</p>", 'gi'), "$1"); + pee = pee.replace(new RegExp('<p><blockquote([^>]*)>', 'gi'), "<blockquote$1><p>"); + pee = pee.replace(new RegExp('</blockquote></p>', 'gi'), '</p></blockquote>'); + pee = pee.replace(new RegExp('<p>\\s*(</?(?:'+blocklist+')[^>]*>)', 'gi'), "$1"); + pee = pee.replace(new RegExp('(</?(?:'+blocklist+')[^>]*>)\\s*</p>', 'gi'), "$1"); + pee = pee.replace(new RegExp('\\s*\\n', 'gi'), "<br />\n"); + pee = pee.replace(new RegExp('(</?(?:'+blocklist+')[^>]*>)\\s*<br />', 'gi'), "$1"); + pee = pee.replace(new RegExp('<br />(\\s*</?(?:p|li|div|dl|dd|dt|th|pre|td|ul|ol)>)', 'gi'), '$1'); + pee = pee.replace(new RegExp('^((?: )*)\\s', 'mg'), '$1 '); + //pee = pee.replace(new RegExp('(<pre.*?>)(.*?)</pre>!ise', " stripslashes('$1') . stripslashes(clean_pre('$2')) . '</pre>' "); // Hmm... + return pee; + } +} diff --git a/wp-admin/js/forms.js b/wp-admin/js/forms.js new file mode 100644 index 0000000..21a62f4 --- /dev/null +++ b/wp-admin/js/forms.js @@ -0,0 +1,31 @@ +function checkAll(form) { + for (i = 0, n = form.elements.length; i < n; i++) { + if(form.elements[i].type == "checkbox" && !(form.elements[i].hasAttribute('onclick'))) { + if(form.elements[i].checked == true) + form.elements[i].checked = false; + else + form.elements[i].checked = true; + } + } +} + +function getNumChecked(form) { + var num = 0; + for (i = 0, n = form.elements.length; i < n; i++) { + if (form.elements[i].type == "checkbox") { + if (form.elements[i].checked == true) + num++; + } + } + return num; +} + +function checkAllUsers(role) { + var checkboxs = document.getElementsByTagName('input'); + for(var i = 0, inp; inp = checkboxs[i]; i++) + if(inp.type.toLowerCase() == 'checkbox' && inp.className == role) + if(inp.checked == false) + inp.checked = true; + else + inp.checked = false; +}
\ No newline at end of file diff --git a/wp-admin/js/link-cat.js b/wp-admin/js/link-cat.js deleted file mode 100644 index a0775ce..0000000 --- a/wp-admin/js/link-cat.js +++ /dev/null @@ -1,10 +0,0 @@ -addLoadEvent(function(){linkcatList=new listMan('linkcategorychecklist');linkcatList.ajaxRespEl='jaxcat';linkcatList.topAdder=1;linkcatList.alt=0;linkcatList.showLink=0;}); -addLoadEvent(newLinkCatAddIn); -function newLinkCatAddIn() { - var jaxcat = $('jaxcat'); - if ( !jaxcat ) - return false; - Element.update(jaxcat,'<span id="ajaxcat"><input type="text" name="newcat" id="newcat" size="16" autocomplete="off"/><input type="button" name="Button" id="catadd" value="' + linkcatL10n.add + '"/><input type="hidden"/><span id="howto">' + linkcatL10n.how + '</span></span>'); - $('newcat').onkeypress = function(e) { return killSubmit("linkcatList.ajaxAdder('link-category','jaxcat');", e); }; - $('catadd').onclick = function() { linkcatList.ajaxAdder('link-category', 'jaxcat'); }; -} diff --git a/wp-admin/js/link.js b/wp-admin/js/link.js new file mode 100644 index 0000000..9f5a28d --- /dev/null +++ b/wp-admin/js/link.js @@ -0,0 +1,48 @@ +addLoadEvent( function() { + jQuery('#link_name').focus(); + // postboxes + add_postbox_toggles('link'); + + // category tabs + var categoryTabs = jQuery('#category-tabs').tabs(); + + // Ajax Cat + var newCat = jQuery('#newcat').one( 'focus', function() { jQuery(this).val( '' ).removeClass( 'form-input-tip' ) } ); + jQuery('#category-add-sumbit').click( function() { newCat.focus(); } ); + var noSyncChecks = false; // prophylactic. necessary? + var syncChecks = function() { + if ( noSyncChecks ) + return; + noSyncChecks = true; + var th = jQuery(this); + var c = th.is(':checked'); + var id = th.val().toString(); + jQuery('#in-category-' + id + ', #in-popular-category-' + id).attr( 'checked', c ); + noSyncChecks = false; + }; + var catAddAfter = function( r, s ) { + jQuery(s.what + ' response_data', r).each( function() { + var t = jQuery(jQuery(this).text()); + t.find( 'label' ).each( function() { + var th = jQuery(this); + var val = th.find('input').val(); + var id = th.find('input')[0].id + jQuery('#' + id).change( syncChecks ); + var name = jQuery.trim( th.text() ); + var o = jQuery( '<option value="' + parseInt( val, 10 ) + '"></option>' ).text( name ); + } ); + } ); + }; + jQuery('#categorychecklist').wpList( { + alt: '', + what: 'link-category', + response: 'category-ajax-response', + addAfter: catAddAfter + } ); + jQuery('#category-add-toggle').click( function() { + jQuery(this).parents('div:first').toggleClass( 'wp-hidden-children' ); + categoryTabs.tabsClick( 1 ); + return false; + } ); + jQuery('.categorychecklist :checkbox').change( syncChecks ).filter( ':checked' ).change(); +}); diff --git a/wp-admin/js/media-upload.js b/wp-admin/js/media-upload.js new file mode 100644 index 0000000..b8c615d --- /dev/null +++ b/wp-admin/js/media-upload.js @@ -0,0 +1,12 @@ +// send html to the post editor +function send_to_editor(h) { + var win = window.opener ? window.opener : window.dialogArguments; + if ( !win ) + win = top; + tinyMCE = win.tinyMCE; + if ( typeof tinyMCE != 'undefined' && ( ed = tinyMCE.getInstanceById('content') ) && !ed.isHidden() ) { + tinyMCE.selectedInstance.getWin().focus(); + tinyMCE.execCommand('mceInsertContent', false, h); + } else + win.edInsertContent(win.edCanvas, h); +}
\ No newline at end of file diff --git a/wp-admin/js/page.js b/wp-admin/js/page.js new file mode 100644 index 0000000..02fd708 --- /dev/null +++ b/wp-admin/js/page.js @@ -0,0 +1,16 @@ +addLoadEvent( function() { + add_postbox_toggles('page'); + make_slugedit_clickable(); + + // hide advanced slug field + jQuery('#pageslugdiv').hide(); + + jQuery('.edit-timestamp').click(function () { + if (jQuery('#timestampdiv').is(":hidden")) { + jQuery('#timestampdiv').slideDown("normal"); + } else { + jQuery('#timestampdiv').hide(); + } + return false; + }); +});
\ No newline at end of file diff --git a/wp-admin/js/password-strength-meter.js b/wp-admin/js/password-strength-meter.js new file mode 100644 index 0000000..eba43fc --- /dev/null +++ b/wp-admin/js/password-strength-meter.js @@ -0,0 +1,162 @@ +// Password strength meter +// This jQuery plugin is written by firas kassem [2007.04.05] +// Firas Kassem phiras.wordpress.com || phiras at gmail {dot} com +// for more information : http://phiras.wordpress.com/2007/04/08/password-strength-meter-a-jquery-plugin/ + +var shortPass = 'Too short' +var badPass = 'Bad' +var goodPass = 'Good' +var strongPass = 'Strong' + + + +function passwordStrength(password,username) +{ + score = 0 + + //password < 4 + if (password.length < 4 ) { return shortPass } + + //password == username + if (password.toLowerCase()==username.toLowerCase()) return badPass + + //password length + score += password.length * 4 + score += ( checkRepetition(1,password).length - password.length ) * 1 + score += ( checkRepetition(2,password).length - password.length ) * 1 + score += ( checkRepetition(3,password).length - password.length ) * 1 + score += ( checkRepetition(4,password).length - password.length ) * 1 + + //password has 3 numbers + if (password.match(/(.*[0-9].*[0-9].*[0-9])/)) score += 5 + + //password has 2 sybols + if (password.match(/(.*[!,@,#,$,%,^,&,*,?,_,~].*[!,@,#,$,%,^,&,*,?,_,~])/)) score += 5 + + //password has Upper and Lower chars + if (password.match(/([a-z].*[A-Z])|([A-Z].*[a-z])/)) score += 10 + + //password has number and chars + if (password.match(/([a-zA-Z])/) && password.match(/([0-9])/)) score += 15 + // + //password has number and symbol + if (password.match(/([!,@,#,$,%,^,&,*,?,_,~])/) && password.match(/([0-9])/)) score += 15 + + //password has char and symbol + if (password.match(/([!,@,#,$,%,^,&,*,?,_,~])/) && password.match(/([a-zA-Z])/)) score += 15 + + //password is just a nubers or chars + if (password.match(/^\w+$/) || password.match(/^\d+$/) ) score -= 10 + + //verifing 0 < score < 100 + if ( score < 0 ) score = 0 + if ( score > 100 ) score = 100 + + if (score < 34 ) return badPass + if (score < 68 ) return goodPass + return strongPass +} + + +// checkRepetition(1,'aaaaaaabcbc') = 'abcbc' +// checkRepetition(2,'aaaaaaabcbc') = 'aabc' +// checkRepetition(2,'aaaaaaabcdbcd') = 'aabcd' + +function checkRepetition(pLen,str) { + res = "" + for ( i=0; i<str.length ; i++ ) { + repeated=true + for (j=0;j < pLen && (j+i+pLen) < str.length;j++) + repeated=repeated && (str.charAt(j+i)==str.charAt(j+i+pLen)) + if (j<pLen) repeated=false + if (repeated) { + i+=pLen-1 + repeated=false + } + else { + res+=str.charAt(i) + } + } + return res +} +// Password strength meter +// This jQuery plugin is written by firas kassem [2007.04.05] +// Firas Kassem phiras.wordpress.com || phiras at gmail {dot} com +// for more information : http://phiras.wordpress.com/2007/04/08/password-strength-meter-a-jquery-plugin/ + +var shortPass = 'Too short' +var badPass = 'Bad' +var goodPass = 'Good' +var strongPass = 'Strong' + + + +function passwordStrength(password,username) +{ + score = 0 + + //password < 4 + if (password.length < 4 ) { return shortPass } + + //password == username + if (password.toLowerCase()==username.toLowerCase()) return badPass + + //password length + score += password.length * 4 + score += ( checkRepetition(1,password).length - password.length ) * 1 + score += ( checkRepetition(2,password).length - password.length ) * 1 + score += ( checkRepetition(3,password).length - password.length ) * 1 + score += ( checkRepetition(4,password).length - password.length ) * 1 + + //password has 3 numbers + if (password.match(/(.*[0-9].*[0-9].*[0-9])/)) score += 5 + + //password has 2 sybols + if (password.match(/(.*[!,@,#,$,%,^,&,*,?,_,~].*[!,@,#,$,%,^,&,*,?,_,~])/)) score += 5 + + //password has Upper and Lower chars + if (password.match(/([a-z].*[A-Z])|([A-Z].*[a-z])/)) score += 10 + + //password has number and chars + if (password.match(/([a-zA-Z])/) && password.match(/([0-9])/)) score += 15 + // + //password has number and symbol + if (password.match(/([!,@,#,$,%,^,&,*,?,_,~])/) && password.match(/([0-9])/)) score += 15 + + //password has char and symbol + if (password.match(/([!,@,#,$,%,^,&,*,?,_,~])/) && password.match(/([a-zA-Z])/)) score += 15 + + //password is just a nubers or chars + if (password.match(/^\w+$/) || password.match(/^\d+$/) ) score -= 10 + + //verifing 0 < score < 100 + if ( score < 0 ) score = 0 + if ( score > 100 ) score = 100 + + if (score < 34 ) return badPass + if (score < 68 ) return goodPass + return strongPass +} + + +// checkRepetition(1,'aaaaaaabcbc') = 'abcbc' +// checkRepetition(2,'aaaaaaabcbc') = 'aabc' +// checkRepetition(2,'aaaaaaabcdbcd') = 'aabcd' + +function checkRepetition(pLen,str) { + res = "" + for ( i=0; i<str.length ; i++ ) { + repeated=true + for (j=0;j < pLen && (j+i+pLen) < str.length;j++) + repeated=repeated && (str.charAt(j+i)==str.charAt(j+i+pLen)) + if (j<pLen) repeated=false + if (repeated) { + i+=pLen-1 + repeated=false + } + else { + res+=str.charAt(i) + } + } + return res +} diff --git a/wp-admin/js/post.js b/wp-admin/js/post.js new file mode 100644 index 0000000..9aeafcc --- /dev/null +++ b/wp-admin/js/post.js @@ -0,0 +1,157 @@ +// this file contains all the scripts used in the post/edit page + +function new_tag_remove_tag() { + var id = jQuery( this ).attr( 'id' ); + var num = id.substr( 10 ); + var current_tags = jQuery( '#tags-input' ).val().split(','); + delete current_tags[num]; + var new_tags = []; + jQuery.each( current_tags, function( key, val ) { + if ( val && !val.match(/^\s+$/) && '' != val ) { + new_tags = new_tags.concat( val ); + } + }); + jQuery( '#tags-input' ).val( new_tags.join( ',' ).replace( /\s*,+\s*/, ',' ).replace( /,+/, ',' ).replace( /,+\s+,+/, ',' ).replace( /,+\s*$/, '' ).replace( /^\s*,+/, '' ) ); + tag_update_quickclicks(); + jQuery('#newtag').focus(); + return false; +} + +function tag_update_quickclicks() { + var current_tags = jQuery( '#tags-input' ).val().split(','); + jQuery( '#tagchecklist' ).empty(); + shown = false; +// jQuery.merge( current_tags, current_tags ); // this doesn't work anymore, need something to array_unique + jQuery.each( current_tags, function( key, val ) { + val = val.replace( /^\s+/, '' ).replace( /\s+$/, '' ); // trim + if ( !val.match(/^\s+$/) && '' != val ) { + txt = '<span><a id="tag-check-' + key + '" class="ntdelbutton">X</a> ' + val + '</span> '; + jQuery( '#tagchecklist' ).append( txt ); + jQuery( '#tag-check-' + key ).click( new_tag_remove_tag ); + shown = true; + } + }); + if ( shown ) + jQuery( '#tagchecklist' ).prepend( '<strong>'+postL10n.tagsUsed+'</strong><br />' ); +} + +function tag_flush_to_text() { + var newtags = jQuery('#tags-input').val() + ',' + jQuery('#newtag').val(); + // massage + newtags = newtags.replace( /\s+,+\s*/g, ',' ).replace( /,+/g, ',' ).replace( /,+\s+,+/g, ',' ).replace( /,+\s*$/g, '' ).replace( /^\s*,+/g, '' ); + jQuery('#tags-input').val( newtags ); + tag_update_quickclicks(); + jQuery('#newtag').val(''); + jQuery('#newtag').focus(); + return false; +} + +function tag_save_on_publish() { + if ( jQuery('#newtag').val() != postL10n.addTag ) + tag_flush_to_text(); +} + +function tag_press_key( e ) { + if ( 13 == e.keyCode ) { + tag_flush_to_text(); + return false; + } +} + +addLoadEvent( function() { + // postboxes + add_postbox_toggles('post'); + + // If no tags on the page, skip the tag and category stuff. + if ( !jQuery('#tags-input').size() ) { + return; + } + + // Editable slugs + make_slugedit_clickable(); + + // hide advanced slug field + jQuery('#slugdiv').hide(); + + jQuery('#tags-input').hide(); + tag_update_quickclicks(); + // add the quickadd form + jQuery('#jaxtag').prepend('<span id="ajaxtag"><input type="text" name="newtag" id="newtag" class="form-input-tip" size="16" autocomplete="off" value="'+postL10n.addTag+'" /><input type="button" class="button" id="tagadd" value="' + postL10n.add + '"/><input type="hidden"/><input type="hidden"/><span class="howto">'+postL10n.separate+'</span></span>'); + jQuery('#tagadd').click( tag_flush_to_text ); + jQuery('#newtag').focus(function() { + if ( this.value == postL10n.addTag ) + jQuery(this).val( '' ).removeClass( 'form-input-tip' ); + }); + jQuery('#newtag').blur(function() { + if ( this.value == '' ) + jQuery(this).val( postL10n.addTag ).addClass( 'form-input-tip' ); + }); + + // auto-save tags on post save/publish + jQuery('#publish').click( tag_save_on_publish ); + jQuery('#save-post').click( tag_save_on_publish ); + + // auto-suggest stuff + jQuery('#newtag').suggest( 'admin-ajax.php?action=ajax-tag-search', { delay: 500, minchars: 2 } ); + jQuery('#newtag').keypress( tag_press_key ); + + // category tabs + var categoryTabs =jQuery('#category-tabs').tabs(); + + // Ajax Cat + var newCat = jQuery('#newcat').one( 'focus', function() { jQuery(this).val( '' ).removeClass( 'form-input-tip' ) } ); + jQuery('#category-add-sumbit').click( function() { newCat.focus(); } ); + var newCatParent = false; + var newCatParentOption = false; + var noSyncChecks = false; // prophylactic. necessary? + var syncChecks = function() { + if ( noSyncChecks ) + return; + noSyncChecks = true; + var th = jQuery(this); + var c = th.is(':checked'); + var id = th.val().toString(); + jQuery('#in-category-' + id + ', #in-popular-category-' + id).attr( 'checked', c ); + noSyncChecks = false; + }; + var catAddAfter = function( r, s ) { + if ( !newCatParent ) newCatParent = jQuery('#newcat_parent'); + if ( !newCatParentOption ) newCatParentOption = newCatParent.find( 'option[value=-1]' ); + jQuery(s.what + ' response_data', r).each( function() { + var t = jQuery(jQuery(this).text()); + t.find( 'label' ).each( function() { + var th = jQuery(this); + var val = th.find('input').val(); + var id = th.find('input')[0].id + jQuery('#' + id).change( syncChecks ); + if ( newCatParent.find( 'option[value=' + val + ']' ).size() ) + return; + var name = jQuery.trim( th.text() ); + var o = jQuery( '<option value="' + parseInt( val, 10 ) + '"></option>' ).text( name ); + newCatParent.prepend( o ); + } ); + newCatParentOption.attr( 'selected', true ); + } ); + }; + jQuery('#categorychecklist').wpList( { + alt: '', + response: 'category-ajax-response', + addAfter: catAddAfter + } ); + jQuery('#category-add-toggle').click( function() { + jQuery(this).parents('div:first').toggleClass( 'wp-hidden-children' ); + categoryTabs.tabsClick( 1 ); + jQuery('#newcat').focus(); + return false; + } ); + jQuery('.categorychecklist :checkbox').change( syncChecks ).filter( ':checked' ).change(); + + jQuery('.edit-timestamp').click(function () { + if (jQuery('#timestampdiv').is(":hidden")) { + jQuery('#timestampdiv').slideDown("normal"); + } else { + jQuery('#timestampdiv').hide(); + } + return false; + }); +}); diff --git a/wp-admin/js/postbox.js b/wp-admin/js/postbox.js new file mode 100644 index 0000000..a512f4b --- /dev/null +++ b/wp-admin/js/postbox.js @@ -0,0 +1,14 @@ +function add_postbox_toggles(page) { + jQuery('.postbox h3').prepend('<a class="togbox">+</a> '); + jQuery('.postbox h3').click( function() { jQuery(jQuery(this).parent().get(0)).toggleClass('closed'); save_postboxes_state(page); } ); +} + +function save_postboxes_state(page) { + var closed = jQuery('.postbox').filter('.closed').map(function() { return this.id; }).get().join(','); + jQuery.post(postboxL10n.requestFile, { + action: 'closed-postboxes', + closed: closed, + closedpostboxesnonce: jQuery('#closedpostboxesnonce').val(), + page: page + }); +} diff --git a/wp-admin/js/slug.js b/wp-admin/js/slug.js new file mode 100644 index 0000000..f26a5f2 --- /dev/null +++ b/wp-admin/js/slug.js @@ -0,0 +1,48 @@ +function edit_permalink(post_id) { + var i, c = 0; + var e = jQuery('#editable-post-name'); + var revert_e = e.html(); + var real_slug = jQuery('#post_name'); + var revert_slug = real_slug.html(); + var b = jQuery('#edit-slug-buttons'); + var revert_b = b.html(); + var full = jQuery('#editable-post-name-full').html(); + + b.html('<a href="" class="save">'+slugL10n.save+'</a> <a class="cancel" href="">'+slugL10n.cancel+'</a>'); + b.children('.save').click(function() { + var new_slug = e.children('input').val(); + jQuery.post(slugL10n.requestFile, { + action: 'sample-permalink', + post_id: post_id, + new_slug: new_slug, + new_title: jQuery('#title').val(), + samplepermalinknonce: jQuery('#samplepermalinknonce').val()}, function(data) { + jQuery('#edit-slug-box').html(data); + b.html(revert_b); + real_slug.attr('value', new_slug); + make_slugedit_clickable(); + }); + return false; + }); + jQuery('#edit-slug-buttons .cancel').click(function() { + e.html(revert_e); + b.html(revert_b); + real_slug.attr('value', revert_slug); + return false; + }); + for(i=0; i < full.length; ++i) { + if ('%' == full.charAt(i)) c++; + } + slug_value = (c > full.length/4)? '' : full; + e.html('<input type="text" id="new-post-slug" value="'+slug_value+'" />').children('input').keypress(function(e){ + var key = e.charCode ? e.charCode : e.keyCode ? e.keyCode : 0; + // on enter, just save the new slug, don't save the post + if (13 == key) {b.children('.save').click();return false;} + if (27 == key) {b.children('.cancel').click();return false;} + real_slug.attr('value', this.value)}).focus(); +} + +function make_slugedit_clickable() { + jQuery('#editable-post-name').click(function() {jQuery('#edit-slug-buttons').children('.edit-slug').click()}); +} + diff --git a/wp-admin/js/tags.js b/wp-admin/js/tags.js new file mode 100644 index 0000000..37182df --- /dev/null +++ b/wp-admin/js/tags.js @@ -0,0 +1,21 @@ +jQuery(function($) { + var options = false + + var addAfter = function( r, settings ) { + var name = $("<span>" + $('name', r).text() + "</span>").html(); + var id = $('tag', r).attr('id'); + options[options.length] = new Option(name, id); + } + + var delAfter = function( r, settings ) { + var id = $('tag', r).attr('id'); + for ( var o = 0; o < options.length; o++ ) + if ( id == options[o].value ) + options[o] = null; + } + + if ( options ) + $('#the-list').wpList( { addAfter: addAfter, delAfter: delAfter } ); + else + $('#the-list').wpList(); +}); diff --git a/wp-admin/js/widgets.js b/wp-admin/js/widgets.js new file mode 100644 index 0000000..6bf7f2c --- /dev/null +++ b/wp-admin/js/widgets.js @@ -0,0 +1,136 @@ +jQuery(function($) { + $('.noscript-action').remove(); + + var increment = 1; + + // Open or close widget control form + var toggleWidget = function( li, disableFields ) { + var width = li.find('input.widget-width').val(); + + // it seems IE chokes on these animations because of the positioning/floating + var widgetAnim = $.browser.msie ? function() { + var t = $(this); + if ( t.is(':visible') ) { + if ( disableFields ) { t.find( ':enabled' ).not( '[name="widget-id[]"]' ).attr( 'disabled', 'disabled' ); } + li.css( 'marginLeft', 0 ); + t.siblings('h4').children('a').text( widgetsL10n.edit ); + } else { + t.find( ':disabled' ).attr( 'disabled', '' ); // always enable on open + if ( width > 250 ) + li.css( 'marginLeft', ( width - 250 ) * -1 ); + t.siblings('h4').children('a').text( widgetsL10n.cancel ); + } + t.toggle(); + } : function() { + var t = $(this); + + if ( t.is(':visible') ) { + if ( disableFields ) { t.find( ':enabled' ).not( '[name="widget-id[]"]' ).attr( 'disabled', 'disabled' ); } + if ( width > 250 ) + li.animate( { marginLeft: 0 } ); + t.siblings('h4').children('a').text( widgetsL10n.edit ); + } else { + t.find( ':disabled' ).attr( 'disabled', '' ); // always enable on open + if ( width > 250 ) + li.animate( { marginLeft: ( width - 250 ) * -1 } ); + t.siblings('h4').children('a').text( widgetsL10n.cancel ); + } + t.animate( { height: 'toggle' } ); + }; + + return li.children('div.widget-control').each( widgetAnim ).end(); + }; + + // onclick for edit/cancel links + var editClick = function() { + var q = wpAjax.unserialize( this.href ); + // if link is in available widgets list, make sure it points to the current sidebar + if ( ( q.sidebar && q.sidebar == $('#sidebar').val() ) || q.add ) { + var w = q.edit || q.add; + toggleWidget( $('#current-sidebar .widget-control-list input[@name^="widget-id"][@value=' + w + ']').parents('li:first'), false ).blur(); + return false; + } else if ( q.sidebar ) { // otherwise, redirect to correct page + return true; + } + + // If link is in current widgets list, just open the form + toggleWidget( $(this).parents('li:first'), true ).blur(); + return false; + }; + + // onclick for add links + var addClick = function() { + var oldLi = $(this).parents('li:first').find('ul.widget-control-info li'); + var newLi = oldLi.clone(); + + if ( newLi.html().match( /%i%/ ) ) { + // supplid form is a template, replace %i% by unique id + var i = $('#generated-time').val() + increment.toString(); + increment++; + newLi.html( newLi.html().replace( /%i%/g, i ) ); + } else { + $(this).text( widgetsL10n.edit ).unbind().click( editClick ); + // save form content in textarea so we don't have any conflicting HTML ids + oldLi.html( '<textarea>' + oldLi.html() + '</textarea>' ); + } + + // add event handlers + addWidgetControls( newLi ); + + // add widget to sidebar sortable + widgetSortable.append( newLi ).SortableAddItem( newLi[0] ); + + // increment widget counter + var n = parseInt( $('#widget-count').text(), 10 ) + 1; + $('#widget-count').text( n.toString() ) + + return false; + }; + + // add event handlers to all links found in context + var addWidgetControls = function( context ) { + if ( !context ) + context = document; + + $('a.widget-control-edit', context).click( editClick ); + + // onclick for save links + $('a.widget-control-save', context).click( function() { + toggleWidget( $(this).parents('li:first'), false ).blur() + return false; + } ); + + // onclick for remove links + $('a.widget-control-remove', context).click( function() { + var w = $(this).parents('li:first').find('input[@name^="widget-id"]').val(); + $(this).parents('li:first').remove(); + var t = $('#widget-list ul#widget-control-info-' + w + ' textarea'); + t.parent().html( t.text() ).parents('li.widget-list-item:first').children( 'h4' ).children('a.widget-action') + .show().text( widgetsL10n.add ).unbind().click( addClick ); + var n = parseInt( $('#widget-count').text(), 10 ) - 1; + $('#widget-count').text( n.toString() ) + return false; + } ); + } + + addWidgetControls(); + + $('a.widget-control-add').click( addClick ); + + var widgetSortable; + var widgetSortableInit = function() { + try { // a hack to make sortables work in jQuery 1.2+ and IE7 + $('#current-sidebar .widget-control-list').SortableDestroy(); + } catch(e) {} + widgetSortable = $('#current-sidebar .widget-control-list').Sortable( { + accept: 'widget-sortable', + helperclass: 'sorthelper', + handle: 'h4.widget-title', + onStop: widgetSortableInit + } ); + } + + // initialize sortable + widgetSortableInit(); + +}); |