Skip to content

Commit

Permalink
Cleanup before refactoring to use HubSpot's Tether
Browse files Browse the repository at this point in the history
  • Loading branch information
dandv committed Jul 18, 2015
1 parent 126d605 commit 9dfab45
Show file tree
Hide file tree
Showing 4 changed files with 4 additions and 17 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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/)**

Expand Down Expand Up @@ -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({
Expand Down
4 changes: 0 additions & 4 deletions demos/iDoRecall-menu.css
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,6 @@
color: white;
}

#selection-menu:hover li {
border-color: #CCCCCC;
}

#selection-menu:after {
content: '';
position: absolute;
Expand Down
7 changes: 0 additions & 7 deletions demos/iDoRecall.html
Original file line number Diff line number Diff line change
Expand Up @@ -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 <i>' + truncatedText + '</i></a>');
},
handler: function (e) {
var target = e.target,
id = target.id,
Expand Down
6 changes: 2 additions & 4 deletions src/selection-menu.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 9dfab45

Please sign in to comment.