Ticket #3878 (closed enhancement: invalid)
Press IT Bookmarklet updated
| Reported by: |
|
Owned by: |
|
|---|---|---|---|
| Priority: | normal | Milestone: | |
| Component: | Administration | Version: | 2.2 |
| Severity: | normal | Keywords: | Press IT has-patch |
| Cc: |
Description
Follow up to http://trac.wordpress.org/ticket/3731
Since no-one else has done it, I've written up 2 bookmarklets for Wordpress 2.2-svn. I've tested under Opera9/IE6/FF2, i dont have access to any other browsers to test, however from what i can tell, it should work.
Here is an expanded form of the bookmarklet
//javascript:
function A(b){return (encodeURIComponent)?encodeURIComponent(b):escape(b);}
Q='';
if(window.getSelection){
Q=window.getSelection();
}else if (document.getSelection){
Q=document.getSelection();
}else if(document.selection){
Q=document.selection.createRange().text;
}
location.href='http://*URL*/wp-admin/post-new.php?text='+A(Q)+'&popupurl='+A(location.href)+'&popuptitle='+A(document.title);
The last line can also be writen as:
void(window.open('http://*URL*/wp-admin/post-new.php?text='+A(Q)+'&popupurl='+A(location.href)+'&popuptitle='+A(document.title)));
to open in a new window, Both bookmarklets are listed in the post page.
As to getting the current selected text: window.getSelection should work for Safari document.getSelection() should work for mozilla/opera document.selection.createRange().text should work for IE variants
The total length is 388 characters for the location.href version, which leaves 100 characters spare for the domain name, and any other small fixes which get added. (IE6 SP2 has a maximum limit of 488 characters for bookmarklets: http://subsimple.com/bookmarklets/rules.asp ) The window.open version has less space for the domain name, however most should still fit.
The function A() had to be used to pull the totalsize of the bookmarklet down to within limits allowed by IE6.
A Patch has been attached (Patch against SVN 4915).
Finally, Here are the 2 bookmarklets(with PHP and HTML):
<a href="javascript:function A(b){return (encodeURIComponent)?encodeURIComponent(b):escape(b);}Q='';if(window.getSelection){Q=window.getSelection();}else if (document.getSelection){Q=document.getSelection()}else if(document.selection){Q=document.selection.createRange().text;}void(window.open('<?php echo get_option('siteurl') ?>/wp-admin/post-new.php?text='+A(Q)+'&popupurl='+A(location.href)+'&popuptitle='+A(document.title)));" title="<?php printf(__('Press It - %s'), wp_specialchars(get_option('blogname'))); ?>"><?php printf(__('Press It - %s'), wp_specialchars(get_option('blogname'))); ?></a> <?php echo __('New Window/tab') ?><br/>
<a href="javascript:function A(b){return (encodeURIComponent)?encodeURIComponent(b):escape(b);}Q='';if(window.getSelection){Q=window.getSelection();}else if (document.getSelection){Q=document.getSelection()}else if(document.selection){Q=document.selection.createRange().text;}location.href='<?php echo get_option('siteurl') ?>/wp-admin/post-new.php?text='+A(Q)+'&popupurl='+A(location.href)+'&popuptitle='+A(document.title);" title="<?php printf(__('Press It - %s'), wp_specialchars(get_option('blogname'))); ?>"><?php printf(__('Press It - %s'), wp_specialchars(get_option('blogname'))); ?></a> <?php echo __('Current Window') ?>
Attachments
Change History
-
attachment
new-post-bookmarklet.patch
added
(Patch against SVN 4915).
Actually, my mistake, it seems to be against revision 4950, Which is the latest in the SVN repos as of a few hours ago.

Bookmarklet Patch