]> git.wh0rd.org - tt-rss.git/blobdiff - js/functions.js
add a link to headlines-spacer to open next unread feed
[tt-rss.git] / js / functions.js
index 8691c1ee5d29b8a75c4303aff90df9c89b40c77e..9915e6808542c57f64be2904afec4be69247e686 100644 (file)
@@ -44,11 +44,8 @@ function exception_error(location, e, ext_info) {
 
        try {
 
-               if (ext_info) {
-                       if (ext_info.responseText) {
-                               ext_info = ext_info.responseText;
-                       }
-               }
+               if (ext_info)
+                       ext_info = JSON.stringify(ext_info);
 
                try {
                        new Ajax.Request("backend.php", {
@@ -104,13 +101,15 @@ function exception_error(location, e, ext_info) {
                        title: "Unhandled exception",
                        style: "width: 600px",
                        report: function() {
-                               if (confirm(__("Are you sure to report this exception to tt-rss.org? The report will include your browser information. Your IP would be saved in the database."))) {
+                               if (confirm(__("Are you sure to report this exception to tt-rss.org? The report will include information about your web browser and tt-rss configuration. Your IP will be saved in the database."))) {
 
                                        document.forms['exceptionForm'].params.value = $H({
                                                browserName: navigator.appName,
                                                browserVersion: navigator.appVersion,
                                                browserPlatform: navigator.platform,
                                                browserCookies: navigator.cookieEnabled,
+                                               ttrssVersion: __ttrss_version,
+                                               initParams: JSON.stringify(init_params),
                                        }).toQueryString();
 
                                        document.forms['exceptionForm'].submit();
@@ -205,6 +204,7 @@ function notify_real(msg, no_hide, n_type) {
                return;
        } else {
                Element.show(n);
+               new Effect.Highlight(n);
        }
 
        /* types:
@@ -226,13 +226,13 @@ function notify_real(msg, no_hide, n_type) {
                no_hide = true;
        } else if (n_type == 3) {
                n.className = "notify error";
-               msg = "<span><img src='images/sign_excl.svg'></span>" + msg;
+               msg = "<span><img src='images/alert.png'></span>" + msg;
        } else if (n_type == 4) {
                n.className = "notify info";
-               msg = "<span><img src='images/sign_info.svg'></span>" + msg;
+               msg = "<span><img src='images/information.png'></span>" + msg;
        }
 
-       msg += " <span><img src=\"images/close_notify.svg\" class=\"close\" title=\"" +
+       msg += " <span><img src=\"images/cross.png\" class=\"close\" title=\"" +
                __("Click to close") + "\" onclick=\"notify('')\"></span>";
 
 //     msg = "<img src='images/live_com_loading.gif'> " + msg;
@@ -829,7 +829,14 @@ function quickAddFeed() {
                                                onComplete: function(transport) {
                                                        try {
 
-                                                               var reply = JSON.parse(transport.responseText);
+                                                               try {
+                                                                       var reply = JSON.parse(transport.responseText);
+                                                               } catch (e) {
+                                                                       Element.hide("feed_add_spinner");
+                                                                       alert(__("Failed to parse output. This can indicate server timeout and/or network issues. Backend output was logged to browser console."));
+                                                                       console.log('quickAddFeed, backend returned:' + transport.responseText);
+                                                                       return;
+                                                               }
 
                                                                var rc = reply['result'];
 
@@ -854,6 +861,8 @@ function quickAddFeed() {
                                                                case 4:
                                                                        feeds = rc['feeds'];
 
+                                                                       Element.show("fadd_multiple_notify");
+
                                                                        var select = dijit.byId("feedDlg_feedContainerSelect");
 
                                                                        while (select.getOptions().length > 0)
@@ -1148,33 +1157,48 @@ function quickAddFilter() {
                        href: query});
 
                if (!inPreferences()) {
+                       var selectedText = getSelectionText();
+
                        var lh = dojo.connect(dialog, "onLoad", function(){
                                dojo.disconnect(lh);
 
-                               var query = "op=rpc&method=getlinktitlebyid&id=" + getActiveArticleId();
+                               if (selectedText != "") {
 
-                               new Ajax.Request("backend.php", {
-                               parameters: query,
-                               onComplete: function(transport) {
-                                       var reply = JSON.parse(transport.responseText);
+                                       var feed_id = activeFeedIsCat() ? 'CAT:' + parseInt(getActiveFeedId()) :
+                                               getActiveFeedId();
 
-                                       var title = false;
+                                       var rule = { reg_exp: selectedText, feed_id: feed_id, filter_type: 1 };
 
-                                       if (reply && reply) title = reply.title;
+                                       addFilterRule(null, dojo.toJson(rule));
 
-                                       if (title || getActiveFeedId() || activeFeedIsCat()) {
+                               } else {
+
+                                       var query = "op=rpc&method=getlinktitlebyid&id=" + getActiveArticleId();
 
-                                               console.log(title + " " + getActiveFeedId());
+                                       new Ajax.Request("backend.php", {
+                                       parameters: query,
+                                       onComplete: function(transport) {
+                                               var reply = JSON.parse(transport.responseText);
 
-                                               var feed_id = activeFeedIsCat() ? 'CAT:' + parseInt(getActiveFeedId()) :
-                                                       getActiveFeedId();
+                                               var title = false;
 
-                                               var rule = { reg_exp: title, feed_id: feed_id, filter_type: 1 };
+                                               if (reply && reply) title = reply.title;
 
-                                               addFilterRule(null, dojo.toJson(rule));
-                                       }
+                                               if (title || getActiveFeedId() || activeFeedIsCat()) {
 
-                               } });
+                                                       console.log(title + " " + getActiveFeedId());
+
+                                                       var feed_id = activeFeedIsCat() ? 'CAT:' + parseInt(getActiveFeedId()) :
+                                                               getActiveFeedId();
+
+                                                       var rule = { reg_exp: title, feed_id: feed_id, filter_type: 1 };
+
+                                                       addFilterRule(null, dojo.toJson(rule));
+                                               }
+
+                                       } });
+
+                               }
 
                        });
                }
@@ -1270,10 +1294,8 @@ function backend_sanity_check_callback(transport) {
                        console.log('reading init-params...');
 
                        for (k in params) {
-                               var v = params[k];
-                               console.log("IP: " + k + " => " + v);
-
-                               if (k == "label_base_index") _label_base_index = parseInt(v);
+                               console.log("IP: " + k + " => " + JSON.stringify(params[k]));
+                               if (k == "label_base_index") _label_base_index = parseInt(params[k]);
                        }
 
                        init_params = params;
@@ -1934,3 +1956,25 @@ function feed_to_label_id(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();
+}