Context
Real application of free software (GPLv3) (arguing this issue) that I code, it MELT monitor on github (FWIW, I AT the commit am 56a83d358d3966eddb55 ... on February 11 th 2016). This is on Linux / x86_64 / Debian, Firefox / 44, JQuery-2.2.0, JqueryUI 1.11.4, clipboard.js 1.5.8 ....
A more open (but without code) related question was omitted by Programmers. So I made a JsFiddle example for this very question, but the JsFiddle example is probably very wrong.
I have a (dynamically generated) HTML document with some <span>-s class='momitemref_cl', such as <span class='momitemref_cl'>this</span>etc. (the internal content of such spaces is always one word, for example this, actually some variable name or identifier in some of my DSLs). My goal is to create a dynamically created menu for each such interval, to enable some operations on them, in particular: hilight each appearance of this word and copy and select the word in the browser and the clipboard on the desktop.
Here are a lot of questions about copying to the clipboard in Javascript, like this . Some of them mention Zeno Rocha clipboard.js , which I am trying to use.
Explanation Code
JsFiddle: JQueryUI
function make_menu(spa) {
console.log("make_menu spa=", spa);
var name = $(spa).text();
mom_menuitemcount++;
var menuid = "menuid_" + mom_menuitemcount;
console.log("make_menu name=", name, " menuid=", menuid);
$maindiv.after("<ul class='mommenu_cl' id='" + menuid + "'>"
+ "<li class='ui-state-disabled'>* <i>" + name + "</i> *</li>"
+ "<li>Hilight</li>" + "<li>Copy</li>" + "</ul>");
var mymenu = $('#' + menuid);
mymenu.menu({
select: function(ev, ui) {
var uitem = ui.item;
var utext = uitem.text();
console.log("mymenu-select ev=", ev, " ui=", ui, " name=", name,
" uitem=", uitem, " utext=", utext);
switch (utext) {
case "Hilight":
$maindiv.find(".momitemref_cl").each(function(ix, el) {
var etext = $(el).text();
console.log("hilighting el=", el, " etext=", etext);
if (etext == name) {
$(el).toggleClass("momhilight_cl");
}
});
break;
case "Copy":
break;
};
setTimeout(200, destroy_menu);
},
position: {
my: "left top",
at: "bottom left",
of: spa
}
});
mom_menuitem = mymenu;
console.log("make_menu spa=", spa, " mymenu=", mymenu);
return mymenu;
}
, //// what should go here?; , :
uitem.select();
document.execCommand('Copy');
AFAIU , , , (, ), .
$clipboardh = new Clipboard(".momitemref_cl", {
text: function (trig) {
console.log("clipboard text trig=", trig);
};
});
( ), /// some code is missing here probably .
, , (//// what should go here?....) (/// some code is missing here probably....)
MVCE JsFiddle
, clipboard.js JQueryUI span ??
, , , , contextmenu ( , span -s class='momitemref_cl'?)
, MELT monitor ( JsFiddle...) CSS mom_itemref_cl mom_itemval_cl, .
PS. JsFiddle . ,
https://jsfiddle.net/bstarynk/g2notLd7/132/
NB. , Firefox Chrome.