PageRenderTime 32ms CodeModel.GetById 1ms app.highlight 25ms RepoModel.GetById 1ms app.codeStats 0ms

/aspnet_client/system_web/1_0_3705_6018/SmartNavIE5.js

http://github.com/khaneh/Orders
JavaScript | 205 lines | 178 code | 19 blank | 8 comment | 63 complexity | 9e31ea2046dc01d93b8d53dcb9ac80c3 MD5 | raw file
  1<!------------------------------------------------------------------------
  2//
  3//  Copyright 2000 Microsoft Corporation.  All Rights Reserved.
  4//
  5//  File:         SmartNavie5.js
  6//
  7//  Description:  this file implements a smart navigation mecanism for IE5.0
  8//
  9//----------------------------------------------------------------------->
 10
 11if (window.__smartNav == null &&  (window.parent.__smartNav == null
 12                || window.parent.frames["__hifSmartNav"] != window))
 13{
 14    var sn = new Object();
 15    window.__smartNav = sn;
 16    sn.hif = document.all("__hifSmartNav");
 17    sn.siHif = sn.hif.sourceIndex;
 18    sn.update = function()
 19    {
 20        var sn = window.__smartNav;
 21        if (sn.xmli.XMLDocument.readyState < 4 || sn.updated == true)
 22            return;
 23        sn.updated = true;
 24        try { fd = frames["__hifSmartNav"].document; } catch (e) {return;}
 25        var fdr = fd.getElementsByTagName("asp_smartnav_rdir");
 26        if (fdr.length > 0)
 27        {
 28            if (sn.sHif == null)
 29            {
 30                sn.sHif = document.createElement("IFRAME");
 31                sn.sHif.name = "__hifSmartNav";
 32                sn.sHif.style.display = "none";
 33            }
 34            try {window.location = fdr[0].url;} catch (e) {};
 35            return;
 36        }
 37
 38        var fdurl = fd.location.href;
 39        if (fdurl == "IEsmartnav1")
 40            return;
 41        var fdurlb = fdurl.split("?")[0];
 42        if (document.location.href.indexOf(fdurlb) < 0)
 43        {
 44            document.location.href=fdurl;
 45            return;
 46        }
 47
 48        var hdm = document.getElementsByTagName("head")[0];
 49        var hk = hdm.childNodes;
 50        for (var i = hk.length - 1; i>= 0; i--)
 51        {
 52            if (hk[i].tagName != "BASEFONT" || hk[i].innerHTML.length == 0)
 53                hdm.removeChild(hdm.childNodes[i]);
 54        }
 55        var kids = fd.getElementsByTagName("head")[0].childNodes;
 56        for (var i = 0; i < kids.length; i++)
 57        {
 58            var tn = kids[i].tagName;
 59            var k = document.createElement(tn);
 60            k.id = kids[i].id;
 61            switch(tn)
 62            {
 63            case "TITLE":
 64                k.innerText = kids[i].text;
 65                hdm.insertAdjacentElement("afterbegin", k);
 66                continue;
 67            case "BASEFONT" :
 68                if (kids[i].innerHTML.length > 0)
 69                    continue;
 70                k.mergeAttributes(kids[i]);
 71                break;
 72            default:
 73                var o = document.createElement("BODY");
 74                o.innerHTML = "<BODY>" + kids[i].outerHTML + "</BODY>";
 75                k = o.firstChild;
 76                k.mergeAttributes(kids[i]);
 77                break;
 78            }
 79            hdm.appendChild(k);
 80        }
 81
 82        var colSelect = document.body.getElementsByTagName("SELECT");
 83        for (var i = 0; i < colSelect.length; i ++)
 84            colSelect[i].removeNode(true);
 85
 86        var obody = document.body;
 87        sn.sHif = sn.hif;
 88        obody.insertAdjacentElement("beforeBegin", sn.hif);
 89        obody.innerHTML = fd.body.innerHTML;
 90        obody.clearAttributes();
 91        obody.id = fd.body.id;
 92        obody.mergeAttributes(fd.body);
 93        window.setTimeout(sn.restoreFocus, 0);
 94        sn.attachForm();
 95    };
 96
 97    window.__smartNav.restoreFocus = function()
 98    {
 99        var curAe = document.activeElement;
100        var sAeId = window.__smartNav.ae;
101        if (sAeId==null || curAe!=null && (curAe.id==sAeId||curAe.name==sAeId))
102            return;
103        var ae = document.all(sAeId);
104        if (ae == null) return;
105        try { ae.focus(); } catch(e){};
106    }
107
108    window.__smartNav.saveHistory = function()
109    {
110        if (window.__smartNav.sHif != null)
111        {
112            if (window.__smartNav.hif != null)
113                window.__smartNav.hif.parentElement.removeChild(window.__smartNav.hif);
114            document.all[window.__smartNav.siHif].insertAdjacentElement(
115                        "beforeBegin", window.__smartNav.sHif);
116        }
117    }
118
119    window.__smartNav.init = function()
120    {
121        try { if (window.event.returnValue == false) return;} catch(e) {}
122        var sn = window.__smartNav;
123        if (document.activeElement != null)
124        {
125            var ae = document.activeElement.id;
126            if (ae.length == 0)
127                ae = document.activeElement.name;
128            sn.ae = ae;
129        }
130        else
131            sn.ae = null;
132        if (document.selection.type != "None")
133            try {document.selection.empty();} catch (e) {}
134        var hif = sn.sHif;
135        try { if (hif) hif.parentElement.removeChild(hif);} catch(e){}
136        sn.hif = document.all["__hifSmartNav"];
137        if (sn.hif.tagName != "IFRAME")
138            sn.hif = window.__smartNav.hif[0];
139        sn.hifName = "__hifSmartNav" + (new Date()).getTime();
140        frames["__hifSmartNav"].name = sn.hifName;
141        sn.form.target = sn.hifName;
142        sn.updated = false;
143    };
144
145    window.__smartNav.submit = function()
146    {
147        window.__smartNav.init();
148        window.__smartNav.form._submit();
149    };
150
151    window.__smartNav.attachForm = function()
152    {
153        var cf = document.forms;
154        var sn = window.__smartNav;
155        for (var i=0; i<cf.length; i++)
156        {
157            if (cf[i].__smartNavEnabled != null)
158            {
159                sn.form = cf[i];
160                break;
161            }
162        }
163
164        if (sn.form == null)
165            return false;
166
167        var sft = sn.form.target;
168        if (sft.length != 0 && sft != "__hifSmartNav") return false;
169
170        var sfc = sn.form.action.split("?")[0];
171        var url = window.location.href.split("?")[0];
172        if (url.lastIndexOf(sfc) + sfc.length != url.length) return false;
173        if (sn.form.__formAttached == true) return true;
174
175        sn.form.__formAttached = true;
176        sn.form.attachEvent("onsubmit", sn.init);
177        sn.form._submit = sn.form.submit;
178        sn.form.submit = sn.submit;
179        return true;
180    };
181
182    sn.sFn = "if (document.readyState != 'complete')"
183               + "return;"
184               + "var wpd = window.parent.document;"
185               + "var xmli = wpd.createElement('XML');"
186               + "wpd.body.appendChild(xmli);"
187               + "window.parent.__smartNav.xmli = xmli;"
188               + "xmli.onreadystatechange=window.parent.__smartNav.update;"
189               + "xmli.src = '';";
190
191    var rc = sn.attachForm();
192    if (rc)
193        window.attachEvent("onbeforeunload", sn.saveHistory);
194    else
195        window.__smartNav = null;
196}
197
198
199if (window.parent != window && window.parent.__smartNav != null
200    && window.parent.frames["__hifSmartNav"] == window)
201{
202    var f = new Function(window.parent.__smartNav.sFn);
203    document.attachEvent("onreadystatechange", f);
204}
205