// UrlFrame.js // Javascript Behaviour for the UrlFrame Control. // This control implement an iframe element that connects to the page properties. // The pageproperty "url" can be used // Copyright (c) by Matthias Hertel, http://www.mathertel.de // This work is licensed under a BSD style license. See http://www.mathertel.de/License.aspx // ----- // 12.08.2005 created by Matthias Hertel // 27.09.2005 PageProperty attribute added // 28.09.2005 internal timer added // 16.09.2006 context on event-methods is now set to the bound object. // 19.11.2007 using the OpenAjax hub instead of PageProperties // 18.12.2007 Simplifications and documentation. jcl.UrlFrameBehaviour = { // ----- Properties ----- // name of a event name that is used in the url pattern. eventname: "url", /// <summary>The local or complete event name that is used for publishing OpenAjax events.</summary> _eventvalue: "", // this is the url of the HTML iframe element containing placeholders for page properties. urlpattern: "about:blank", // this is the actual url of the HTML iframe (not normalized by HTML). _url: "", // this is the timer used to refresh the iframe. _timer: null, // ----- Methods ----- init: function () { if (this.eventname != null) { this.eventname = jcl.BuildFullEventname(this); OpenAjax.hub.subscribe(this.eventname, this._handleEvent, this); } // if }, // init // many page properties might be changed at ince so delay the url calculation a little bit. _handleEvent: function (eventName, eventData) { this._eventvalue = eventData; if (this._timer != null) window.clearTimeout(this._timer); this._timer = window.setTimeout(this.RefreshUrl.bind(this), 50); }, // _handleEvent // re-calculate the url for the iframe element RefreshUrl: function () { var url; var evn = jcl.LocalEventName(this.eventname); var idx = this.urlpattern.indexOf("[" + evn + "]"); this._timer = null; if (idx >= 0) { url = this.urlpattern.substr(0, idx) + this._eventvalue + this.urlpattern.substr(idx + evn.length + 2); if (this._url != url) { this.contentWindow.location.replace(url); // do not push onto history ! this._url = url; } // if } // if } // RefreshUrl }; // jcl.UrlFrameBehaviour
This page is part of the http://www.mathertel.de/ web site.
For updates and discussions see http://ajaxaspects.blogspot.com/.