Show
Ignore:
Timestamp:
09/24/08 17:23:11 (6 years ago)
Author:
zigorou
Message:

Add fx2, fx3 supports

Location:
lang/javascript/exdomstorage/trunk
Files:
6 modified

Legend:

Unmodified
Added
Removed
  • lang/javascript/exdomstorage/trunk/sample/index.html

    r19808 r19810  
    33  <head> 
    44    <title>DOM Storage Test for IE6, IE7</title> 
    5     <!--[if lt IE 8]> 
    65    <script type="text/javascript" src="../src/exdomstorage.js"></script> 
    7     <![endif]--> 
    86    <script type="text/javascript" src="sample.js"></script> 
    97  </head> 
  • lang/javascript/exdomstorage/trunk/sample/sample.js

    • Property svn:mime-type set to text/javascript
    r19802 r19810  
    5151} 
    5252 
    53 window.attachEvent("onload", function(evt) { 
     53// via http://d.hatena.ne.jp/amachang/20080517/1210991851 
     54function attach(elm, eventType, handler) { 
     55    if (elm.addEventListener) { 
     56        elm.addEventListener(eventType, handler, false); 
     57    } 
     58    else { 
     59        elm.attachEvent('on' + eventType, handler); 
     60    } 
     61} 
     62 
     63function detach(elm, eventType, handler) { 
     64    if (elm.removeEventListener) { 
     65        elm.removeEventListener(eventType, handler, false); 
     66    } 
     67    else { 
     68        elm.detachEvent('on' + eventType, handler); 
     69    } 
     70} 
     71 
     72attach(window, "load", function(evt) { 
    5473  dumpStorage("local"); 
    5574  dumpStorage("session"); 
    5675 
    57   /* 
    58   if (typeof localStorage.onstorage == "unknown") { 
    59         localStorage.onstorage = function() { dumpStorage("local"); }; 
    60         sessionStorage.onstorage = function() { dumpStorage("session"); }; 
    61   } 
    62   else { 
    63         document.attachEvent("onstorage", function(evt) { 
    64           if (evt.uri == "#session") { 
    65                 dumpStorage("session"); 
    66           } 
    67           else { 
    68                 dumpStorage("local"); 
    69           } 
    70         }); 
    71   } 
    72   */ 
    73  
    74   document.attachEvent("onstorage", function(evt) { 
     76  attach(document, "storage", function(evt) { 
    7577        if (evt.uri == "#session") { 
    7678          dumpStorage("session"); 
     
    8284 
    8385  var localStorageForm = document.getElementById("localStorageForm"); 
    84   localStorageForm.attachEvent("onsubmit", function(evt) { 
     86  attach(localStorageForm, "submit", function(evt) { 
    8587        var key = localStorageForm.elements["lkey"].value; 
    8688        var val = localStorageForm.elements["lvalue"].value; 
     
    9496 
    9597  var sessionStorageForm = document.getElementById("sessionStorageForm"); 
    96   sessionStorageForm.attachEvent("onsubmit", function(evt) { 
     98  attach(sessionStorageForm, "onsubmit", function(evt) { 
    9799        var key = sessionStorageForm.elements["skey"].value; 
    98100        var val = sessionStorageForm.elements["svalue"].value; 
     
    108110  var sessionStorageClear = document.getElementById("sessionStorageClear"); 
    109111 
    110   localStorageClear.attachEvent("onclick", function(evt) { 
     112  attach(localStorageClear, "click", function(evt) { 
    111113        localStorage.clear(); 
    112114  }); 
    113115 
    114   sessionStorageClear.attachEvent("onclick", function(evt) { 
     116  attach(sessionStorageClear, "click", function(evt) { 
    115117        sessionStorage.clear(); 
    116118  }); 
  • lang/javascript/exdomstorage/trunk/src/exdomstorage.htc

    • Property svn:mime-type set to text/x-component
  • lang/javascript/exdomstorage/trunk/src/exdomstorage.js

    • Property svn:mime-type set to text/javascript
    r19802 r19810  
    11(function() { 
    2    if (window["localStorage"] && window["sessionStorage"]) 
     2   if (window.localStorage && window.sessionStorage) 
    33         return; 
    44 
    5    with({ nodeSet: document.getElementsByTagName("script"), storages: ["localStorage", "sessionStorage"] }) { 
    6          var loader = nodeSet.item(nodeSet.length - 1); 
    7          var src = loader.getAttribute("src"); 
    8          var behavior_uri = src.replace(/\/\w+\.js$/, '/exdomstorage.htc'); 
     5   if (typeof window.ScriptEngine == "function" && window.ScriptEngine() == "JScript") { // for IE6, IE7 
     6         with({ nodeSet: document.getElementsByTagName("script"), storages: ["localStorage", "sessionStorage"] }) { 
     7           var loader = nodeSet.item(nodeSet.length - 1); 
     8           var src = loader.getAttribute("src"); 
     9           var behavior_uri = src.replace(/\/\w+\.js$/, '/exdomstorage.htc'); 
    910 
    10          for (var i in storages) with ({ storage: document.createElement('script'), name: storages[i] }) { 
    11            window[name] = storage; 
    12            loader.parentNode.appendChild(storage); 
    13            storage.addBehavior(behavior_uri + "#" + name); 
     11           for (var i in storages) with ({ storage: document.createElement('script'), name: storages[i] }) { 
     12                 window[name] = storage; 
     13                 loader.parentNode.appendChild(storage); 
     14                 storage.addBehavior(behavior_uri + "#" + name); 
     15           } 
    1416         } 
    1517   } 
     18   else if (window.globalStorage && !window.localStorage) { // for Fx2, Fx3 
     19         window.localStorage = window.globalStorage[location.hostname]; 
     20   } 
    1621})(); 
  • lang/javascript/exdomstorage/trunk/src/exdomstorage_impl.js

    • Property svn:mime-type set to text/javascript
  • lang/javascript/exdomstorage/trunk/src/json2.js

    • Property svn:mime-type set to text/javascript