[wp-trac] [WordPress Trac] #3878: Press IT Bookmarklet updated
WordPress Trac
wp-trac at lists.automattic.com
Tue Feb 27 06:43:26 GMT 2007
#3878: Press IT Bookmarklet updated
----------------------------+-----------------------------------------------
Reporter: DD32 | Owner: anonymous
Type: enhancement | Status: new
Priority: normal | Milestone: 2.2
Component: Administration | Version:
Severity: normal | Keywords: Press IT has-patch
----------------------------+-----------------------------------------------
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') ?>
}}}
--
Ticket URL: <http://trac.wordpress.org/ticket/3878>
WordPress Trac <http://trac.wordpress.org/>
WordPress blogging software
More information about the wp-trac
mailing list