prevent filter selected text dialog from opening in wrong order
This commit is contained in:
parent
590b1fc39e
commit
da97b29dbe
21
js/App.js
21
js/App.js
|
@ -358,6 +358,27 @@ const App = {
|
|||
return p;
|
||||
}
|
||||
},
|
||||
// http://stackoverflow.com/questions/6251937/how-to-get-selecteduser-highlighted-text-in-contenteditable-element-and-replac
|
||||
getSelectedText: function() {
|
||||
let text = "";
|
||||
|
||||
if (typeof window.getSelection != "undefined") {
|
||||
const sel = window.getSelection();
|
||||
if (sel.rangeCount) {
|
||||
const container = document.createElement("div");
|
||||
for (let 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();
|
||||
},
|
||||
displayIfChecked: function(checkbox, elemId) {
|
||||
if (checkbox.checked) {
|
||||
Element.show(elemId);
|
||||
|
|
|
@ -19,8 +19,6 @@ const Filters = {
|
|||
query = {op: "pref-filters", method: "edit", id: id};
|
||||
}
|
||||
|
||||
xhr.post("backend.php", query, function (reply) {
|
||||
try {
|
||||
const dialog = new fox.SingleUseDialog({
|
||||
id: "filterEditDlg",
|
||||
title: id ? __("Edit Filter") : __("Create Filter"),
|
||||
|
@ -307,54 +305,46 @@ const Filters = {
|
|||
});
|
||||
}
|
||||
},
|
||||
content: reply
|
||||
content: __("Loading, please wait...")
|
||||
});
|
||||
|
||||
if (!App.isPrefs()) {
|
||||
/* global getSelectionText */
|
||||
const selectedText = getSelectionText();
|
||||
const tmph = dojo.connect(dialog, 'onShow', function () {
|
||||
dojo.disconnect(tmph);
|
||||
|
||||
const lh = dojo.connect(dialog, "onShow", function () {
|
||||
dojo.disconnect(lh);
|
||||
xhr.post("backend.php", query, function (reply) {
|
||||
dialog.attr('content', reply);
|
||||
|
||||
if (!App.isPrefs()) {
|
||||
const selectedText = App.getSelectedText();
|
||||
|
||||
if (selectedText != "") {
|
||||
|
||||
const feed_id = Feeds.activeIsCat() ? 'CAT:' + parseInt(Feeds.getActive()) :
|
||||
Feeds.getActive();
|
||||
|
||||
const rule = {reg_exp: selectedText, feed_id: [feed_id], filter_type: 1};
|
||||
|
||||
dialog.editRule(null, dojo.toJson(rule));
|
||||
|
||||
} else {
|
||||
|
||||
const query = {op: "article", method: "getmetadatabyid", id: Article.getActive()};
|
||||
|
||||
xhr.json("backend.php", query, (reply) => {
|
||||
let title = false;
|
||||
let title;
|
||||
|
||||
if (reply && reply.title) title = reply.title;
|
||||
|
||||
if (title || Feeds.getActive() || Feeds.activeIsCat()) {
|
||||
|
||||
console.log(title + " " + Feeds.getActive());
|
||||
|
||||
const feed_id = Feeds.activeIsCat() ? 'CAT:' + parseInt(Feeds.getActive()) :
|
||||
Feeds.getActive();
|
||||
|
||||
const rule = {reg_exp: title, feed_id: [feed_id], filter_type: 1};
|
||||
|
||||
dialog.editRule(null, dojo.toJson(rule));
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
});
|
||||
dialog.show();
|
||||
|
||||
} catch (e) {
|
||||
App.Error.report(e);
|
||||
}
|
||||
});
|
||||
},
|
||||
};
|
||||
|
|
22
js/common.js
22
js/common.js
|
@ -401,25 +401,3 @@ const Notify = {
|
|||
}
|
||||
};
|
||||
|
||||
// http://stackoverflow.com/questions/6251937/how-to-get-selecteduser-highlighted-text-in-contenteditable-element-and-replac
|
||||
/* exported getSelectionText */
|
||||
function getSelectionText() {
|
||||
let text = "";
|
||||
|
||||
if (typeof window.getSelection != "undefined") {
|
||||
const sel = window.getSelection();
|
||||
if (sel.rangeCount) {
|
||||
const container = document.createElement("div");
|
||||
for (let 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