What is it?
A bookmarklet for the iPhone that delivers rudimentary copy and paste functionality. Data is stored in window.name, so the usual security caveats apply.
This is primarily a proof of concept for working with iPhone-specific event handlers, and is presented with that goal in mind. A few liberties have been taken with JavaScript syntax since there is a single platform in play and every character counts.
The necessary style sheet is included via a data URI. This turned out to be a nice way to avoid any server-side dependencies.
How is it used?
Hold down with one finger on the screen to pop up the context menu, which will vary depending on the status of the window.name variable. An additional option is exposed if you hold down over a paragraph (must be a real paragraph with a <P> tag). See line 55 of the source.
Here is an uncondensed version for your perusal.
javascript: mD=false; d=document; cT=function(){ clearTimeout(mD); } ; data={ url:'',text:'' } ; d.ontouchstart=function(ev){ t=ev.touches[0].target; if(t.id!='contextMenu'&&(t.nodeName!='A'&&t.parentNode.nodeName!='A')){ rCM(); mD=setTimeout(sCM,500,ev); d.ontouchmove=cT; } } ; d.ontouchend=cT; rCM=function(){ if(cM=d.getElementById('contextMenu')){ cM.parentNode.removeChild(cM); } } ; rP=function(ev){ ps=d.getElementsByTagName('textarea'); for(var i=0;i 150?(t.pageY-150):0)+'px'; cM.style.left=(t.pageX>150?(t.pageX-150):0)+'px'; cM.style.display='none'; if(window.name!=''){ html=unescape('%3Cli%3E%3Ca href=%22#paste%22 onclick=%22rP();rCM();return false;%22%3EP%3C/a%3E%3C/li%3E%3Cli%3E%3Ca href=%22mailto:friend?subject=Web Link&body=')+window.name+unescape('%22%3EE%3C/a%3E%3C/li%3E%3Cli%3E%3Ca href=%22#clear%22 onclick=%22window.name=\'\';rCM();return false;%22%3EC%3C/a%3E%3C/li%3E'); } else{ html=unescape('%3Cli%3E%3Ca onclick=%22window.name=data.url;%22%3EURI%3C/a%3E%3C/li%3E'); data.url=escape(location.href); if(tt.nodeName=='#text'&&tt.parentNode.nodeName=='P'){ html+=unescape('%3Cli%3E%3Ca onclick=%22window.name=data.text;%22%3E¶%3C/a%3E%3C/li%3E'); data.text=escape(tt.parentNode.innerHTML)+' from: '+location.href; } } cM.innerHTML=html; d.body.appendChild(cM); cM.style.display='block'; } ; init=function(){ css=d.createElement('link'); css.type='text/css'; css.rel='stylesheet'; css.href='data:text/css;base64,I2NvbnRleHRNZW51IHtsaXN0LXN0eWxlLXR5cGU6IG5vbmU7cG9zaXRpb246IGFic29sdXRlO29wYWNpdHk6IDAuODttYXJnaW46IDA7cGFkZGluZzogMTBweDtiYWNrZ3JvdW5kLWNvbG9yOiAjNmY4NmEzO3dpZHRoOiAyNSU7aGVpZ2h0OiAyNSU7Zm9udC1mYW1pbHk6IFwiTHVjaWRhIEdyYW5kZVwiLHNhbnMtc2VyaWY7fQ0KI2NvbnRleHRNZW51IGxpIHtmbG9hdDogbGVmdDt9DQojY29udGV4dE1lbnUgYSB7ZGlzcGxheTogYmxvY2s7dGV4dC1hbGlnbjogY2VudGVyO3RleHQtZGVjb3JhdGlvbjogbm9uZTtmb250LXNpemU6IDNlbTttaW4td2lkdGg6IDFlbTtwYWRkaW5nOiAxMHB4O2JvcmRlcjogMXB4IHNvbGlkICNjY2M7Y29sb3I6ICNmZmY7fQ0KI2NvbnRleHRNZW51IGE6aG92ZXIge2JvcmRlci1jb2xvcjogI2ZmZjt9'; d.getElementsByTagName('head')[0].appendChild(css); } ; init(); |
Recent Comments