I am using the push method to add new values to an existing array (st[]). Adding a new value works, but then all values in the array get the value of the last added element.
if(!window.WordCatcher){
WordCatcher = {};
}
WordCatcher.selector = {};
WordCatcher.selector.getSelected = function(){
var t = '';
if(window.getSelection) {t = window.getSelection();}
else if(document.getSelection) {t = document.getSelection();}
else if(document.selection) {t = document.selection.createRange().text;}
return t;
}
st = new Array();
WordCatcher.selector.dblclick = function() {
st.push(WordCatcher.selector.getSelected());
console.log(st);
}
Call the function in jQuery with:
$(document).bind("dblclick", WordCatcher.selector.dblclick);
Example: If I double click first "Die", second "Smart", third "TV", I will get the following log in firebug:
[Die { constructor=Selection, focusNode=textNode, anchorNode=textNode, mehr...}] [Smart {constructor=Selection, focusNode=textNode, anchorNode=textNode, mehr...}, Smart {constructor=Selection, focusNode=textNode, anchorNode=textNode, mehr...}] [TV { constructor=Selection, focusNode=textNode, anchorNode=textNode, mehr...}, TV {constructor=Selection, focusNode=textNode, anchorNode=textNode, mehr...}, TV {constructor=Selection, focusNode=textNode, anchorNode=textNode, mehr...}]
Maybe somebody has an idea what I am doing work.
Best regards, Andy