4 İşlemeler 19668620d6 ... f0ff9548ad

Yazar SHA1 Mesaj Tarih
  Mathieu Lirzin f0ff9548ad iframe: Replace 'load_iframe' with 'load_page' 7 yıl önce
  Mathieu Lirzin 8b6d06063c reducers: Make CURRENT_URL handler more readable 7 yıl önce
  Mathieu Lirzin fdebd75dfd actions: Remove INIT 7 yıl önce
  Mathieu Lirzin 9e25fe2f96 iframe: Reverse if/else conditional clauses in 'Pages.load_iframe' 7 yıl önce
3 değiştirilmiş dosya ile 46 ekleme ve 48 silme
  1. 0 2
      js/src/actions.js
  2. 42 41
      js/src/iframe.js
  3. 4 5
      js/src/reducers.js

+ 0 - 2
js/src/actions.js

@@ -16,8 +16,6 @@
    You should have received a copy of the GNU General Public License
    along with GNU Texinfo.  If not, see <http://www.gnu.org/licenses/>.  */
 
-export const INIT = "init";
-
 export const SIDEBAR_LOADED = "sidebar-ready";
 
 export const CURRENT_URL = "current-url";

+ 42 - 41
js/src/iframe.js

@@ -69,46 +69,6 @@ Pages
       }
   }
 
-  static load_iframe (linkid)
-  {
-    let path = window.location.pathname + window.location.search;
-
-    if (linkid === config.INDEX_ID)
-      {
-        window.history.pushState ("", document.title, path);
-        return;
-      }
-
-    let [pageid, hash] = linkid_split (linkid);
-    let div = document.getElementById (pageid);
-    if (!div)
-      {
-        let msg = "no iframe container correspond to identifier: " + pageid;
-        throw new ReferenceError (msg);
-      }
-
-    path = path.replace (/#.*/, "") + "#" + linkid;
-    let url = pageid + ".xhtml" + hash;
-
-    /* Select contained iframe or create it if necessary.  */
-    let iframe = div.querySelector ("iframe");
-    if (iframe === null)
-      {
-        iframe = document.createElement ("iframe");
-        iframe.setAttribute ("class", "node");
-        iframe.setAttribute ("name", path);
-        iframe.setAttribute ("src", url);
-        div.appendChild (iframe);
-      }
-    else
-      {
-        let msg = { message_kind: "scroll-to", hash };
-        iframe.contentWindow.postMessage (msg, "*");
-      }
-
-    window.history.pushState ("", document.title, path);
-  }
-
   render (state)
   {
     let new_linkids = Object.keys (state.loaded_nodes)
@@ -124,7 +84,7 @@ Pages
         let div = document.getElementById (pageid);
         if (!div)
           throw new Error ("no div with id: " + pageid);
-        Pages.load_iframe (state.current);
+        load_page (state.current);
         div.removeAttribute ("hidden");
         this.prev_id = state.current;
         this.prev_div = div;
@@ -132,6 +92,47 @@ Pages
   }
 }
 
+function
+load_page (linkid)
+{
+  let path = window.location.pathname + window.location.search;
+
+  if (linkid === config.INDEX_ID)
+    {
+      window.history.pushState ("", document.title, path);
+      return;
+    }
+
+  let [pageid, hash] = linkid_split (linkid);
+  let div = document.getElementById (pageid);
+  if (!div)
+    {
+      let msg = "no iframe container correspond to identifier: " + pageid;
+      throw new ReferenceError (msg);
+    }
+
+  path = path.replace (/#.*/, "") + "#" + linkid;
+  let url = pageid + ".xhtml" + hash;
+
+  /* Select contained iframe or create it if necessary.  */
+  let iframe = div.querySelector ("iframe");
+  if (iframe)
+    {
+      let msg = { message_kind: "scroll-to", hash };
+      iframe.contentWindow.postMessage (msg, "*");
+    }
+  else
+    {
+      iframe = document.createElement ("iframe");
+      iframe.setAttribute ("class", "node");
+      iframe.setAttribute ("name", path);
+      iframe.setAttribute ("src", url);
+      div.appendChild (iframe);
+    }
+
+  window.history.pushState ("", document.title, path);
+}
+
 /*-----------------------------------------
 | Event handlers for the iframe context.  |
 `----------------------------------------*/

+ 4 - 5
js/src/reducers.js

@@ -20,7 +20,6 @@ import {
   CACHE_LINKS,
   CURRENT_URL,
   HIDE_COMPONENT,
-  INIT,
   NAVIGATE,
   SHOW_COMPONENT,
   SIDEBAR_LOADED
@@ -31,8 +30,6 @@ global_reducer (state, action)
 {
   switch (action.type)
     {
-    case INIT:
-      return Object.assign ({}, state, { action });
     case SIDEBAR_LOADED:
       return Object.assign ({}, state, { sidebar_loaded: true, action });
     case CACHE_LINKS:
@@ -51,11 +48,13 @@ global_reducer (state, action)
       }
     case CURRENT_URL:
       {
+        let res = Object.assign ({}, state, { action });
         let url = (action.pointer) ?
             state.loaded_nodes[action.pointer] : action.url;
-        let res = Object.assign ({}, state, { current: url, action });
-        res.text_input_visible = false;
+
+        res.current = url;
         res.loaded_nodes[url] = res.loaded_nodes[url] || {};
+        res.text_input_visible = false;
         return res;
       }
     case NAVIGATE: