]> git.wh0rd.org - tt-rss.git/blobdiff - functions.js
getMainContext() and related JS-stuff
[tt-rss.git] / functions.js
index 817946c397737ca2153b90f5cd1b2ce823352258..384f34827c8b20e12c90f6db297ca1c400e6d79b 100644 (file)
@@ -80,12 +80,14 @@ function delay(gap) {
 var notify_hide_timerid = false;
 var notify_last_doc = false;
 
+var notify_effect = false;
+
 function hide_notify() {
        if (notify_last_doc) {
                var n = notify_last_doc.getElementById("notify");               
                if (browser_has_opacity()) {
                        if (notify_opacity >= 0) {
-                               notify_opacity = notify_opacity - 0.2;
+                               notify_opacity = notify_opacity - 0.1;
                                n.style.opacity = notify_opacity;
                                notify_hide_timerid = window.setTimeout("hide_notify()", 20);   
                        } else {
@@ -105,8 +107,18 @@ function notify_real(msg, doc, no_hide, is_err) {
 
        if (!n || !nb) return;
 
+       if (notify_hide_timerid) {
+               window.clearTimeout(notify_hide_timerid);
+       }
+
+       notify_last_doc = doc;
+       notify_opacity = 1;
+
        if (msg == "") {
-               n.style.display = "none";
+               if (n.style.display == "block") {
+                       notify_hide_timerid = window.setTimeout("hide_notify()", 0);
+               }
+               return;
        } else {
                n.style.display = "block";
        }
@@ -123,13 +135,6 @@ function notify_real(msg, doc, no_hide, is_err) {
 
        nb.innerHTML = msg;
 
-       if (notify_hide_timerid) {
-               window.clearTimeout(notify_hide_timerid);
-       }
-
-       notify_last_doc = doc;
-       notify_opacity = 1;
-
        if (!no_hide) {
                notify_hide_timerid = window.setTimeout("hide_notify()", 3000);
        }
@@ -359,6 +364,11 @@ function disableContainerChildren(id, disable, doc) {
 
        var container = doc.getElementById(id);
 
+       if (!container) {
+               //alert("disableContainerChildren: element " + id + " not found");
+               return;
+       }
+
        for (var i = 0; i < container.childNodes.length; i++) {
                var child = container.childNodes[i];
 
@@ -401,29 +411,15 @@ function setActiveFeedId(id) {
        return setCookie("ttrss_vf_actfeed", id);
 }
 
-var xmlhttp_rpc = false;
+var xmlhttp_rpc = Ajax.getTransport();
 
-/*@cc_on @*/
-/*@if (@_jscript_version >= 5)
-// JScript gives us Conditional compilation, we can cope with old IE versions.
-// and security blocked creation of the objects.
-try {
-       xmlhttp_rpc = new ActiveXObject("Msxml2.XMLHTTP");
-} catch (e) {
+function parse_counters(reply, scheduled_call) {
        try {
-               xmlhttp_rpc = new ActiveXObject("Microsoft.XMLHTTP");
-       } catch (E) {
-               xmlhttp_rpc = false;
-       }
-}
-@end @*/
+               var f_document = getMainContext().frames["feeds-frame"].document;
+               var title_obj = getMainContext();
 
-if (!xmlhttp_rpc && typeof XMLHttpRequest!='undefined') {
-       xmlhttp_rpc = new XMLHttpRequest();
-}
+               debug("F_DOC: " + f_document + ", T_OBJ: " + title_obj);
 
-function parse_counters(reply, f_document, title_obj, scheduled_call) {
-       try {
                for (var l = 0; l < reply.childNodes.length; l++) {
                        if (!reply.childNodes[l] ||
                                typeof(reply.childNodes[l].getAttribute) == "undefined") {
@@ -507,9 +503,6 @@ function parse_counters(reply, f_document, title_obj, scheduled_call) {
        }
 }
 
-// this one is called from feedlist context
-// thus title_obj passed to parse_counters is parent (e.g. main ttrss window)
-
 function all_counters_callback() {
        if (xmlhttp_rpc.readyState == 4) {
                try {
@@ -524,9 +517,9 @@ function all_counters_callback() {
                        }
 
                        var reply = xmlhttp_rpc.responseXML.firstChild;
-                       var f_document = parent.frames["feeds-frame"].document;
+//                     var f_document = parent.frames["feeds-frame"].document;
 
-                       parse_counters(reply, f_document, parent);
+                       parse_counters(reply);
        
                } catch (e) {
                        exception_error("all_counters_callback", e);
@@ -934,28 +927,7 @@ function leading_zero(p) {
        return s;
 }
 
-function center_element(e) {
-
-       try {
-               var c_width = document.body.clientWidth;
-               var c_height = document.body.clientHeight;
-       
-               var c_scroll = document.body.scrollTop;
-       
-               var e_width = e.clientWidth;
-               var e_height = e.clientHeight;
-       
-               var set_y = (c_height / 2) + c_scroll - (e_height / 2);
-               var set_x = (c_width / 2) - (e_width / 2);
-       
-               e.style.top = set_y + "px";
-               e.style.left = set_x + "px";
-       } catch (e) {
-               exception_error("center_element", e);
-       }
-}
-
-function closeInfoBox() {
+function closeInfoBox(cleanup) {
        var box = document.getElementById('infoBox');
        var shadow = document.getElementById('infoBoxShadow');
 
@@ -965,7 +937,10 @@ function closeInfoBox() {
                box.style.display = "none";
        }
 
+       if (cleanup) box.innerHTML = "&nbsp;";
+
        enableHotkeys();
+
 }
 
 
@@ -989,13 +964,15 @@ function displayDlg(id, param) {
 
 function infobox_submit_callback() {
        if (xmlhttp.readyState == 4) {
-               notify(xmlhttp.responseText);
                closeInfoBox();
 
                // called from prefs, reload tab
                if (active_tab) {
                        selectTab(active_tab, false);
                }
+
+               notify(xmlhttp.responseText);
+
        } 
 }
 
@@ -1021,30 +998,13 @@ function qaddFilter() {
                return
        }
 
-       var regexp = document.getElementById("fadd_regexp");
-       var match = document.getElementById("fadd_match");
-       var feed = document.getElementById("fadd_feed");
-       var action = document.getElementById("fadd_action");
-
-       if (regexp.value.length == 0) {
-               alert("Missing filter expression.");
-       } else {
-               notify("Adding filter...");
-
-               var v_match = match[match.selectedIndex].text;
-               var feed_id = feed[feed.selectedIndex].id;
-               var action_id = action[action.selectedIndex].id;
+       var query = Form.serialize("filter_add_form");
 
-               xmlhttp.open("GET", "backend.php?op=pref-filters&quiet=1&subop=add&regexp=" +
-                       param_escape(regexp.value) + "&match=" + v_match +
-                       "&fid=" + param_escape(feed_id) + "&aid=" + param_escape(action_id), true);
-                       
-               xmlhttp.onreadystatechange=infobox_submit_callback;
-               xmlhttp.send(null);
-
-               regexp.value = "";
-       }
+       xmlhttp.open("GET", "backend.php?" + query, true);
+       xmlhttp.onreadystatechange=infobox_submit_callback;
+       xmlhttp.send(null);
 
+       return true;
 }
 
 function toggleSubmitNotEmpty(e, submit_id) {
@@ -1058,3 +1018,66 @@ function toggleSubmitNotEmpty(e, submit_id) {
 function isValidURL(s) {
        return s.match("http://") != null || s.match("https://") != null;
 }
+
+function qafAdd() {
+
+       if (!xmlhttp_ready(xmlhttp)) {
+               printLockingError();
+               return
+       }
+
+       notify("Adding feed...");
+
+       closeInfoBox();
+
+       var feeds_doc = window.frames["feeds-frame"].document;
+
+       feeds_doc.location.href = "backend.php?op=error&msg=Loading,%20please wait...";
+       
+       var query = Form.serialize("feed_add_form");
+       
+       xmlhttp.open("GET", "backend.php?" + query, true);
+       xmlhttp.onreadystatechange=dlg_frefresh_callback;
+       xmlhttp.send(null);
+}
+
+function filterCR(e)
+{
+     var key;
+
+     if(window.event)
+          key = window.event.keyCode;     //IE
+     else
+          key = e.which;     //firefox
+
+     if(key == 13)
+          return false;
+     else
+          return true;
+}
+
+function getMainContext() {
+       if (parent.window != window) {
+               return parent.window;
+       } else {
+               return this.window;
+       }
+}
+
+function debug(msg) {
+       var ctx = getMainContext();
+
+       var c = ctx.document.getElementById('debug_output');
+       if (c && c.style.display == "block") {
+               while (c.lastChild != 'undefined' && c.childNodes.length > 20) {
+                       c.removeChild(c.lastChild);
+               }
+       
+               var d = new Date();
+               var ts = leading_zero(d.getHours()) + ":" + leading_zero(d.getMinutes()) +
+                       ":" + leading_zero(d.getSeconds());
+               c.innerHTML = "<li>[" + ts + "] " + msg + "</li>" + c.innerHTML;
+       }
+}
+
+