quickAddFilter: if text is currently highlighted, use that instead of active article title for placeholder text
This commit is contained in:
parent
43d790f054
commit
0c7e49936a
|
@ -1150,9 +1150,22 @@ function quickAddFilter() {
|
||||||
href: query});
|
href: query});
|
||||||
|
|
||||||
if (!inPreferences()) {
|
if (!inPreferences()) {
|
||||||
|
var selectedText = getSelectionText();
|
||||||
|
|
||||||
var lh = dojo.connect(dialog, "onLoad", function(){
|
var lh = dojo.connect(dialog, "onLoad", function(){
|
||||||
dojo.disconnect(lh);
|
dojo.disconnect(lh);
|
||||||
|
|
||||||
|
if (selectedText != "") {
|
||||||
|
|
||||||
|
var feed_id = activeFeedIsCat() ? 'CAT:' + parseInt(getActiveFeedId()) :
|
||||||
|
getActiveFeedId();
|
||||||
|
|
||||||
|
var rule = { reg_exp: selectedText, feed_id: feed_id, filter_type: 1 };
|
||||||
|
|
||||||
|
addFilterRule(null, dojo.toJson(rule));
|
||||||
|
|
||||||
|
} else {
|
||||||
|
|
||||||
var query = "op=rpc&method=getlinktitlebyid&id=" + getActiveArticleId();
|
var query = "op=rpc&method=getlinktitlebyid&id=" + getActiveArticleId();
|
||||||
|
|
||||||
new Ajax.Request("backend.php", {
|
new Ajax.Request("backend.php", {
|
||||||
|
@ -1178,6 +1191,8 @@ function quickAddFilter() {
|
||||||
|
|
||||||
} });
|
} });
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1936,3 +1951,25 @@ function feed_to_label_id(feed) {
|
||||||
return _label_base_index - 1 + Math.abs(feed);
|
return _label_base_index - 1 + Math.abs(feed);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// http://stackoverflow.com/questions/6251937/how-to-get-selecteduser-highlighted-text-in-contenteditable-element-and-replac
|
||||||
|
|
||||||
|
function getSelectionText() {
|
||||||
|
var text = "";
|
||||||
|
|
||||||
|
if (typeof window.getSelection != "undefined") {
|
||||||
|
var sel = window.getSelection();
|
||||||
|
if (sel.rangeCount) {
|
||||||
|
var container = document.createElement("div");
|
||||||
|
for (var i = 0, len = sel.rangeCount; i < len; ++i) {
|
||||||
|
container.appendChild(sel.getRangeAt(i).cloneContents());
|
||||||
|
}
|
||||||
|
text = container.innerHTML;
|
||||||
|
}
|
||||||
|
} else if (typeof document.selection != "undefined") {
|
||||||
|
if (document.selection.type == "Text") {
|
||||||
|
text = document.selection.createRange().textText;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return text.stripTags();
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue