概述:qx.core.Variant类为qooxdoo框架提供全局的配置,qooxdoo的已有的配置项有client:设置代码运行浏览器,debug:设置代码的运行模式,aspects:设置是否开启方面,dynlocale:动态区域? 。Variant为qooxdoo通过工具根据具体环境设置从一份代码中提取出不同的分支代码提供了基础。所谓具体环境设置就是Variant中的设置值。
Variant
--------------
define(key, allowedValues, defaultValue) 定义一个设置
get(key)
isSet(key, variants)
select(key, variantFunctionMap)
第二个参数是一个形为{值A:对象B}的Map,如果值A与Variant中key(参数1)的值一致,返回对象B,否则返回variantFunctionMap[default];
/**
* Manage variants of source code. May it be for different debug options,
* browsers or other environment flags.
* [源代码配置]管理。用于设定不同的调试选项、浏览器和其他环境标记。
*
*
* Variants enable the selection and removal of code from the build version.
* A variant consists of a collection of states from which exactly one is active
* at load time of the framework. The global map <code>qxvariants</code> can be
* used to select a variant before the Framework is loades.
* [源代码配置]使得从构建版本选定或者移除代码成为可能
* 一个[源代码配置]由“确切对象:在框架载入时激活”的状态集合组成
* 全局的map qxvariants用于在框架载入之前选择一个[源代码配置]
*
*
* Depending on the selected variant a specific code
* path can be choosen using the <code>select</code> method. The generator is
* able to set a variant and remove all code paths which are
* not selected by the variant.
* 一份具体的代码依赖于选择的[源代码配置]
* 路径可以用select方法选择,generator可以设置一个[源代码配置]和移除所有没有被[源代码配置]选择的代码
*
* Variants are used to implement browser optimized builds and to remove
* debugging code from the build version. It is very similar to conditional
* compilation in C/C++.
* [源代码配置]用于实现浏览器最小化构建和从构建版本移除调试代码。它非常像C/C++的条件编绎。
*
* Here is a list of pre-defined variant names, the possible values they take,
* and their system default:
* 这里是一个清单,包含预定义的[源代码配置]名称、可供设置的值和系统默认值
* <table>
* <tr>
* <th>Variant name</th><th>Possible values</th><th>System default</th>
* </tr><tr>
* <td>qx.client <td>[ "gecko", "mshtml", "opera", "webkit" ] <td><auto-detected>
* </tr><tr>
* <td>qx.debug <td>[ "on", "off" ] <td>"on"
* </tr><tr>
* <td>qx.aspects <td>[ "on", "off" ] <td>"off"
* </tr><tr>
* <td>qx.dynlocale <td>[ "on", "off" ] <td>"on"
* </tr>
* </table>
*/
qx.Bootstrap.define("qx.core.Variant",
{
statics :
{
/** {Map} stored variants */
__variants : {},
/** {Map} cached results */
__cache : {},
/**
* Pseudo function as replacement for isSet() which will only be handled by the optimizer
* 替代isSet的假冒方法,仅用于优化程序
*
* @return {Boolean}
*/
compilerIsSet : function() {
return true;
},
/**
* Define a variant 定义一个[源代码配置]
*
* @param key {String} An Unique key for the variant. The key must be prefixed with a
* namespace identifier (e.g. <code>"qx.debug"</code>)
* @param allowedValues {String[]} An array of all allowed values for this variant.
* @param defaultValue {String} Default value for the variant. Must be one of the values
* defined in <code>defaultValues</code>.
*/
define : function(key, allowedValues, defaultValue)
{
if (qx.core.Variant.compilerIsSet("qx.debug", "on"))
{
if (!this.__isValidArray(allowedValues)) {
throw new Error('Allowed values of variant "' + key + '" must be defined!');
}
if (defaultValue === undefined) {
throw new Error('Default value of variant "' + key + '" must be defined!');
}
}
if (!this.__variants[key])
{
this.__variants[key] = {};
}
else if (qx.core.Variant.compilerIsSet("qx.debug", "on"))
{
if (this.__variants[key].defaultValue !== undefined) {
throw new Error('Variant "' + key + '" is already defined!');
}
}
this.__variants[key].allowedValues = allowedValues;
this.__variants[key].defaultValue = defaultValue;
},
/**
* Get the current value of a variant.
* 获取[源代码配置]的当前值
*
* @param key {String} name of the variant
* @return {String} current value of the variant
*/
get : function(key)
{
var data = this.__variants[key];
if (qx.core.Variant.compilerIsSet("qx.debug", "on"))
{
if (data === undefined) {
throw new Error('Variant "' + key + '" is not defined.');
}
}
if (data.value !== undefined) {
return data.value;
}
return data.defaultValue;
},
/**
* Import settings from global qxvariants into current environment
* 从全局的qxvariants导入设置到当前环境
*
* @return {void}
*/
__init : function()
{
if (window.qxvariants)
{
for (var key in qxvariants)
{
if (qx.core.Variant.compilerIsSet("qx.debug", "on"))
{
if ((key.split(".")).length < 2) {
throw new Error('Malformed settings key "' + key + '". Must be following the schema "namespace.key".');
}
}
if (!this.__variants[key]) {
this.__variants[key] = {};
}
this.__variants[key].value = qxvariants[key];
}
window.qxvariants = undefined;
try {
delete window.qxvariants;
} catch(ex) {};
this.__loadUrlVariants(this.__variants);
}
},
/**
* Load variants from URL parameters if the setting <code>"qx.allowUrlSettings"</code>
* is set to true.
* 如果qx.allowUrlSettings设定为true,从URL参数载入[源代码配置]
*
*
* The url scheme for variants is: <code>qxvariant:VARIANT_NAME:VARIANT_VALUE</code>.
*/
__loadUrlVariants : function()
{
if (qx.core.Setting.get("qx.allowUrlVariants") != true) {
return;
}
var urlVariants = document.location.search.slice(1).split("&");
for (var i=0; i<urlVariants.length; i++)
{
var variant = urlVariants[i].split(":");
if (variant.length != 3 || variant[0] != "qxvariant") {
continue;
}
var key = variant[1];
if (!this.__variants[key]) {
this.__variants[key] = {};
}
this.__variants[key].value = decodeURIComponent(variant[2]);
}
},
/**
* Select a function depending on the value of the variant.
* 依据[源代码设置]的值获取一个function
*
* Example:
* 示例
*
* <pre class='javascript'>
* var f = qx.Variant.select("qx.client", {
* "gecko": fucntion() { ... },
* "mshtml|opera": function() { ... },
* "default": function() { ... }
* });
* </pre>
*
* Depending on the value of the <code>"qx.client"</code> variant whit will select the
* corresponding function. The first case is selected if the variant is "gecko", the second
* is selected if the variant is "mshtml" or "opera" and the third function is selected if
* none of the other keys match the variant. "default" is the default case.
*
* @param key {String} name of the variant. To enable the generator to optimize
* this selection, the key must be a string literal.
* @param variantFunctionMap {Map} map with variant names as keys and functions as values.
* @return {Function} The selected function from the map.
*/
select : function(key, variantFunctionMap)
{
if (qx.core.Variant.compilerIsSet("qx.debug", "on"))
{
// WARINING: all changes to this function must be duplicated in the generator!!
// modules/variantoptimizer.py (processVariantSelect)
if (!this.__isValidObject(this.__variants[key])) {
throw new Error("Variant \"" + key + "\" is not defined");
}
if (!this.__isValidObject(variantFunctionMap)) {
throw new Error("the second parameter must be a map!");
}
}
for (var variant in variantFunctionMap)
{
if (this.isSet(key, variant)) {
return variantFunctionMap[variant];
}
}
if (variantFunctionMap["default"] !== undefined) {
return variantFunctionMap["default"];
}
if (qx.core.Variant.compilerIsSet("qx.debug", "on"))
{
throw new Error('No match for variant "' + key +
'" in variants [' + qx.lang.Object.getKeysAsString(variantFunctionMap) +
'] found, and no default ("default") given');
}
},
/**
* Check whether a variant is set to a given value. To enable the generator to optimize
* this selection, both parameters must be string literals.
* 检查是否[源代码配置]设定为给定的值,使得generator可以优化这个选择,两个参数都必须为字面量
*
* This method is meant to be used in if statements to select code paths. If the condition of
* an if statement is only this method, the generator is able to optimize the if
* statement.
* 此方法表达了它被用于if语句选择一个代码路径,如果if语句的条件仅仅是此方法,generator就可优化这个if语句
*
* Example:
*
* <pre class='javascript'>
* if (qx.core.Variant.isSet("qx.client", "mshtml")) {
* // some Internet Explorer specific code
* } else if(qx.core.Variant.isSet("qx.client", "opera")){
* // Opera specific code
* } else {
* // common code for all other browsers
* }
* </pre>
*
* @param key {String} name of the variant
* @param variants {String} value to check for. Several values can be "or"-combined by separating
* them with a "|" character. A value of "mshtml|opera" would for example check if the variant is
* set to "mshtml" or "opera"
* @return {Boolean} whether the variant is set to the given value
*/
isSet : function(key, variants)
{
var access = key + "$" + variants;
if (this.__cache[access] !== undefined) {
return this.__cache[access];
}
var retval = false;
// fast path
if (variants.indexOf("|") < 0)
{
retval = this.get(key) === variants;
}
else
{
var keyParts = variants.split("|");
for (var i=0, l=keyParts.length; i<l; i++)
{
if (this.get(key) === keyParts[i])
{
retval = true;
break;
}
}
}
this.__cache[access] = retval;
return retval;
},
/**
* Whether a value is a valid array. Valid arrays are:
*
* * type is object
* * instance is Array
*
* @name __isValidArray
* @param v {var} the value to validate.
* @return {Boolean} whether the variable is valid
*/
__isValidArray : function(v) {
return typeof v === "object" && v !== null && v instanceof Array;
},
/**
* Whether a value is a valid object. Valid object are:
*
* * type is object
* * instance != Array
*
* @name __isValidObject
* @param v {var} the value to validate.
* @return {Boolean} whether the variable is valid
*/
__isValidObject : function(v) {
return typeof v === "object" && v !== null && !(v instanceof Array);
},
/**
* Whether the array contains the given element
*
* @name __arrayContains
* @param arr {Array} the array
* @param obj {var} object to look for
* @return {Boolean} whether the array contains the element
*/
__arrayContains : function(arr, obj)
{
for (var i=0, l=arr.length; i<l; i++)
{
if (arr[i] == obj) {
return true;
}
}
return false;
}
},
/*
*****************************************************************************
DEFER
*****************************************************************************
*/
defer : function(statics)
{
statics.define("qx.client", [ "gecko", "mshtml", "opera", "webkit" ], qx.bom.client.Engine.NAME);
statics.define("qx.debug", [ "on", "off" ], "on");
statics.define("qx.aspects", [ "on", "off" ], "off");
statics.define("qx.dynlocale", [ "on", "off" ], "on");
statics.__init();
}
});
分享到:
相关推荐
3. **面向对象编程**:qooxdoo完全基于面向对象的编程模型,允许开发者定义自己的类,继承现有类,并实现多态性。这使得代码结构清晰,易于维护。 4. **数据绑定**:框架提供了数据绑定机制,使得UI组件可以自动...
它的全称为"Qooxdoo Software Development Kit",提供了完整的工具链,帮助开发者用JavaScript编写高质量、可维护的代码。这个SDK不仅是一个框架,更是一个开发环境,涵盖了从代码生成、编译到调试的全过程。 ### 1...
将不建议使用npm模块qx-cli ,从现在开始,您要做的所有事情是: $ npm install -g qooxdoo-compiler$ qx create myapp$ cd myapp$ qx compile不要忘记,如果您以前安装过qx-cli ,则必须发出以下命令: $ npm ...
Qooxdoo-Compiler是Qooxdoo( )应用程序的新编译器和命令行界面,使用100%Node.JS Javascript编写,它在标准python生成器上进行了以下关键改进: 包括Babel,用于将ES6添加到所有Qooxdoo应用程序中 快速(最快24...
qooxdoo-contrib是qooxdoo项目(http://qooxdoo.org)的组成部分。 用户可以在简洁的结构中灵活地开发,维护和促进贡献。 贡献可以轻松地集成到自定义qooxdoo应用程序中。 注意:SourceForge上的此存储库是旧版! 它...
Qooxdoo JavaScript框架qooxdoo是一个通用JavaScript框架,使您可以为各种平台创建应用程序。 通过其面向对象的编程模型,您可以构建丰富的交互式应用程序(RIA),用于移动设备的类似于本机的应用程序,轻量级的...
1. **安装和配置**:首先,你需要安装qooxdoo SDK,并设置好开发环境。 2. **创建项目**:使用qooxdoo的`generate.py`脚本初始化一个新的项目,这会生成基本的项目结构。 3. **编写代码**:在生成的项目结构中,你...
1. **对象导向编程**:qooxdoo基于面向对象的编程模型,允许开发者使用类和对象的概念来构建JavaScript代码,提高代码的可重用性和可维护性。 2. **编译器**:qooxdoo的编译器将源代码转换为优化的JavaScript,提高...
qooxdoo框架的快速应用程序开发。 您可以拖放组件,定义属性并生成源代码。
qooxdoo是一个使用JavaScript编写的开源应用程序框架,用于开发富互联网应用(RIA)。它包含了一整套用于构建跨浏览器应用的工具和组件,从底层的类系统到用户界面组件,例如表格、列表、窗口、按钮、弹出窗口等。...
此外,还有生成器工具,可以自动生成应用的基础结构,包括源码目录、资源配置和预定义的类结构,帮助开发者快速启动新项目。 5. **响应式布局**: Qooxdoo 4.1版本对响应式设计提供了很好的支持,使得应用程序能够...
1. **后端代码**:主要使用Java编写,包含Spring MVC的配置、Controller类、Service层和DAO层,处理HTTP请求,访问数据库等。 2. **前端代码**:使用Qooxdoo的JavaScript库创建用户界面,通过Ajax通信与后端交互,...
语言:English (United States) 扩展开发人员工具,添加显示与所选DOM元素关联的QooxDoo数据的侧栏。 扩展开发人员工具,添加一个侧栏,显示与所选相关联的Qooxdoo数据。... 在控制台中使用$ q使用所选窗口小部件。
qooxdoo采用面向对象的编程方式,这意味着开发者可以利用类、继承、封装和多态等概念来组织代码。这种模型使得代码结构更加清晰,易于理解和维护。通过定义类和对象,开发者可以创建复杂的业务逻辑和用户界面,同时...
qooxdoo是一个全面和创新的AJAX应用程序框架。利用面向对象的JavaScript允许开发令人印象深刻的跨浏览器的应用。没有HTML,CSS知识,也不是必要的。它包括一个独立于平台的开发工具链,一个最先进的图形用户界面工具...
Qooxdoo使用了虚拟DOM(Document Object Model)的概念,允许开发者在内存中构建和操作DOM树,提高了性能并减少了对实际DOM的操作。这使得UI更新更为高效,特别是在处理大量动态数据时。 3. **资源管理**: SDK中...
扩展开发工具,添加一个侧栏,显示与所选DOM元素相关联的Qooxdoo数据。 扩展开发人员工具,添加侧边栏,以显示与所选DOM元素关联的...在控制台中使用$ q与选定的小部件一起使用。 支持语言:English (United States)
标题中的“新将Delphi的Form窗口转换为Qooxdoo窗体”指的是一个技术转换过程,涉及到两个不同的开发环境和框架:Delphi和Qooxdoo。Delphi是一款基于Object Pascal语言的集成开发环境(IDE),常用于构建桌面应用程序...
Qooxdoo JavaScript框架的控件 关于该项目 ville.Embed是一个控件,旨在使图像,图标和图形更加动态。 好处 使用令人惊叹的图标集在项目中使用纯CSS图标 使用代码或结合代码和HTML5的模板标签将SVG图标嵌入项目中 ...
qooxdoo开发框架的界面可视化设计器