From 9dfab451c9849ed8d892d0d311d354be264575f0 Mon Sep 17 00:00:00 2001 From: Dan Dascalescu Date: Fri, 17 Jul 2015 23:56:29 -0700 Subject: [PATCH] Cleanup before refactoring to use HubSpot's Tether --- README.md | 4 ++-- demos/iDoRecall-menu.css | 4 ---- demos/iDoRecall.html | 7 ------- src/selection-menu.js | 6 ++---- 4 files changed, 4 insertions(+), 17 deletions(-) diff --git a/README.md b/README.md index e997a46..23db035 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ SelectionMenu is a small, self-contained, framework-agnostic JavaScript module that displays a custom context menu when the user selects text on the page. -This menu may offer a search feature, dictionary lookup, post to Facebook or similar. +This menu may offer a search feature, dictionary lookup, share on social media, or similar. **[Live Demo](http://idorecall.github.io/selection-menu/)** @@ -43,7 +43,7 @@ Pass an object literal with the following options: * `minlength` (number, optional): Only display the menu if the selected text has at least this length. Defaults to 5 characters. * `maxlength` (number, optional): Only display the menu if the selected text is at most this long. Defaults to `Infinity`. * `id` (string, optional): The ID of the menu element which is inserted. Defaults to `selection-menu`. -* `onselect` (function, optional): Custom event generated when the mouse selection changes. Not generated when the selection is changed via the keyboard. Use it to customize the menu dynamically based on the contents of the selection: +* `onselect` (function, optional): Custom event generated when the mouse/finger selection changes. Not generated when the selection is changed via the keyboard. Use it to customize the menu dynamically based on the contents of the selection: ```js new SelectionMenu({ diff --git a/demos/iDoRecall-menu.css b/demos/iDoRecall-menu.css index 870d6d6..aeeff56 100644 --- a/demos/iDoRecall-menu.css +++ b/demos/iDoRecall-menu.css @@ -46,10 +46,6 @@ color: white; } -#selection-menu:hover li { - border-color: #CCCCCC; -} - #selection-menu:after { content: ''; position: absolute; diff --git a/demos/iDoRecall.html b/demos/iDoRecall.html index 05366ad..047fa3e 100644 --- a/demos/iDoRecall.html +++ b/demos/iDoRecall.html @@ -45,13 +45,6 @@ container: document.getElementById('article'), id: 'selection-menu', menuHTML: document.querySelector('#mymenu').innerHTML, - onselect: function (e) { - var truncatedText = this.selectedText.replace(/\s+/g, ' '); - if (truncatedText.length > 30) - truncatedText = truncatedText.slice(0, 30) + '...'; - - this.menuHTML = this.menuHTML.replace(/ search for .*/g, ' search for ' + truncatedText + ''); - }, handler: function (e) { var target = e.target, id = target.id, diff --git a/src/selection-menu.js b/src/selection-menu.js index b4bceb0..baf6874 100644 --- a/src/selection-menu.js +++ b/src/selection-menu.js @@ -103,10 +103,8 @@ // Call the onselect handler to give it a chance to modify the menu instance.onselect && instance.onselect.call(instance, e); - // Fill the menu span - var range = window.getSelection().getRangeAt(0); - // Get the start and end nodes of the selection + var range = window.getSelection().getRangeAt(0); var startNode = range.startContainer; var endNode = range.endContainer; @@ -142,7 +140,7 @@ // Fill the menu span span.innerHTML = instance.menuHTML; - // Inject the span element into the new Range + // Inject the span element at the start of the new Range newRange.insertNode(span); // Menu positioning