Browse files

minified scripts, smaller fixes

  • Loading branch information...
1 parent 14f8644 commit 973131d490ca91c9749a2e0cac249ef73a3a8cd0 @molily committed Jun 19, 2011
Showing with 36 additions and 29 deletions.
  1. +23 −23 README
  2. +2 −2 copylink.js
  3. +4 −1 copylink.min.js
  4. +2 −2 selectionmenu.js
  5. +5 −1 selectionmenu.min.js
View
46 README
@@ -1,7 +1,7 @@
Deutsche Beschreibung:
----------------------
-SelectionMenu und CopyLink sind kleine, framework-unabhängige JavaScript.
+SelectionMenu und CopyLink sind kleine, framework-unabhängige JavaScripte.
SelectionMenu zeigt beim Markieren von Text ein Kontextmenü an. Die Idee und
Umsetzung ähnelt der auf nytimes.com. Das Script ist jedoch einfacher und universell
@@ -31,7 +31,7 @@ English Description:
SelectionMenu and CopyLink are small self-contained, framework-agnostic scripts
which demonstrate the abilities of the JavaScript APIs DOM Range and Microsoft
-Text Ranges.
+TextRanges.
SelectionMenu shows a context menu when the user selects some text on the page.
This menu may offer a search feature, dictionary lookup, post to Facebook or similar.
@@ -84,23 +84,23 @@ selected text is read. Depending on the clicked link, the selected text is
looked up on Google or Bing.
new SelectionMenu({
- container : document.getElementById('article'),
- menuHTML : '<a id="selection-menu-google">Google Search</a><a id="selection-menu-bing">Bing Search</a>',
- handler : function (e) {
- var target = e.target || e.srcElement,
- id = target.id,
- selectedText = this.selectedText,
- query = encodeURI(selectedText.replace(/\s/g, '+')),
- searchURI;
-
- if (id == 'selection-menu-google') {
- searchURI = 'http://www.google.com/search?ie=utf-8&q=';
- } else if (id == 'selection-menu-bing') {
- searchURI = 'http://www.bing.com/search?q=';
- }
-
- location.href = searchURI + query;
- }
+ container : document.getElementById('article'),
+ menuHTML : '<a id="selection-menu-google">Google Search</a><a id="selection-menu-bing">Bing Search</a>',
+ handler : function (e) {
+ var target = e.target || e.srcElement,
+ id = target.id,
+ selectedText = this.selectedText,
+ query = encodeURI(selectedText.replace(/\s/g, '+')),
+ searchURI;
+
+ if (id == 'selection-menu-google') {
+ searchURI = 'http://www.google.com/search?ie=utf-8&q=';
+ } else if (id == 'selection-menu-bing') {
+ searchURI = 'http://www.bing.com/search?q=';
+ }
+
+ location.href = searchURI + query;
+ }
});
@@ -130,8 +130,8 @@ This observes copy events at the element with the ID “article”. It appends t
string “Source: <URL>” when the user copys text which is longer than 20 characters.
new CopyLink({
- container : document.getElementById('article'),
- handler : function () {
- return '<br>Source: ' + location.href;
- }
+ container : document.getElementById('article'),
+ handler : function () {
+ return '<br>Source: ' + location.href;
+ }
});
View
4 copylink.js
@@ -1,5 +1,5 @@
/*
-CopyLink 1.0
+CopyLink 1.1
http://github.com/molily/selectionmenu
by molily (zapperlott@gmail.com, http://molily.de/)
@@ -178,7 +178,7 @@ var CopyLink = (function (window, document) {
// EN: If the end node is an element, use its last text node as the end offset
// DE: Falls der Endknoten ein Element ist, nehme das Ende des letzten Textknoten
if (endNode.nodeType == 1) {
- var endNode = endNode.lastChild;
+ endNode = endNode.lastChild;
if (!endNode || endNode.nodeType != 3) {
return;
}
View
5 copylink.min.js
@@ -1 +1,4 @@
-var CopyLink=function(h,g){function j(a,c,e){if(a.addEventListener)a.addEventListener(c,e,false);else a.attachEvent&&a.attachEvent("on"+c,function(){return e.call(a,h.event)})}function l(){return h.getSelection?h.getSelection():g.selection&&g.selection.createRange?g.selection.createRange():false}function m(a){return a.toString?a.toString():a.text}function k(){var a=b.parentNode;a&&a.removeChild(b)}function i(a){this.minimalSelection=a.minimalSelection||20;this.container=a.container;this.handler=a.handler|| function(){return"<br>Source: "+location.href};this.create();this.setupEvents()}var b=null;i.addEvent=j;i.prototype={create:function(){if(!b){b=g.createElement("span");b.id="copylink";b.style.cssText="position: absolute; left: -9999px;"}},setupEvents:function(){var a=this;j(a.container,"copy",function(){a.insert()})},insert:function(){var a=l();if(a)if(!(m(a).length<this.minimalSelection))if(a.getRangeAt){var c=a.getRangeAt(0),e=g.createRange(),f=c.startContainer,d=c.endContainer;if(f&&d&&f.compareDocumentPosition){if(f.compareDocumentPosition(d)& 2){f=d;d=c.startContainer}f=c.endOffset;if(d.nodeType==1){d=d.lastChild;if(!d||d.nodeType!=3)return;f=d.data.length}e.setStart(d,f);b.innerHTML=this.handler();e.insertNode(b);c.setEndAfter(b);a.removeAllRanges();a.addRange(c);h.setTimeout(function(){c.setEndBefore(b);a.removeAllRanges();a.addRange(c);k()},0)}}else if(a.duplicate){e=a.duplicate();e.setEndPoint("StartToEnd",a);b.innerHTML=this.handler();e.pasteHTML(b.outerHTML);a.setEndPoint("EndToEnd",e);a.select();b=g.getElementById("copylink");h.setTimeout(k, 0)}}};return i}(window,document);
+var CopyLink=function(h,f){function j(a,b,d){a.addEventListener?a.addEventListener(b,d,!1):a.attachEvent&&a.attachEvent("on"+b,function(){return d.call(a,h.event)})}function k(){var a=b.parentNode;a&&a.removeChild(b)}function i(a){this.id=a.id||"copylink";this.minimalSelection=a.minimalSelection||20;this.container=a.container;this.handler=a.handler||function(){return"<br>Source: "+location.href};this.create();this.setupEvents()}var b=null;i.addEvent=j;i.prototype={create:function(){if(!b)b=f.createElement("span"),
+b.id=this.id,b.style.cssText="position: absolute; left: -9999px;"},setupEvents:function(){var a=this;j(a.container,"copy",function(){a.insert()})},insert:function(){var a=h.getSelection?h.getSelection():f.selection&&f.selection.createRange?f.selection.createRange():!1;if(a&&!((a.toString?a.toString():a.text).length<this.minimalSelection))if(a.getRangeAt){var e=a.getRangeAt(0),d=e.startContainer,c=e.endContainer;if(d&&c&&d.compareDocumentPosition){if(d.compareDocumentPosition(c)&2)d=c,c=e.startContainer;
+d=e.endOffset;if(c.nodeType==1){c=c.lastChild;if(!c||c.nodeType!=3)return;d=c.data.length}var g=f.createRange();g.setStart(c,d);b.innerHTML=this.handler.call(this);g.insertNode(b);e.setEndAfter(b);a.removeAllRanges();a.addRange(e);h.setTimeout(function(){e.setEndBefore(b);a.removeRange?a.removeRange(e):a.removeAllRanges();a.addRange(e);k()},0)}}else if(a.duplicate)g=a.duplicate(),g.setEndPoint("StartToEnd",a),b.innerHTML=this.handler.call(this),g.pasteHTML(b.outerHTML),a.setEndPoint("EndToEnd",g),
+a.select(),b=f.getElementById(id),h.setTimeout(k,0)}};return i}(window,document);
View
4 selectionmenu.js
@@ -1,5 +1,5 @@
/*
-SelectionMenu 1.0
+SelectionMenu 1.1
http://github.com/molily/selectionmenu
by molily (zapperlott@gmail.com, http://molily.de/)
@@ -252,7 +252,7 @@ var SelectionMenu = (function (window, document) {
// EN: If the end node is an element, use its last text node as the end offset
// DE: Falls der Endknoten ein Element ist, nehme das Ende des letzten Textknoten
if (endNode.nodeType == 1) {
- var endNode = endNode.lastChild;
+ endNode = endNode.lastChild;
if (!endNode || endNode.nodeType != 3) {
return;
}
View
6 selectionmenu.min.js
@@ -1 +1,5 @@
-var SelectionMenu=function(h,f){function i(a,b,d){if(a.addEventListener)a.addEventListener(b,d,false);else a.attachEvent&&a.attachEvent("on"+b,function(){return d.call(a,h.event)})}function k(){return h.getSelection?h.getSelection():f.selection&&f.selection.createRange?f.selection.createRange():false}function l(a){return a.toString?a.toString():a.text}function n(a,b){return a.compareDocumentPosition?!!(a.compareDocumentPosition(b)&16):a.contains(b)}function m(a){a=a.target||a.srcElement;return a== c||n(c,a)}function j(a){this.menuHTML=a.menuHTML;this.minimalSelection=a.minimalSelection||5;this.container=a.container;this.handler=a.handler;this.create();this.setupEvents()}var c=null;j.addEvent=i;j.prototype={create:function(){if(!c){c=f.createElement("span");c.id="selection-menu"}},setupEvents:function(){var a=this,b=a.container;i(b,"mousedown",function(d){a.hide(d)});i(b,"mouseup",function(d){a.insert(d);h.setTimeout(function(){a.hideIfNoSelection()},0)});a.setupMenuEvents()},setupMenuEvents:function(){var a= this;i(c,"click",function(b){a.handler.call(a,b);return false});c.unselectable=true},hide:function(a){if(!(a&&m(a)))(a=c.parentNode)&&a.removeChild(c)},hideIfNoSelection:function(){var a=k();if(a)l(a).length||this.hide()},insert:function(a){if(!m(a)){var b=k();if(b){var d=l(b);this.selectedText=d;if(d.length<this.minimalSelection)this.hide(a);else{if(b.getRangeAt){a=b.getRangeAt(0);d=f.createRange();var g=a.startContainer,e=a.endContainer;if(!(g&&e&&g.compareDocumentPosition))return;if(g.compareDocumentPosition(e)& 2)e=a.startContainer;g=a.endOffset;if(e.nodeType==1){e=e.lastChild;if(!e||e.nodeType!=3)return;g=e.data.length}d.setStart(e,g);c.innerHTML=this.menuHTML;d.insertNode(c);b.removeRange?b.removeRange(a):b.removeAllRanges();b.addRange(a)}else if(b.duplicate){d=b.duplicate();d.setEndPoint("StartToEnd",b);c.innerHTML=this.menuHTML;d.pasteHTML(c.outerHTML);b.select();c=f.getElementById("selection-menu");this.setupMenuEvents()}else return;this.position()}}}},position:function(){c.style.marginTop=-(c.offsetHeight+ 5)+"px"}};return j}(window,document);
+var SelectionMenu=function(h,e){function i(a,b,d){a.addEventListener?a.addEventListener(b,d,!1):a.attachEvent&&a.attachEvent("on"+b,function(){return d.call(a,h.event)})}function k(){return h.getSelection?h.getSelection():e.selection&&e.selection.createRange?e.selection.createRange():!1}function l(a){a=a.target||a.srcElement;return a==c||(c.compareDocumentPosition?!!(c.compareDocumentPosition(a)&16):c.contains(a))}function j(a){this.id=a.id||"selection-menu";this.menuHTML=a.menuHTML;this.minimalSelection=
+a.minimalSelection||5;this.container=a.container;this.handler=a.handler;this.create();this.setupEvents()}var c=null;j.addEvent=i;j.prototype={create:function(){if(!c)c=e.createElement("span"),c.id=this.id},setupEvents:function(){var a=this,b=a.container;i(b,"mousedown",function(b){a.hide(b)});i(b,"mouseup",function(b){a.insert(b);h.setTimeout(function(){a.hideIfNoSelection()},0)});a.setupMenuEvents()},setupMenuEvents:function(){var a=this;i(c,"click",function(b){a.handler.call(a,b);return!1});c.unselectable=
+!0},hide:function(a){if(!a||!l(a))(a=c.parentNode)&&a.removeChild(c)},hideIfNoSelection:function(){var a=k();a&&((a.toString?a.toString():a.text).length||this.hide())},insert:function(a){if(!l(a)){var b=k();if(b){var d=b.toString?b.toString():b.text;this.selectedText=d;if(d.length<this.minimalSelection)this.hide(a);else{if(b.getRangeAt){var a=b.getRangeAt(0),f=a.startContainer,d=a.endContainer;if(!f||!d||!f.compareDocumentPosition)return;if(f.compareDocumentPosition(d)&2)d=a.startContainer;f=a.endOffset;
+if(d.nodeType==1){d=d.lastChild;if(!d||d.nodeType!=3)return;f=d.data.length}var g=e.createRange();g.setStart(d,f);c.innerHTML=this.menuHTML;g.insertNode(c);b.removeRange?b.removeRange(a):b.removeAllRanges();b.addRange(a)}else if(b.duplicate)g=b.duplicate(),g.setEndPoint("StartToEnd",b),c.innerHTML=this.menuHTML,g.pasteHTML(c.outerHTML),b.select(),c=e.getElementById(id),this.setupMenuEvents();else return;this.position()}}}},position:function(){c.style.marginTop=-(c.offsetHeight+5)+"px"}};return j}(window,
+document);

0 comments on commit 973131d

Please sign in to comment.