]> git.wh0rd.org - tt-rss.git/blob - js/functions.js
remove pubsubhubbub: dead
[tt-rss.git] / js / functions.js
1 var loading_progress = 0;
2 var sanity_check_done = false;
3 var init_params = {};
4 var _label_base_index = -1024;
5 var notify_hide_timerid = false;
6
7 Ajax.Base.prototype.initialize = Ajax.Base.prototype.initialize.wrap(
8 function (callOriginal, options) {
9
10 if (getInitParam("csrf_token") != undefined) {
11 Object.extend(options, options || { });
12
13 if (Object.isString(options.parameters))
14 options.parameters = options.parameters.toQueryParams();
15 else if (Object.isHash(options.parameters))
16 options.parameters = options.parameters.toObject();
17
18 options.parameters["csrf_token"] = getInitParam("csrf_token");
19 }
20
21 return callOriginal(options);
22 }
23 );
24
25 /* add method to remove element from array */
26
27 Array.prototype.remove = function(s) {
28 for (var i=0; i < this.length; i++) {
29 if (s == this[i]) this.splice(i, 1);
30 }
31 };
32
33
34 function report_error(message, filename, lineno, colno, error) {
35 exception_error(error, null, filename, lineno);
36 }
37
38 function exception_error(e, e_compat, filename, lineno, colno) {
39 if (typeof e == "string") e = e_compat;
40
41 if (!e) return; // no exception object, nothing to report.
42
43 try {
44 console.error(e);
45 var msg = e.toString();
46
47 try {
48 new Ajax.Request("backend.php", {
49 parameters: {op: "rpc", method: "log",
50 file: e.fileName ? e.fileName : filename,
51 line: e.lineNumber ? e.lineNumber : lineno,
52 msg: msg, context: e.stack},
53 onComplete: function (transport) {
54 console.warn(transport.responseText);
55 } });
56
57 } catch (e) {
58 console.error("Exception while trying to log the error.", e);
59 }
60
61 var content = "<div class='fatalError'><p>" + msg + "</p>";
62
63 if (e.stack) {
64 content += "<div><b>Stack trace:</b></div>" +
65 "<textarea name=\"stack\" readonly=\"1\">" + e.stack + "</textarea>";
66 }
67
68 content += "</div>";
69
70 content += "<div class='dlgButtons'>";
71
72 content += "<button dojoType=\"dijit.form.Button\" "+
73 "onclick=\"dijit.byId('exceptionDlg').hide()\">" +
74 __('Close') + "</button>";
75 content += "</div>";
76
77 if (dijit.byId("exceptionDlg"))
78 dijit.byId("exceptionDlg").destroyRecursive();
79
80 var dialog = new dijit.Dialog({
81 id: "exceptionDlg",
82 title: "Unhandled exception",
83 style: "width: 600px",
84 content: content});
85
86 dialog.show();
87
88 } catch (ei) {
89 console.error("Exception while trying to report an exception:", ei);
90 console.error("Original exception:", e);
91
92 alert("Exception occured while trying to report an exception.\n" +
93 ei.stack + "\n\nOriginal exception:\n" + e.stack);
94 }
95
96 }
97
98 function param_escape(arg) {
99 if (typeof encodeURIComponent != 'undefined')
100 return encodeURIComponent(arg);
101 else
102 return escape(arg);
103 }
104
105 function param_unescape(arg) {
106 if (typeof decodeURIComponent != 'undefined')
107 return decodeURIComponent(arg);
108 else
109 return unescape(arg);
110 }
111
112 function notify_real(msg, no_hide, n_type) {
113
114 var n = $("notify");
115
116 if (!n) return;
117
118 if (notify_hide_timerid) {
119 window.clearTimeout(notify_hide_timerid);
120 }
121
122 if (msg == "") {
123 if (n.hasClassName("visible")) {
124 notify_hide_timerid = window.setTimeout(function() {
125 n.removeClassName("visible") }, 0);
126 }
127 return;
128 }
129
130 /* types:
131
132 1 - generic
133 2 - progress
134 3 - error
135 4 - info
136
137 */
138
139 msg = "<span class=\"msg\"> " + __(msg) + "</span>";
140
141 if (n_type == 2) {
142 msg = "<span><img src=\""+getInitParam("icon_indicator_white")+"\"></span>" + msg;
143 no_hide = true;
144 } else if (n_type == 3) {
145 msg = "<span><img src=\""+getInitParam("icon_alert")+"\"></span>" + msg;
146 } else if (n_type == 4) {
147 msg = "<span><img src=\""+getInitParam("icon_information")+"\"></span>" + msg;
148 }
149
150 msg += " <span><img src=\""+getInitParam("icon_cross")+"\" class=\"close\" title=\"" +
151 __("Click to close") + "\" onclick=\"notify('')\"></span>";
152
153 n.innerHTML = msg;
154
155 window.setTimeout(function() {
156 // goddamnit firefox
157 if (n_type == 2) {
158 n.className = "notify notify_progress visible";
159 } else if (n_type == 3) {
160 n.className = "notify notify_error visible";
161 msg = "<span><img src='images/alert.png'></span>" + msg;
162 } else if (n_type == 4) {
163 n.className = "notify notify_info visible";
164 } else {
165 n.className = "notify visible";
166 }
167
168 if (!no_hide) {
169 notify_hide_timerid = window.setTimeout(function() {
170 n.removeClassName("visible") }, 5*1000);
171 }
172
173 }, 10);
174
175 }
176
177 function notify(msg, no_hide) {
178 notify_real(msg, no_hide, 1);
179 }
180
181 function notify_progress(msg, no_hide) {
182 notify_real(msg, no_hide, 2);
183 }
184
185 function notify_error(msg, no_hide) {
186 notify_real(msg, no_hide, 3);
187
188 }
189
190 function notify_info(msg, no_hide) {
191 notify_real(msg, no_hide, 4);
192 }
193
194 function setCookie(name, value, lifetime, path, domain, secure) {
195
196 var d = false;
197
198 if (lifetime) {
199 d = new Date();
200 d.setTime(d.getTime() + (lifetime * 1000));
201 }
202
203 console.log("setCookie: " + name + " => " + value + ": " + d);
204
205 int_setCookie(name, value, d, path, domain, secure);
206
207 }
208
209 function int_setCookie(name, value, expires, path, domain, secure) {
210 document.cookie= name + "=" + escape(value) +
211 ((expires) ? "; expires=" + expires.toGMTString() : "") +
212 ((path) ? "; path=" + path : "") +
213 ((domain) ? "; domain=" + domain : "") +
214 ((secure) ? "; secure" : "");
215 }
216
217 function delCookie(name, path, domain) {
218 if (getCookie(name)) {
219 document.cookie = name + "=" +
220 ((path) ? ";path=" + path : "") +
221 ((domain) ? ";domain=" + domain : "" ) +
222 ";expires=Thu, 01-Jan-1970 00:00:01 GMT";
223 }
224 }
225
226
227 function getCookie(name) {
228
229 var dc = document.cookie;
230 var prefix = name + "=";
231 var begin = dc.indexOf("; " + prefix);
232 if (begin == -1) {
233 begin = dc.indexOf(prefix);
234 if (begin != 0) return null;
235 }
236 else {
237 begin += 2;
238 }
239 var end = document.cookie.indexOf(";", begin);
240 if (end == -1) {
241 end = dc.length;
242 }
243 return unescape(dc.substring(begin + prefix.length, end));
244 }
245
246 function gotoPreferences() {
247 document.location.href = "prefs.php";
248 }
249
250 function gotoLogout() {
251 document.location.href = "backend.php?op=logout";
252 }
253
254 function gotoMain() {
255 document.location.href = "index.php";
256 }
257
258 /** * @(#)isNumeric.js * * Copyright (c) 2000 by Sundar Dorai-Raj
259 * * @author Sundar Dorai-Raj
260 * * Email: sdoraira@vt.edu
261 * * This program is free software; you can redistribute it and/or
262 * * modify it under the terms of the GNU General Public License
263 * * as published by the Free Software Foundation; either version 2
264 * * of the License, or (at your option) any later version,
265 * * provided that any use properly credits the author.
266 * * This program is distributed in the hope that it will be useful,
267 * * but WITHOUT ANY WARRANTY; without even the implied warranty of
268 * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
269 * * GNU General Public License for more details at http://www.gnu.org * * */
270
271 var numbers=".0123456789";
272 function isNumeric(x) {
273 // is x a String or a character?
274 if(x.length>1) {
275 // remove negative sign
276 x=Math.abs(x)+"";
277 for(var j=0;j<x.length;j++) {
278 // call isNumeric recursively for each character
279 number=isNumeric(x.substring(j,j+1));
280 if(!number) return number;
281 }
282 return number;
283 }
284 else {
285 // if x is number return true
286 if(numbers.indexOf(x)>=0) return true;
287 return false;
288 }
289 }
290
291
292 function toggleSelectRowById(sender, id) {
293 var row = $(id);
294 return toggleSelectRow(sender, row);
295 }
296
297 function toggleSelectListRow(sender) {
298 var row = sender.parentNode;
299 return toggleSelectRow(sender, row);
300 }
301
302 /* this is for dijit Checkbox */
303 function toggleSelectListRow2(sender) {
304 var row = sender.domNode.parentNode;
305 return toggleSelectRow(sender, row);
306 }
307
308 /* this is for dijit Checkbox */
309 function toggleSelectRow2(sender, row, is_cdm) {
310
311 if (!row)
312 if (!is_cdm)
313 row = sender.domNode.parentNode.parentNode;
314 else
315 row = sender.domNode.parentNode.parentNode.parentNode; // oh ffs
316
317 if (sender.checked && !row.hasClassName('Selected'))
318 row.addClassName('Selected');
319 else
320 row.removeClassName('Selected');
321
322 if (typeof updateSelectedPrompt != undefined)
323 updateSelectedPrompt();
324 }
325
326
327 function toggleSelectRow(sender, row) {
328
329 if (!row) row = sender.parentNode.parentNode;
330
331 if (sender.checked && !row.hasClassName('Selected'))
332 row.addClassName('Selected');
333 else
334 row.removeClassName('Selected');
335
336 if (typeof updateSelectedPrompt != undefined)
337 updateSelectedPrompt();
338 }
339
340 function checkboxToggleElement(elem, id) {
341 if (elem.checked) {
342 Effect.Appear(id, {duration : 0.5});
343 } else {
344 Effect.Fade(id, {duration : 0.5});
345 }
346 }
347
348 function dropboxSelect(e, v) {
349 for (var i = 0; i < e.length; i++) {
350 if (e[i].value == v) {
351 e.selectedIndex = i;
352 break;
353 }
354 }
355 }
356
357 function getURLParam(param){
358 return String(window.location.href).parseQuery()[param];
359 }
360
361 function closeInfoBox(cleanup) {
362 dialog = dijit.byId("infoBox");
363
364 if (dialog) dialog.hide();
365
366 return false;
367 }
368
369
370 function displayDlg(title, id, param, callback) {
371
372 notify_progress("Loading, please wait...", true);
373
374 var query = "?op=dlg&method=" +
375 param_escape(id) + "&param=" + param_escape(param);
376
377 new Ajax.Request("backend.php", {
378 parameters: query,
379 onComplete: function (transport) {
380 infobox_callback2(transport, title);
381 if (callback) callback(transport);
382 } });
383
384 return false;
385 }
386
387 function infobox_callback2(transport, title) {
388 var dialog = false;
389
390 if (dijit.byId("infoBox")) {
391 dialog = dijit.byId("infoBox");
392 }
393
394 //console.log("infobox_callback2");
395 notify('');
396
397 var content = transport.responseText;
398
399 if (!dialog) {
400 dialog = new dijit.Dialog({
401 title: title,
402 id: 'infoBox',
403 style: "width: 600px",
404 onCancel: function() {
405 return true;
406 },
407 onExecute: function() {
408 return true;
409 },
410 onClose: function() {
411 return true;
412 },
413 content: content});
414 } else {
415 dialog.attr('title', title);
416 dialog.attr('content', content);
417 }
418
419 dialog.show();
420
421 notify("");
422 }
423
424 function getInitParam(key) {
425 return init_params[key];
426 }
427
428 function setInitParam(key, value) {
429 init_params[key] = value;
430 }
431
432 function fatalError(code, msg, ext_info) {
433 if (code == 6) {
434 window.location.href = "index.php";
435 } else if (code == 5) {
436 window.location.href = "public.php?op=dbupdate";
437 } else {
438
439 if (msg == "") msg = "Unknown error";
440
441 if (ext_info) {
442 if (ext_info.responseText) {
443 ext_info = ext_info.responseText;
444 }
445 }
446
447 if (ERRORS && ERRORS[code] && !msg) {
448 msg = ERRORS[code];
449 }
450
451 var content = "<div><b>Error code:</b> " + code + "</div>" +
452 "<p>" + msg + "</p>";
453
454 if (ext_info) {
455 content = content + "<div><b>Additional information:</b></div>" +
456 "<textarea style='width: 100%' readonly=\"1\">" +
457 ext_info + "</textarea>";
458 }
459
460 var dialog = new dijit.Dialog({
461 title: "Fatal error",
462 style: "width: 600px",
463 content: content});
464
465 dialog.show();
466
467 }
468
469 return false;
470
471 }
472
473 function filterDlgCheckAction(sender) {
474 var action = sender.value;
475
476 var action_param = $("filterDlg_paramBox");
477
478 if (!action_param) {
479 console.log("filterDlgCheckAction: can't find action param box!");
480 return;
481 }
482
483 // if selected action supports parameters, enable params field
484 if (action == 4 || action == 6 || action == 7 || action == 9) {
485 new Effect.Appear(action_param, {duration : 0.5});
486
487 Element.hide(dijit.byId("filterDlg_actionParam").domNode);
488 Element.hide(dijit.byId("filterDlg_actionParamLabel").domNode);
489 Element.hide(dijit.byId("filterDlg_actionParamPlugin").domNode);
490
491 if (action == 7) {
492 Element.show(dijit.byId("filterDlg_actionParamLabel").domNode);
493 } else if (action == 9) {
494 Element.show(dijit.byId("filterDlg_actionParamPlugin").domNode);
495 } else {
496 Element.show(dijit.byId("filterDlg_actionParam").domNode);
497 }
498
499 } else {
500 Element.hide(action_param);
501 }
502 }
503
504
505 function explainError(code) {
506 return displayDlg(__("Error explained"), "explainError", code);
507 }
508
509 function loading_set_progress(p) {
510 loading_progress += p;
511
512 if (dijit.byId("loading_bar"))
513 dijit.byId("loading_bar").update({progress: loading_progress});
514
515 if (loading_progress >= 90)
516 remove_splash();
517
518 }
519
520 function remove_splash() {
521
522 if (Element.visible("overlay")) {
523 console.log("about to remove splash, OMG!");
524 Element.hide("overlay");
525 console.log("removed splash!");
526 }
527 }
528
529 function strip_tags(s) {
530 return s.replace(/<\/?[^>]+(>|$)/g, "");
531 }
532
533 function truncate_string(s, length) {
534 if (!length) length = 30;
535 var tmp = s.substring(0, length);
536 if (s.length > length) tmp += "&hellip;";
537 return tmp;
538 }
539
540 function hotkey_prefix_timeout() {
541
542 var date = new Date();
543 var ts = Math.round(date.getTime() / 1000);
544
545 if (hotkey_prefix_pressed && ts - hotkey_prefix_pressed >= 5) {
546 console.log("hotkey_prefix seems to be stuck, aborting");
547 hotkey_prefix_pressed = false;
548 hotkey_prefix = false;
549 Element.hide('cmdline');
550 }
551
552 setTimeout(hotkey_prefix_timeout, 1000);
553
554 }
555
556 function uploadIconHandler(rc) {
557 switch (rc) {
558 case 0:
559 notify_info("Upload complete.");
560 if (inPreferences()) {
561 updateFeedList();
562 } else {
563 setTimeout('updateFeedList(false, false)', 50);
564 }
565 break;
566 case 1:
567 notify_error("Upload failed: icon is too big.");
568 break;
569 case 2:
570 notify_error("Upload failed.");
571 break;
572 }
573 }
574
575 function removeFeedIcon(id) {
576 if (confirm(__("Remove stored feed icon?"))) {
577 var query = "backend.php?op=pref-feeds&method=removeicon&feed_id=" + param_escape(id);
578
579 console.log(query);
580
581 notify_progress("Removing feed icon...", true);
582
583 new Ajax.Request("backend.php", {
584 parameters: query,
585 onComplete: function(transport) {
586 notify_info("Feed icon removed.");
587 if (inPreferences()) {
588 updateFeedList();
589 } else {
590 setTimeout('updateFeedList(false, false)', 50);
591 }
592 } });
593 }
594
595 return false;
596 }
597
598 function uploadFeedIcon() {
599 var file = $("icon_file");
600
601 if (file.value.length == 0) {
602 alert(__("Please select an image file to upload."));
603 } else {
604 if (confirm(__("Upload new icon for this feed?"))) {
605 notify_progress("Uploading, please wait...", true);
606 return true;
607 }
608 }
609
610 return false;
611 }
612
613 function addLabel(select, callback) {
614
615 var caption = prompt(__("Please enter label caption:"), "");
616
617 if (caption != undefined) {
618
619 if (caption == "") {
620 alert(__("Can't create label: missing caption."));
621 return false;
622 }
623
624 var query = "?op=pref-labels&method=add&caption=" +
625 param_escape(caption);
626
627 if (select)
628 query += "&output=select";
629
630 notify_progress("Loading, please wait...", true);
631
632 if (inPreferences() && !select) active_tab = "labelConfig";
633
634 new Ajax.Request("backend.php", {
635 parameters: query,
636 onComplete: function(transport) {
637 if (callback) {
638 callback(transport);
639 } else if (inPreferences()) {
640 updateLabelList();
641 } else {
642 updateFeedList();
643 }
644 } });
645
646 }
647
648 }
649
650 function quickAddFeed() {
651 var query = "backend.php?op=feeds&method=quickAddFeed";
652
653 // overlapping widgets
654 if (dijit.byId("batchSubDlg")) dijit.byId("batchSubDlg").destroyRecursive();
655 if (dijit.byId("feedAddDlg")) dijit.byId("feedAddDlg").destroyRecursive();
656
657 var dialog = new dijit.Dialog({
658 id: "feedAddDlg",
659 title: __("Subscribe to Feed"),
660 style: "width: 600px",
661 show_error: function(msg) {
662 var elem = $("fadd_error_message");
663
664 elem.innerHTML = msg;
665
666 if (!Element.visible(elem))
667 new Effect.Appear(elem);
668
669 },
670 execute: function() {
671 if (this.validate()) {
672 console.log(dojo.objectToQuery(this.attr('value')));
673
674 var feed_url = this.attr('value').feed;
675
676 Element.show("feed_add_spinner");
677 Element.hide("fadd_error_message");
678
679 new Ajax.Request("backend.php", {
680 parameters: dojo.objectToQuery(this.attr('value')),
681 onComplete: function(transport) {
682 try {
683
684 try {
685 var reply = JSON.parse(transport.responseText);
686 } catch (e) {
687 Element.hide("feed_add_spinner");
688 alert(__("Failed to parse output. This can indicate server timeout and/or network issues. Backend output was logged to browser console."));
689 console.log('quickAddFeed, backend returned:' + transport.responseText);
690 return;
691 }
692
693 var rc = reply['result'];
694
695 notify('');
696 Element.hide("feed_add_spinner");
697
698 console.log(rc);
699
700 switch (parseInt(rc['code'])) {
701 case 1:
702 dialog.hide();
703 notify_info(__("Subscribed to %s").replace("%s", feed_url));
704
705 updateFeedList();
706 break;
707 case 2:
708 dialog.show_error(__("Specified URL seems to be invalid."));
709 break;
710 case 3:
711 dialog.show_error(__("Specified URL doesn't seem to contain any feeds."));
712 break;
713 case 4:
714 feeds = rc['feeds'];
715
716 Element.show("fadd_multiple_notify");
717
718 var select = dijit.byId("feedDlg_feedContainerSelect");
719
720 while (select.getOptions().length > 0)
721 select.removeOption(0);
722
723 select.addOption({value: '', label: __("Expand to select feed")});
724
725 var count = 0;
726 for (var feedUrl in feeds) {
727 select.addOption({value: feedUrl, label: feeds[feedUrl]});
728 count++;
729 }
730
731 Effect.Appear('feedDlg_feedsContainer', {duration : 0.5});
732
733 break;
734 case 5:
735 dialog.show_error(__("Couldn't download the specified URL: %s").
736 replace("%s", rc['message']));
737 break;
738 case 6:
739 dialog.show_error(__("XML validation failed: %s").
740 replace("%s", rc['message']));
741 break;
742 break;
743 case 0:
744 dialog.show_error(__("You are already subscribed to this feed."));
745 break;
746 }
747
748 } catch (e) {
749 console.error(transport.responseText);
750 exception_error(e);
751 }
752
753 } });
754
755 }
756 },
757 href: query});
758
759 dialog.show();
760 }
761
762 function createNewRuleElement(parentNode, replaceNode) {
763 var form = document.forms["filter_new_rule_form"];
764
765 //form.reg_exp.value = form.reg_exp.value.replace(/(<([^>]+)>)/ig,"");
766
767 var query = "backend.php?op=pref-filters&method=printrulename&rule="+
768 param_escape(dojo.formToJson(form));
769
770 console.log(query);
771
772 new Ajax.Request("backend.php", {
773 parameters: query,
774 onComplete: function (transport) {
775 try {
776 var li = dojo.create("li");
777
778 var cb = dojo.create("input", { type: "checkbox" }, li);
779
780 new dijit.form.CheckBox({
781 onChange: function() {
782 toggleSelectListRow2(this) },
783 }, cb);
784
785 dojo.create("input", { type: "hidden",
786 name: "rule[]",
787 value: dojo.formToJson(form) }, li);
788
789 dojo.create("span", {
790 onclick: function() {
791 dijit.byId('filterEditDlg').editRule(this);
792 },
793 innerHTML: transport.responseText }, li);
794
795 if (replaceNode) {
796 parentNode.replaceChild(li, replaceNode);
797 } else {
798 parentNode.appendChild(li);
799 }
800 } catch (e) {
801 exception_error(e);
802 }
803 } });
804 }
805
806 function createNewActionElement(parentNode, replaceNode) {
807 var form = document.forms["filter_new_action_form"];
808
809 if (form.action_id.value == 7) {
810 form.action_param.value = form.action_param_label.value;
811 } else if (form.action_id.value == 9) {
812 form.action_param.value = form.action_param_plugin.value;
813 }
814
815 var query = "backend.php?op=pref-filters&method=printactionname&action="+
816 param_escape(dojo.formToJson(form));
817
818 console.log(query);
819
820 new Ajax.Request("backend.php", {
821 parameters: query,
822 onComplete: function (transport) {
823 try {
824 var li = dojo.create("li");
825
826 var cb = dojo.create("input", { type: "checkbox" }, li);
827
828 new dijit.form.CheckBox({
829 onChange: function() {
830 toggleSelectListRow2(this) },
831 }, cb);
832
833 dojo.create("input", { type: "hidden",
834 name: "action[]",
835 value: dojo.formToJson(form) }, li);
836
837 dojo.create("span", {
838 onclick: function() {
839 dijit.byId('filterEditDlg').editAction(this);
840 },
841 innerHTML: transport.responseText }, li);
842
843 if (replaceNode) {
844 parentNode.replaceChild(li, replaceNode);
845 } else {
846 parentNode.appendChild(li);
847 }
848
849 } catch (e) {
850 exception_error(e);
851 }
852 } });
853 }
854
855
856 function addFilterRule(replaceNode, ruleStr) {
857 if (dijit.byId("filterNewRuleDlg"))
858 dijit.byId("filterNewRuleDlg").destroyRecursive();
859
860 var query = "backend.php?op=pref-filters&method=newrule&rule=" +
861 param_escape(ruleStr);
862
863 var rule_dlg = new dijit.Dialog({
864 id: "filterNewRuleDlg",
865 title: ruleStr ? __("Edit rule") : __("Add rule"),
866 style: "width: 600px",
867 execute: function() {
868 if (this.validate()) {
869 createNewRuleElement($("filterDlg_Matches"), replaceNode);
870 this.hide();
871 }
872 },
873 href: query});
874
875 rule_dlg.show();
876 }
877
878 function addFilterAction(replaceNode, actionStr) {
879 if (dijit.byId("filterNewActionDlg"))
880 dijit.byId("filterNewActionDlg").destroyRecursive();
881
882 var query = "backend.php?op=pref-filters&method=newaction&action=" +
883 param_escape(actionStr);
884
885 var rule_dlg = new dijit.Dialog({
886 id: "filterNewActionDlg",
887 title: actionStr ? __("Edit action") : __("Add action"),
888 style: "width: 600px",
889 execute: function() {
890 if (this.validate()) {
891 createNewActionElement($("filterDlg_Actions"), replaceNode);
892 this.hide();
893 }
894 },
895 href: query});
896
897 rule_dlg.show();
898 }
899
900 function editFilterTest(query) {
901
902 if (dijit.byId("filterTestDlg"))
903 dijit.byId("filterTestDlg").destroyRecursive();
904
905 var test_dlg = new dijit.Dialog({
906 id: "filterTestDlg",
907 title: "Test Filter",
908 style: "width: 600px",
909 results: 0,
910 limit: 100,
911 max_offset: 10000,
912 getTestResults: function(query, offset) {
913 var updquery = query + "&offset=" + offset + "&limit=" + test_dlg.limit;
914
915 console.log("getTestResults:" + offset);
916
917 new Ajax.Request("backend.php", {
918 parameters: updquery,
919 onComplete: function (transport) {
920 try {
921 var result = JSON.parse(transport.responseText);
922
923 if (result && dijit.byId("filterTestDlg") && dijit.byId("filterTestDlg").open) {
924 test_dlg.results += result.size();
925
926 console.log("got results:" + result.size());
927
928 $("prefFilterProgressMsg").innerHTML = __("Looking for articles (%d processed, %f found)...")
929 .replace("%f", test_dlg.results)
930 .replace("%d", offset);
931
932 console.log(offset + " " + test_dlg.max_offset);
933
934 for (var i = 0; i < result.size(); i++) {
935 var tmp = new Element("table");
936 tmp.innerHTML = result[i];
937 dojo.parser.parse(tmp);
938
939 $("prefFilterTestResultList").innerHTML += tmp.innerHTML;
940 }
941
942 if (test_dlg.results < 30 && offset < test_dlg.max_offset) {
943
944 // get the next batch
945 window.setTimeout(function () {
946 test_dlg.getTestResults(query, offset + test_dlg.limit);
947 }, 0);
948
949 } else {
950 // all done
951
952 Element.hide("prefFilterLoadingIndicator");
953
954 if (test_dlg.results == 0) {
955 $("prefFilterTestResultList").innerHTML = "<tr><td align='center'>No recent articles matching this filter have been found.</td></tr>";
956 $("prefFilterProgressMsg").innerHTML = "Articles matching this filter:";
957 } else {
958 $("prefFilterProgressMsg").innerHTML = __("Found %d articles matching this filter:")
959 .replace("%d", test_dlg.results);
960 }
961
962 }
963
964 } else if (!result) {
965 console.log("getTestResults: can't parse results object");
966
967 Element.hide("prefFilterLoadingIndicator");
968
969 notify_error("Error while trying to get filter test results.");
970
971 } else {
972 console.log("getTestResults: dialog closed, bailing out.");
973 }
974 } catch (e) {
975 exception_error(e);
976 }
977
978 } });
979 },
980 href: query});
981
982 dojo.connect(test_dlg, "onLoad", null, function(e) {
983 test_dlg.getTestResults(query, 0);
984 });
985
986 test_dlg.show();
987
988 }
989
990 function quickAddFilter() {
991 var query = "";
992 if (!inPreferences()) {
993 query = "backend.php?op=pref-filters&method=newfilter&feed=" +
994 param_escape(getActiveFeedId()) + "&is_cat=" +
995 param_escape(activeFeedIsCat());
996 } else {
997 query = "backend.php?op=pref-filters&method=newfilter";
998 }
999
1000 console.log(query);
1001
1002 if (dijit.byId("feedEditDlg"))
1003 dijit.byId("feedEditDlg").destroyRecursive();
1004
1005 if (dijit.byId("filterEditDlg"))
1006 dijit.byId("filterEditDlg").destroyRecursive();
1007
1008 dialog = new dijit.Dialog({
1009 id: "filterEditDlg",
1010 title: __("Create Filter"),
1011 style: "width: 600px",
1012 test: function() {
1013 var query = "backend.php?" + dojo.formToQuery("filter_new_form") + "&savemode=test";
1014
1015 editFilterTest(query);
1016 },
1017 selectRules: function(select) {
1018 $$("#filterDlg_Matches input[type=checkbox]").each(function(e) {
1019 e.checked = select;
1020 if (select)
1021 e.parentNode.addClassName("Selected");
1022 else
1023 e.parentNode.removeClassName("Selected");
1024 });
1025 },
1026 selectActions: function(select) {
1027 $$("#filterDlg_Actions input[type=checkbox]").each(function(e) {
1028 e.checked = select;
1029
1030 if (select)
1031 e.parentNode.addClassName("Selected");
1032 else
1033 e.parentNode.removeClassName("Selected");
1034
1035 });
1036 },
1037 editRule: function(e) {
1038 var li = e.parentNode;
1039 var rule = li.getElementsByTagName("INPUT")[1].value;
1040 addFilterRule(li, rule);
1041 },
1042 editAction: function(e) {
1043 var li = e.parentNode;
1044 var action = li.getElementsByTagName("INPUT")[1].value;
1045 addFilterAction(li, action);
1046 },
1047 addAction: function() { addFilterAction(); },
1048 addRule: function() { addFilterRule(); },
1049 deleteAction: function() {
1050 $$("#filterDlg_Actions li.[class*=Selected]").each(function(e) { e.parentNode.removeChild(e) });
1051 },
1052 deleteRule: function() {
1053 $$("#filterDlg_Matches li.[class*=Selected]").each(function(e) { e.parentNode.removeChild(e) });
1054 },
1055 execute: function() {
1056 if (this.validate()) {
1057
1058 var query = dojo.formToQuery("filter_new_form");
1059
1060 console.log(query);
1061
1062 new Ajax.Request("backend.php", {
1063 parameters: query,
1064 onComplete: function (transport) {
1065 if (inPreferences()) {
1066 updateFilterList();
1067 }
1068
1069 dialog.hide();
1070 } });
1071 }
1072 },
1073 href: query});
1074
1075 if (!inPreferences()) {
1076 var selectedText = getSelectionText();
1077
1078 var lh = dojo.connect(dialog, "onLoad", function(){
1079 dojo.disconnect(lh);
1080
1081 if (selectedText != "") {
1082
1083 var feed_id = activeFeedIsCat() ? 'CAT:' + parseInt(getActiveFeedId()) :
1084 getActiveFeedId();
1085
1086 var rule = { reg_exp: selectedText, feed_id: feed_id, filter_type: 1 };
1087
1088 addFilterRule(null, dojo.toJson(rule));
1089
1090 } else {
1091
1092 var query = "op=rpc&method=getlinktitlebyid&id=" + getActiveArticleId();
1093
1094 new Ajax.Request("backend.php", {
1095 parameters: query,
1096 onComplete: function(transport) {
1097 var reply = JSON.parse(transport.responseText);
1098
1099 var title = false;
1100
1101 if (reply && reply) title = reply.title;
1102
1103 if (title || getActiveFeedId() || activeFeedIsCat()) {
1104
1105 console.log(title + " " + getActiveFeedId());
1106
1107 var feed_id = activeFeedIsCat() ? 'CAT:' + parseInt(getActiveFeedId()) :
1108 getActiveFeedId();
1109
1110 var rule = { reg_exp: title, feed_id: feed_id, filter_type: 1 };
1111
1112 addFilterRule(null, dojo.toJson(rule));
1113 }
1114
1115 } });
1116
1117 }
1118
1119 });
1120 }
1121
1122 dialog.show();
1123
1124 }
1125
1126 function unsubscribeFeed(feed_id, title) {
1127
1128 var msg = __("Unsubscribe from %s?").replace("%s", title);
1129
1130 if (title == undefined || confirm(msg)) {
1131 notify_progress("Removing feed...");
1132
1133 var query = "?op=pref-feeds&quiet=1&method=remove&ids=" + feed_id;
1134
1135 new Ajax.Request("backend.php", {
1136 parameters: query,
1137 onComplete: function(transport) {
1138
1139 if (dijit.byId("feedEditDlg")) dijit.byId("feedEditDlg").hide();
1140
1141 if (inPreferences()) {
1142 updateFeedList();
1143 } else {
1144 if (feed_id == getActiveFeedId())
1145 setTimeout(function() { viewfeed({feed:-5}) }, 100);
1146
1147 if (feed_id < 0) updateFeedList();
1148 }
1149
1150 } });
1151 }
1152
1153 return false;
1154 }
1155
1156
1157 function backend_sanity_check_callback(transport) {
1158
1159 if (sanity_check_done) {
1160 fatalError(11, "Sanity check request received twice. This can indicate "+
1161 "presence of Firebug or some other disrupting extension. "+
1162 "Please disable it and try again.");
1163 return;
1164 }
1165
1166 var reply = JSON.parse(transport.responseText);
1167
1168 if (!reply) {
1169 fatalError(3, "Sanity check: invalid RPC reply", transport.responseText);
1170 return;
1171 }
1172
1173 var error_code = reply['error']['code'];
1174
1175 if (error_code && error_code != 0) {
1176 return fatalError(error_code, reply['error']['message']);
1177 }
1178
1179 console.log("sanity check ok");
1180
1181 var params = reply['init-params'];
1182
1183 if (params) {
1184 console.log('reading init-params...');
1185
1186 for (k in params) {
1187 console.log("IP: " + k + " => " + JSON.stringify(params[k]));
1188 if (k == "label_base_index") _label_base_index = parseInt(params[k]);
1189 }
1190
1191 init_params = params;
1192
1193 // PluginHost might not be available on non-index pages
1194 window.PluginHost && PluginHost.run(PluginHost.HOOK_PARAMS_LOADED, init_params);
1195 }
1196
1197 sanity_check_done = true;
1198
1199 init_second_stage();
1200
1201 }
1202
1203 function quickAddCat(elem) {
1204 var cat = prompt(__("Please enter category title:"));
1205
1206 if (cat) {
1207
1208 var query = "?op=rpc&method=quickAddCat&cat=" + param_escape(cat);
1209
1210 notify_progress("Loading, please wait...", true);
1211
1212 new Ajax.Request("backend.php", {
1213 parameters: query,
1214 onComplete: function (transport) {
1215 var response = transport.responseXML;
1216 var select = response.getElementsByTagName("select")[0];
1217 var options = select.getElementsByTagName("option");
1218
1219 dropbox_replace_options(elem, options);
1220
1221 notify('');
1222
1223 } });
1224
1225 }
1226 }
1227
1228 function genUrlChangeKey(feed, is_cat) {
1229 var ok = confirm(__("Generate new syndication address for this feed?"));
1230
1231 if (ok) {
1232
1233 notify_progress("Trying to change address...", true);
1234
1235 var query = "?op=pref-feeds&method=regenFeedKey&id=" + param_escape(feed) +
1236 "&is_cat=" + param_escape(is_cat);
1237
1238 new Ajax.Request("backend.php", {
1239 parameters: query,
1240 onComplete: function(transport) {
1241 var reply = JSON.parse(transport.responseText);
1242 var new_link = reply.link;
1243
1244 var e = $('gen_feed_url');
1245
1246 if (new_link) {
1247
1248 e.innerHTML = e.innerHTML.replace(/\&amp;key=.*$/,
1249 "&amp;key=" + new_link);
1250
1251 e.href = e.href.replace(/\&key=.*$/,
1252 "&key=" + new_link);
1253
1254 new Effect.Highlight(e);
1255
1256 notify('');
1257
1258 } else {
1259 notify_error("Could not change feed URL.");
1260 }
1261 } });
1262 }
1263 return false;
1264 }
1265
1266 function dropbox_replace_options(elem, options) {
1267 while (elem.hasChildNodes())
1268 elem.removeChild(elem.firstChild);
1269
1270 var sel_idx = -1;
1271
1272 for (var i = 0; i < options.length; i++) {
1273 var text = options[i].firstChild.nodeValue;
1274 var value = options[i].getAttribute("value");
1275
1276 if (value == undefined) value = text;
1277
1278 var issel = options[i].getAttribute("selected") == "1";
1279
1280 var option = new Option(text, value, issel);
1281
1282 if (options[i].getAttribute("disabled"))
1283 option.setAttribute("disabled", true);
1284
1285 elem.insert(option);
1286
1287 if (issel) sel_idx = i;
1288 }
1289
1290 // Chrome doesn't seem to just select stuff when you pass new Option(x, y, true)
1291 if (sel_idx >= 0) elem.selectedIndex = sel_idx;
1292 }
1293
1294 // mode = all, none, invert
1295 function selectTableRows(id, mode) {
1296 var rows = $(id).rows;
1297
1298 for (var i = 0; i < rows.length; i++) {
1299 var row = rows[i];
1300 var cb = false;
1301 var dcb = false;
1302
1303 if (row.id && row.className) {
1304 var bare_id = row.id.replace(/^[A-Z]*?-/, "");
1305 var inputs = rows[i].getElementsByTagName("input");
1306
1307 for (var j = 0; j < inputs.length; j++) {
1308 var input = inputs[j];
1309
1310 if (input.getAttribute("type") == "checkbox" &&
1311 input.id.match(bare_id)) {
1312
1313 cb = input;
1314 dcb = dijit.getEnclosingWidget(cb);
1315 break;
1316 }
1317 }
1318
1319 if (cb || dcb) {
1320 var issel = row.hasClassName("Selected");
1321
1322 if (mode == "all" && !issel) {
1323 row.addClassName("Selected");
1324 cb.checked = true;
1325 if (dcb) dcb.set("checked", true);
1326 } else if (mode == "none" && issel) {
1327 row.removeClassName("Selected");
1328 cb.checked = false;
1329 if (dcb) dcb.set("checked", false);
1330
1331 } else if (mode == "invert") {
1332
1333 if (issel) {
1334 row.removeClassName("Selected");
1335 cb.checked = false;
1336 if (dcb) dcb.set("checked", false);
1337 } else {
1338 row.addClassName("Selected");
1339 cb.checked = true;
1340 if (dcb) dcb.set("checked", true);
1341 }
1342 }
1343 }
1344 }
1345 }
1346
1347 }
1348
1349 function getSelectedTableRowIds(id) {
1350 var rows = [];
1351
1352 var elem_rows = $(id).rows;
1353
1354 for (var i = 0; i < elem_rows.length; i++) {
1355 if (elem_rows[i].hasClassName("Selected")) {
1356 var bare_id = elem_rows[i].id.replace(/^[A-Z]*?-/, "");
1357 rows.push(bare_id);
1358 }
1359 }
1360
1361 return rows;
1362 }
1363
1364 function editFeed(feed, event) {
1365 if (feed <= 0)
1366 return alert(__("You can't edit this kind of feed."));
1367
1368 var query = "backend.php?op=pref-feeds&method=editfeed&id=" +
1369 param_escape(feed);
1370
1371 console.log(query);
1372
1373 if (dijit.byId("filterEditDlg"))
1374 dijit.byId("filterEditDlg").destroyRecursive();
1375
1376 if (dijit.byId("feedEditDlg"))
1377 dijit.byId("feedEditDlg").destroyRecursive();
1378
1379 dialog = new dijit.Dialog({
1380 id: "feedEditDlg",
1381 title: __("Edit Feed"),
1382 style: "width: 600px",
1383 execute: function() {
1384 if (this.validate()) {
1385 // console.log(dojo.objectToQuery(this.attr('value')));
1386
1387 notify_progress("Saving data...", true);
1388
1389 new Ajax.Request("backend.php", {
1390 parameters: dojo.objectToQuery(dialog.attr('value')),
1391 onComplete: function(transport) {
1392 dialog.hide();
1393 notify('');
1394 updateFeedList();
1395 }});
1396 }
1397 },
1398 href: query});
1399
1400 dialog.show();
1401 }
1402
1403 function feedBrowser() {
1404 var query = "backend.php?op=feeds&method=feedBrowser";
1405
1406 if (dijit.byId("feedAddDlg"))
1407 dijit.byId("feedAddDlg").hide();
1408
1409 if (dijit.byId("feedBrowserDlg"))
1410 dijit.byId("feedBrowserDlg").destroyRecursive();
1411
1412 var dialog = new dijit.Dialog({
1413 id: "feedBrowserDlg",
1414 title: __("More Feeds"),
1415 style: "width: 600px",
1416 getSelectedFeedIds: function () {
1417 var list = $$("#browseFeedList li[id*=FBROW]");
1418 var selected = new Array();
1419
1420 list.each(function (child) {
1421 var id = child.id.replace("FBROW-", "");
1422
1423 if (child.hasClassName('Selected')) {
1424 selected.push(id);
1425 }
1426 });
1427
1428 return selected;
1429 },
1430 getSelectedFeeds: function () {
1431 var list = $$("#browseFeedList li.Selected");
1432 var selected = new Array();
1433
1434 list.each(function (child) {
1435 var title = child.getElementsBySelector("span.fb_feedTitle")[0].innerHTML;
1436 var url = child.getElementsBySelector("a.fb_feedUrl")[0].href;
1437
1438 selected.push([title, url]);
1439
1440 });
1441
1442 return selected;
1443 },
1444
1445 subscribe: function () {
1446 var mode = this.attr('value').mode;
1447 var selected = [];
1448
1449 if (mode == "1")
1450 selected = this.getSelectedFeeds();
1451 else
1452 selected = this.getSelectedFeedIds();
1453
1454 if (selected.length > 0) {
1455 dijit.byId("feedBrowserDlg").hide();
1456
1457 notify_progress("Loading, please wait...", true);
1458
1459 // we use dojo.toJson instead of JSON.stringify because
1460 // it somehow escapes everything TWICE, at least in Chrome 9
1461
1462 var query = "?op=rpc&method=massSubscribe&payload=" +
1463 param_escape(dojo.toJson(selected)) + "&mode=" + param_escape(mode);
1464
1465 console.log(query);
1466
1467 new Ajax.Request("backend.php", {
1468 parameters: query,
1469 onComplete: function (transport) {
1470 notify('');
1471 updateFeedList();
1472 }
1473 });
1474
1475 } else {
1476 alert(__("No feeds are selected."));
1477 }
1478
1479 },
1480 update: function () {
1481 var query = dojo.objectToQuery(dialog.attr('value'));
1482
1483 Element.show('feed_browser_spinner');
1484
1485 new Ajax.Request("backend.php", {
1486 parameters: query,
1487 onComplete: function (transport) {
1488 notify('');
1489
1490 Element.hide('feed_browser_spinner');
1491
1492 var c = $("browseFeedList");
1493
1494 var reply = JSON.parse(transport.responseText);
1495
1496 var r = reply['content'];
1497 var mode = reply['mode'];
1498
1499 if (c && r) {
1500 c.innerHTML = r;
1501 }
1502
1503 dojo.parser.parse("browseFeedList");
1504
1505 if (mode == 2) {
1506 Element.show(dijit.byId('feed_archive_remove').domNode);
1507 } else {
1508 Element.hide(dijit.byId('feed_archive_remove').domNode);
1509 }
1510
1511 }
1512 });
1513 },
1514 removeFromArchive: function () {
1515 var selected = this.getSelectedFeedIds();
1516
1517 if (selected.length > 0) {
1518
1519 var pr = __("Remove selected feeds from the archive? Feeds with stored articles will not be removed.");
1520
1521 if (confirm(pr)) {
1522 Element.show('feed_browser_spinner');
1523
1524 var query = "?op=rpc&method=remarchive&ids=" +
1525 param_escape(selected.toString());
1526 ;
1527
1528 new Ajax.Request("backend.php", {
1529 parameters: query,
1530 onComplete: function (transport) {
1531 dialog.update();
1532 }
1533 });
1534 }
1535 }
1536 },
1537 execute: function () {
1538 if (this.validate()) {
1539 this.subscribe();
1540 }
1541 },
1542 href: query
1543 });
1544
1545 dialog.show();
1546 }
1547
1548 function showFeedsWithErrors() {
1549 var query = "backend.php?op=pref-feeds&method=feedsWithErrors";
1550
1551 if (dijit.byId("errorFeedsDlg"))
1552 dijit.byId("errorFeedsDlg").destroyRecursive();
1553
1554 dialog = new dijit.Dialog({
1555 id: "errorFeedsDlg",
1556 title: __("Feeds with update errors"),
1557 style: "width: 600px",
1558 getSelectedFeeds: function() {
1559 return getSelectedTableRowIds("prefErrorFeedList");
1560 },
1561 removeSelected: function() {
1562 var sel_rows = this.getSelectedFeeds();
1563
1564 console.log(sel_rows);
1565
1566 if (sel_rows.length > 0) {
1567 var ok = confirm(__("Remove selected feeds?"));
1568
1569 if (ok) {
1570 notify_progress("Removing selected feeds...", true);
1571
1572 var query = "?op=pref-feeds&method=remove&ids="+
1573 param_escape(sel_rows.toString());
1574
1575 new Ajax.Request("backend.php", {
1576 parameters: query,
1577 onComplete: function(transport) {
1578 notify('');
1579 dialog.hide();
1580 updateFeedList();
1581 } });
1582 }
1583
1584 } else {
1585 alert(__("No feeds are selected."));
1586 }
1587 },
1588 execute: function() {
1589 if (this.validate()) {
1590 }
1591 },
1592 href: query});
1593
1594 dialog.show();
1595 }
1596
1597 function get_timestamp() {
1598 var date = new Date();
1599 return Math.round(date.getTime() / 1000);
1600 }
1601
1602 function helpDialog(topic) {
1603 var query = "backend.php?op=backend&method=help&topic=" + param_escape(topic);
1604
1605 if (dijit.byId("helpDlg"))
1606 dijit.byId("helpDlg").destroyRecursive();
1607
1608 dialog = new dijit.Dialog({
1609 id: "helpDlg",
1610 title: __("Help"),
1611 style: "width: 600px",
1612 href: query,
1613 });
1614
1615 dialog.show();
1616 }
1617
1618 function htmlspecialchars_decode (string, quote_style) {
1619 // http://kevin.vanzonneveld.net
1620 // + original by: Mirek Slugen
1621 // + improved by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
1622 // + bugfixed by: Mateusz "loonquawl" Zalega
1623 // + input by: ReverseSyntax
1624 // + input by: Slawomir Kaniecki
1625 // + input by: Scott Cariss
1626 // + input by: Francois
1627 // + bugfixed by: Onno Marsman
1628 // + revised by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
1629 // + bugfixed by: Brett Zamir (http://brett-zamir.me)
1630 // + input by: Ratheous
1631 // + input by: Mailfaker (http://www.weedem.fr/)
1632 // + reimplemented by: Brett Zamir (http://brett-zamir.me)
1633 // + bugfixed by: Brett Zamir (http://brett-zamir.me)
1634 // * example 1: htmlspecialchars_decode("<p>this -&gt; &quot;</p>", 'ENT_NOQUOTES');
1635 // * returns 1: '<p>this -> &quot;</p>'
1636 // * example 2: htmlspecialchars_decode("&amp;quot;");
1637 // * returns 2: '&quot;'
1638 var optTemp = 0,
1639 i = 0,
1640 noquotes = false;
1641 if (typeof quote_style === 'undefined') {
1642 quote_style = 2;
1643 }
1644 string = string.toString().replace(/&lt;/g, '<').replace(/&gt;/g, '>');
1645 var OPTS = {
1646 'ENT_NOQUOTES': 0,
1647 'ENT_HTML_QUOTE_SINGLE': 1,
1648 'ENT_HTML_QUOTE_DOUBLE': 2,
1649 'ENT_COMPAT': 2,
1650 'ENT_QUOTES': 3,
1651 'ENT_IGNORE': 4
1652 };
1653 if (quote_style === 0) {
1654 noquotes = true;
1655 }
1656 if (typeof quote_style !== 'number') { // Allow for a single string or an array of string flags
1657 quote_style = [].concat(quote_style);
1658 for (i = 0; i < quote_style.length; i++) {
1659 // Resolve string input to bitwise e.g. 'PATHINFO_EXTENSION' becomes 4
1660 if (OPTS[quote_style[i]] === 0) {
1661 noquotes = true;
1662 } else if (OPTS[quote_style[i]]) {
1663 optTemp = optTemp | OPTS[quote_style[i]];
1664 }
1665 }
1666 quote_style = optTemp;
1667 }
1668 if (quote_style & OPTS.ENT_HTML_QUOTE_SINGLE) {
1669 string = string.replace(/&#0*39;/g, "'"); // PHP doesn't currently escape if more than one 0, but it should
1670 // string = string.replace(/&apos;|&#x0*27;/g, "'"); // This would also be useful here, but not a part of PHP
1671 }
1672 if (!noquotes) {
1673 string = string.replace(/&quot;/g, '"');
1674 }
1675 // Put this in last place to avoid escape being double-decoded
1676 string = string.replace(/&amp;/g, '&');
1677
1678 return string;
1679 }
1680
1681
1682 function label_to_feed_id(label) {
1683 return _label_base_index - 1 - Math.abs(label);
1684 }
1685
1686 function feed_to_label_id(feed) {
1687 return _label_base_index - 1 + Math.abs(feed);
1688 }
1689
1690 // http://stackoverflow.com/questions/6251937/how-to-get-selecteduser-highlighted-text-in-contenteditable-element-and-replac
1691
1692 function getSelectionText() {
1693 var text = "";
1694
1695 if (typeof window.getSelection != "undefined") {
1696 var sel = window.getSelection();
1697 if (sel.rangeCount) {
1698 var container = document.createElement("div");
1699 for (var i = 0, len = sel.rangeCount; i < len; ++i) {
1700 container.appendChild(sel.getRangeAt(i).cloneContents());
1701 }
1702 text = container.innerHTML;
1703 }
1704 } else if (typeof document.selection != "undefined") {
1705 if (document.selection.type == "Text") {
1706 text = document.selection.createRange().textText;
1707 }
1708 }
1709
1710 return text.stripTags();
1711 }
1712
1713 function openUrlPopup(url) {
1714 var w = window.open("");
1715
1716 w.opener = null;
1717 w.location = url;
1718 }
1719 function openArticlePopup(id) {
1720 var w = window.open("",
1721 "ttrss_article_popup",
1722 "height=900,width=900,resizable=yes,status=no,location=no,menubar=no,directories=no,scrollbars=yes,toolbar=no");
1723
1724 w.opener = null;
1725 w.location = "backend.php?op=article&method=view&mode=raw&html=1&zoom=1&id=" + id + "&csrf_token=" + getInitParam("csrf_token");
1726 }