var CMSRegistry = Class.create(); /** * CMSRegistry is a class to register other objects and values, so they can be accessed in a general way * * @since Wed May 23 2007 * @author: Giso Stallenberg **/ CMSRegistry.prototype = { /** * initialize * * Initialize a new CMSRegistry * * @access public * @since Wed May 23 2007 * @param CMS cms * @return void **/ initialize: function(cms) { this.cms = cms; this.registry = {}; }, /** * set * * Set a new value in the registry * * @access public * @since Wed May 23 2007 * @param string name * @param mixed value * @return void **/ set: function(name, value) { this.registry[name] = value; }, /** * get * * Get a value from the registry, if the value isn't in the registry it tries to create a new object, if this fails throws an error * * @access public * @since Wed May 23 2007 * @param string name * @return mixed **/ get: function(name) { if (typeof this.registry[name] != "undefined") { return this.registry[name]; } try { var theName = name; var object = new window[theName.capitalize() ]; } catch (e) {} if (typeof(object) == "object") { this.set(name, object); return object; } else { throw new Error("Trying to get a value for an unknown item: " + name + "\nMake sure the value is set first."); } } } var CMS = Class.create(); /** * CMS is holds some common functions the windmill CMS javascript classes can use * * @since Fri May 04 2007 * @author: Ron Rademaker **/ CMS.prototype = { /** * initialize * * Initialize a new CMS * * @access public * @since Fri May 04 2007 * @return void **/ initialize: function() { this.curX = 0; this.curY = 0; this.registry = new CMSRegistry(this); }, /** * warn * * Substitute for javascript standard alert function * * @since Fri May 04 2007 * @access public * @param string warning * @return void **/ warn: function(warning) { this._addModalFrame(); var warnDiv = this._createModalDiv("__warndiv"); warnDiv.innerHTML = "

Windmill CMS

" + warning + "

"; document.body.appendChild(warnDiv); this.curwarn = new Draggable("__warndiv", {handle: "__warndiv_dragbar", zindex: 10000}); }, /** * _createModalDiv * * Create a div suitable for modal showing * * @since Thu May 10 2007 * @access private * @param string id * @return void **/ _createModalDiv: function(id) { var modalDiv = document.createElement("div"); modalDiv.id = id; modalDiv.className = "pos_editor stl_editor pos_modaldiv stl_modaldiv"; modalDiv.style.left = (window.viewportDimensions.width / 2) - 198 + "px"; if (window.scrollY) { modalDiv.style.top = window.scrollY + 100 + "px"; } else { modalDiv.style.top = document.documentElement.scrollTop + 100 + "px"; } return modalDiv; }, /** * _addModalFrame * * Adds an iframe masking everything to create a modal popup * * @since Thu May 10 2007 * @access private * @return void **/ _addModalFrame: function() { var modalFrame = document.createElement("iframe"); modalFrame.src = "/lib/plugin/cms/var/blank.html"; modalFrame.id = "__modalFrame"; modalFrame.className = "pos_modal stl_modal"; modalFrame.style.width = window.viewportDimensions.width - 18 + "px"; // -18 = scrollbar modalFrame.style.height = document.body.clientHeight + "px"; document.body.appendChild(modalFrame); }, /** * hideWarning * * Hides the current warning * * @since Thu May 10 2007 * @access public * @return void **/ hideWarning: function() { document.getElementById("__warndiv").parentNode.removeChild(document.getElementById("__warndiv") ); document.getElementById("__modalFrame").parentNode.removeChild(document.getElementById("__modalFrame") ); }, /** * hideAsk * * Hides the current confirm * * @since Thu May 10 2007 * @access public * @return void **/ hideAsk: function() { document.getElementById("__askdiv").parentNode.removeChild(document.getElementById("__askdiv") ); document.getElementById("__modalFrame").parentNode.removeChild(document.getElementById("__modalFrame") ); }, /** * ask * * Replacement for javascript confirm * * @since Fri May 04 2007 * @access public * @param string question * @param array options * @return void **/ ask: function(question, options) { this._addModalFrame(); var askDiv = this._createModalDiv("__askdiv"); askDiv.innerHTML = "

Windmill CMS

" + question + "

"; askDiv.innerHTML += "
"; for (var i = 0; i < options.length; i++) { askDiv.innerHTML += "
"; } askDiv.innerHTML += "
"; document.body.appendChild(askDiv); this.curask = new Draggable("__askdiv", {handle: "__askdiv_dragbar", zindex: 10000}); }, /** * showSaving * * Shows a saving div * * @since Fri May 04 2007 * @access public * @param string id * @return void **/ showSaving: function(id) { document.getElementById(id).style.display = "block"; }, /** * hideSaving * * Hides a saving div * * @since Fri May 04 2007 * @access public * @param string id * @return void **/ hideSaving: function(id) { document.getElementById(id).style.display = "none"; }, /** * showEditor * * Shows an editor div * * @since Fri May 04 2007 * @access public * @param string id * @return void **/ showEditor: function(id) { this.hideEditor(id); $(id).style.left = this.curX + "px"; $(id).style.top = this.curY + "px"; if ($(id).clientWidth + this.curX > this._getScreenWidth() ) { $(id).style.left = this._getScreenWidth() - $(id).clientWidth - 50 + "px"; } Wmcms.updateShimFrame(id); }, /** * updateShimFrame * * Locates and resizes the Shim Iframe * * @since Tue May 08 2007 * @access public * @param string id * @return void **/ updateShimFrame: function(id) { if ($(id).style.left != "-1000px" && $(id + "_shim") ) { $(id + "_shim").style.width = $(id).clientWidth + "px"; $(id + "_shim").style.height = $(id).clientHeight + "px"; $(id + "_shim").style.display = "block"; $(id + "_shim").style.zIndex = -1;// $(id).style.zIndex - 1; setTimeout("Wmcms.updateShimFrame(\"" + id + "\");", 250); } }, /** * getContent * * Gets the content of an element (without stuff like &) * * @since Tue May 08 2007 * @access public * @param string id * @return string **/ getContent: function(id) { if ($(id).textContent) { return $(id).textContent; } else { return document.getElementById(id).innerHTML.replace("&", "&"); } }, /** * _getScreenWidth * * Retrieves the horizontal viewport dimension * * @since Tue May 08 2007 * @access private * @return integer **/ _getScreenWidth: function() { return window.viewportDimensions.width; }, /** * hideEditor * * Hides an editor div * * @since Fri May 04 2007 * @access public * @param string id * @return void **/ hideEditor: function(id) { document.getElementById(id).style.left = "-1000px"; if ($(id + "_shim") ) { document.getElementById(id + "_shim").style.display = "none"; document.getElementById(id + "_shim").style.left = "0px"; document.getElementById(id + "_shim").style.top = "0px"; document.getElementById(id + "_shim").style.zIndex = 0; } }, /** * clickObserver * * Registers x and y location of browser * * @since Fri May 04 2007 * @access public * @param Event event * @return void **/ clickObserver: function(event) { Wmcms.curX = event.clientX; if (window.scrollY) { Wmcms.curY = event.clientY + window.scrollY; } else if (document.documentElement && document.documentElement.scrollTop) { Wmcms.curY = event.clientY + document.documentElement.scrollTop; } else { Wmcms.curY = event.clientY; // Required because that random sequence of bits that sometimes acts like a browser doesn't support a scrollTop of 0 (really, it won't create scrollTop until you have scolled) } }, /** * getObject * * Tries to find out which object exists, the first found is returned * * @since Fri May 25 2007 * @access public * @param string name, string name, ... * @return function **/ getObject: function() { var objName = $A(arguments).find(function(name){ return (typeof(window[name.capitalize() ] ) == "function"); } ); if (typeof(objName) == "undefined") { throw new Error("At least one of the given objectnames should exist as instatiable var"); } return window[objName.capitalize() ]; }, /** * setTinyMCEUpdateHandler * * Sets the tinyMCEUpdateHandler function * * @since Fri Jul 6 2007 * @access public * @param function func * @return void **/ setTinyMCEUpdateHandler : function(func) { this._tinyMCEUpdateHandler = func; }, /** * tinyMCEUpdate * * function to be called on a tinyMCEUpdate (the onchange_callback) * * @since Fri Jul 6 2007 * @access public * @param tinyMCE tinyInstance * @return void **/ tinyMCEUpdate : function(tinyInstance) { if (typeof(this._tinyMCEUpdateHandler) == "function") { this._tinyMCEUpdateHandler(tinyInstance); } } } var Wmcms = new CMS(); Event.observe(document, "click", Wmcms.clickObserver);