/* RSence * Copyright 2006 Riassence Inc. * http://riassence.com/ * * You should have received a copy of the GNU General Public License along * with this software package. If not, contact licensing@riassence.com */ /** The default path where to look for themes. **/ var//RSence.Foundation HDefaultThemePath = '/H/themes'; /** Name of the default theme. **/ var//RSence.Foundation HDefaultThemeName = 'default'; /** List of themes without component-specific theme files. **/ var//RSence.Foundation HNoComponentCSS = []; /** List of themes without a common.css file to load. **/ var//RSence.Foundation HNoCommonCSS = []; /** List of IE6-savvy themes. **/ var//RSence.Foundation HThemeHasIE6GifsInsteadOfPng = ['default']; /*** = Description ** A single instance class. ** The theme manager knows the name of the currently loaded theme and handles ** the loading of theme specific markup snippets and style declarations. ** ** = Instance variables ** +themePath+:: Default root path of the themes path, should contain ** at least the default theme. ** +currentTheme+:: The name of the theme currently in use. Initially the ** default unnamed theme is used. ** ***/ var//RSence.Foundation HThemeManager = HClass.extend({ constructor: null, init: function(){ this.themePath = HDefaultThemePath; this._tmplCache = {}; this._cssCache = {}; this.currentTheme = HDefaultThemeName; }, setThemePath: function( _path ){ this.themePath = _path; }, // Error messages, should be refined. _errTemplateNotFound: function( _url ) { console.log( "ERROR: Template Not Found: '" + _url + "' "); }, _errTemplateFailure: function( _url ) { console.log( "ERROR: Template Failure: '" + _url + "' "); }, _errTemplateException: function( _url ) { console.log( "ERROR: Template Exception: '" + _url + "' "); }, /** = Description * Loads a template file and returns its contents. * If errors occurred, calls the error management functions. * * = Parameters * +_url+:: A valid local file path or http url pointing to the * resource to load. * +_contentType+:: An optional parameter, specifies the content type wanted, * defaults to text/html. * * = Returns * The contents of the path. **/ fetch: function( _url, _contentType, _callBack, _async ) { var _callBackFun; if( !_contentType ){ _contentType = 'text/html; charset=UTF-8'; } if(_async){ _callBackFun = function( resp ){ _callBack( resp.X.responseText ); }; } else{ // console.log('WARNING: Fetching synchronously using HThemeManager is not recommended. Use pre-packaged themes instead.'); var _respText; _callBackFun = function( resp ){ _respText = resp.X.responseText; }; } COMM.request( _url, { onSuccess: _callBackFun, on404: function(resp){ HThemeManager._errTemplateNotFound( resp.url ); }, onFailure: function(resp){ HThemeManager._errTemplateFailure( resp.url ); }, onException: function(resp){ HThemeManager._errTemplateException( resp.url ); }, method: 'GET', async: _async } ); if(!_async){ return _respText; } }, /** Returns the theme/component -specific path, called from inside css * themes, a bit kludgy approach to tell the theme graphics file paths. **/ getThemeGfxPath: function() { var _themeName = this._cssEvalParams[0], _componentName = this._cssEvalParams[1], _themePath = this._cssEvalParams[2], _urlPrefix = this._urlPrefix( _themeName, _componentName, _themePath ); return this._joinPath( _urlPrefix, 'gfx' ); }, /** = Description * Returns the theme/component -specific graphics file path with proper css wrappers. * Used from inside css themes, a bit kludgy approach to tell the file name path. * * = Parameters * +_fileName+:: The File name to load. * **/ getCssFilePath: function( _fileName ){ var _themeName = this._cssEvalParams[0]; if((~HThemeHasIE6GifsInsteadOfPng.indexOf(_themeName)) && (BROWSER_TYPE.ie6 || BROWSER_TYPE.symbian) ){ return "url('"+this._joinPath( this.getThemeGfxPath(), _fileName.replace('.png','-ie6.gif') )+"')"; } else { return "url('"+this._joinPath( this.getThemeGfxPath(), _fileName )+"')"; } }, /** = Description * Loads a css file based on the given url (or file path). * Evaluates the css data. * Makes sure the browser uses the data for component styles. * * = Parameter * +_url+:: A valid url that points to a valid css file. * * = Returns * The source of the url. * **/ loadCSS: function( _url ) { var _contentType = 'text/css', _cssFun = function(_cssText){ // Don't try to do anything with empty or invalid css data: if (!_cssText || _cssText === "") { return; } HThemeManager.useCSS( _cssText ); }; this.fetch( _url, _contentType, _cssFun, true ); }, useCSS: function( _cssText ){ var _contentType = 'text/css'; // Evaluate the css text _cssText = this._bindCSSVariables( _cssText ); var _style, _styleSheet, _head; if(BROWSER_TYPE.ie) { // Internet Explorer (at least 6.x; check what 7.x does) _style = document.createStyleSheet(); _style.cssText = _cssText; } else { // Common, standard