Built-In Namespace _global_
Field Attributes | Field Name and Description |
---|---|
是否 cache code。
若不是要重構 code 則不需要。
undefined: 依照預設
Boolean: 明確設定,但如此即無法繼承。
|
|
<constant> |
JavaScript library framework main class name.
|
Get file resource by XMLHttpRequest
依序載入 resource,用於 include JavaScript 檔之類需求時,取得檔案內容之輕量級函數。 除 Ajax,本函數亦可用在 CScript 執行中。 |
|
evaluate @ Global scope.
|
|
真正執行 module code.
|
|
Test if the value is a native Object.
|
|
framework main prototype definition
for JSDT: 有 prototype 才會將之當作 Class
|
|
要 extend 到 name_space 下的 variables。
variable_hash[variable name] = variable full name, 包括所在 module name.
|
Method Attributes | Method Name and Description |
---|---|
_()
|
|
_get_hash_key(text)
Get the hash key of text.
|
|
a(htm, t, js, ico)
|
|
add_item(item)
增加項目至當前的 synchronous_group.
|
|
add_Microsoft_translate(text, callback, from_enc, to_enc)
為 Microsoft Translator 設置
|
|
afterwards_add(item, item_is_path)
臨時/後續新增項目至當前的 synchronous_group.
|
|
靠常用字自動判別字串之編碼 string,預設編碼
|
|
Big5_kana_fix(text)
將 BIG5 日文假名碼修改為 Unicode 日文假名。
|
|
c(r)
|
|
complement(number)
補數計算。
正數的補數即為自身。若要求得互補之後的數字,請設成負數。
|
|
continued_fraction(sequence, max_no)
取得連分數序列的數值
|
|
eval_code(code)
本 library 專用之 evaluate()。
若在 function 中 eval 以獲得 local variable,在舊 browser 中須加 var。
e.g.
|
|
extend(variable_set, name_space, from_name_space)
延展物件 (learned from jQuery):
將 from_name_space 下的 variable_set 延展/覆蓋到 name_space。
|
|
factorization(number)
取得某數的質因數,因式分解/素因子分解, factorization, get floor factor.
|
|
find_class(class_name, element, parent_node, tag_name, flag)
|
|
floor_sqrt(positive)
得到平方數,相當於 Math.floor(Math.sqrt(number)).
|
|
gcd(n1, n2)
Get GCD of 2 numbers
|
|
get_code_from_generated_various(ns, prefix, code_array)
把 get_various_from_code 生成的 namespace 轉成 code
|
|
get_function_name(fr, ns, force_load)
獲得函數名
|
|
get_module(module_name)
不使用 eval 的方法,get the module namespace of specific module name.
|
|
get_module_path(module_name, file_name)
get the path of specified module.
|
|
get_script_base_path(JSFN)
得知 script file 之相對 base path
|
|
取得執行 script 之 path, 在 .hta 中取代 WScript.ScriptFullName。
|
|
取得執行 script 之名稱
|
|
get_variable(variable_name, name_space)
simple evaluates to get value of specified variable identifier name.
|
|
get_various_from_code(code, fill_code)
get various from code
|
|
get_window_status(node)
取得當前 window status
|
|
has_class(element, class_name)
If HTML element has specified class
|
|
hex(number)
VBScript has a Hex() function but JScript does not.
|
|
include_module_resource(file_name, module_name)
include resource of module.
|
|
include_resource(resource, callback, use_write, type, type, use_write)
Including other JavaScript/CSS files synchronously.
|
|
inherit(parent_module_name, initial_arguments)
module 中模擬 inherit 時使用。
TODO:
同步載入功能
|
|
initI(a)
|
|
initial_env(OS_type, reset)
Setup environment variables
|
|
is_Array(v)
Test if the value is a native Array.
|
|
is_debug(debug_level)
Tell if it's now debugging.
|
|
is_Function(v)
Test if the value is a native Function.
|
|
is_loaded(module_name, module_name)
判斷 module 是否存在,
TODO
以及是否破損。
|
|
is_module_pattern(test_string)
test 是否符合 module pattern.
|
|
is_type(value, want_type, get_Class)
判斷為何種 type。主要用在 Error, DOMException 等 native object 之判別。
|
|
for 引用: include library 自 registry 中的 path
|
|
mutual_division(n1, n2, times)
輾轉相除 n1/n2 或 小數 n1/1 轉成 整數/整數
|
|
name()
translate {String} code_for_including to function
|
|
new_node(nodes, layer)
創建新的 DOM 節點(node)。
createNode() 的功能補充加強版。
TODO: 分割功能(set_attrib, add_child, .
|
|
object_tester(want_type, toString_reference)
get a type test function
|
|
open_template(FN, format, io_mode)
|
|
parse_require(dependency_list, separator, base_require)
解析 dependency list 以獲得所需之 module/path/variable name.
|
|
pv(i, d, k)
|
|
replace_function(name_space, function_name, new_function)
workaround.
|
|
request_item_maybe_module(resource_string)
test function.request 的項目是否為 module.
|
|
require_netscape_privilege(privilege, callback|[callback,arguments])
Ask privilege in mozilla projects: Firefox 2, 3.
|
|
set_debug(debug_level)
Set debugging level
|
|
set_run(running)
control/setup source codes to run.
|
|
setup_module(module_name, code_for_including, parent_module_name)
載入 module。
本函數會預先準備好下層 module 定義時的環境,但請盡量先 call 上層 name-space 再定義下層的,否則可能會出現問題,如 memory leak 等。 |
|
simplify_path(path)
轉化所有 /.
|
|
split_module_name(module_name)
將輸入的 string 分割成各 module 單元。
need environment_adapter() ** 並沒有對 module 做完善的審核! |
|
to_module_name(module, separator)
取得 module 之 name。以 library name 起始。
|
|
to_rational_number(number, rate, max_no)
The best rational approximation.
|
|
to_RegExp_pattern(pattern, RegExp_flag, escape_pattern)
String pattern (e.g.
|
|
use(module, callback, extend_to, force)
Include specified module.
|
|
use_API(API, callback)
自動挑選 domain
|
|
use_function(name_space, dependency_list, extend_to, no_strict)
module 中需要 include function/module/variable 時設定 local variables 使用。
本函數將把所需 function include 至當前 namespace 下。 TODO: 輸入 function name 即可 |
Field Detail
{Boolean, undefined}
cache_code
是否 cache code。
若不是要重構 code 則不需要。
undefined: 依照預設
Boolean: 明確設定,但如此即無法繼承。
Defined in: ce.origin.js.
Defined in: ce.origin.js.
<constant>
Class
JavaScript library framework main class name.
Defined in: ce.origin.js.
Defined in: ce.origin.js.
- See:
- ECMA-262: Object.Class: A string value indicating the kind of this object.
{String, undefined}
get_file
Get file resource by XMLHttpRequest
依序載入 resource,用於 include JavaScript 檔之類需求時,取得檔案內容之輕量級函數。
除 Ajax,本函數亦可用在 CScript 執行中。
Defined in: ce.origin.js.
依序載入 resource,用於 include JavaScript 檔之類需求時,取得檔案內容之輕量級函數。
除 Ajax,本函數亦可用在 CScript 執行中。
Defined in: ce.origin.js.
// get contents of [path/to/file]: var file_contents = CeL.get_file('path/to/file');
- See:
- Cross Site AJAX, Cross-domain Ajax, FF3 issue with iFrames and XSLT standards, Security.fileuri.strict origin policy - MozillaZine Knowledge Base Chrome: NETWORK_ERR: XMLHttpRequest Exception 101
global_eval
evaluate @ Global scope.
By the ECMA-262, new Function() will 'Pass in the Global Environment as the Scope parameter.'
copy from jQuery core.js
Defined in: ce.origin.js.
Defined in: ce.origin.js.
- See:
- Eval JavaScript in a global context | Java.net use execScript on Internet Explorer
i
真正執行 module code.
Defined in: ce.origin.js.
_.debug('including code of [' + _.to_module_name(module_name) + ']..'),
TODO: code_for_including(_, load_arguments)
Defined in: ce.origin.js.
{Boolean}
is_Object
Test if the value is a native Object.
TODO:
test null
Defined in: ce.origin.js.
Defined in: ce.origin.js.
- Since:
- 2009/12/20 08:38:26
prototype
framework main prototype definition
for JSDT: 有 prototype 才會將之當作 Class
Defined in: ce.origin.js.
Defined in: ce.origin.js.
variable_hash
要 extend 到 name_space 下的 variables。
variable_hash[variable name] = variable full name, 包括所在 module name.
Defined in: ce.origin.js.
Defined in: ce.origin.js.
Method Detail
_()
Defined in: old.class template.origin.js.
{String}
_get_hash_key(text)
Get the hash key of text.
Defined in: ce.origin.js.
Defined in: ce.origin.js.
- Parameters:
- {String} text
- text to test
- Returns:
- {String} hash key
a(htm, t, js, ico)
Defined in: map.origin.js.
- Parameters:
- htm
- t
- js
- ico
add_item(item)
增加項目至當前的 synchronous_group.
Defined in: ce.origin.js.
Defined in: ce.origin.js.
- Parameters:
- item
add_Microsoft_translate(text, callback, from_enc, to_enc)
為 Microsoft Translator 設置
Defined in: API.origin.js.
Defined in: API.origin.js.
- Parameters:
- text
- test to translate
- callback
- callback(from text,to text)
- from_enc Optional
- to_enc Optional
- Returns:
afterwards_add(item, item_is_path)
臨時/後續新增項目至當前的 synchronous_group.
callback 用.
Defined in: ce.origin.js.
Defined in: ce.origin.js.
- Parameters:
- item
- item_is_path
autodetectStringEncode(str)
靠常用字自動判別字串之編碼 string,預設編碼
Defined in: file.origin.js.
Defined in: file.origin.js.
- Parameters:
- str
Big5_kana_fix(text)
將 BIG5 日文假名碼修改為 Unicode 日文假名。
Defined in: DOM.origin.js.
Defined in: DOM.origin.js.
- Parameters:
- {String} text
- Unicode text
- Returns:
- See:
- from Unicode 補完計畫 jrename.js
c(r)
Defined in: map.origin.js.
- Parameters:
- r
{Number}
complement(number)
補數計算。
正數的補數即為自身。若要求得互補之後的數字,請設成負數。
Defined in: math.origin.js.
Defined in: math.origin.js.
alert(complement())
- Parameters:
- {Number} number
- Since:
- 2010/3/12 23:47:52
- Returns:
- {Number} base 1: 1's Complement, 2: 2's Complement, (TODO: 3, 4, ..)
- See:
- http://www.tomzap.com/notes/DigitalSystemsEngEE316/1sAnd2sComplement.pdf http://en.wikipedia.org/wiki/Method_of_complements http://en.wikipedia.org/wiki/Signed_number_representations
continued_fraction(sequence, max_no)
取得連分數序列的數值
Defined in: math.origin.js.
Defined in: math.origin.js.
- Parameters:
- {Array} sequence
- 序列
- {Number} max_no Optional
- 取至第 max_no 個
- Returns:
- Requires:
- mutual_division.done
- See:
- var a=continued_fraction([1,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2]); alert(a+'\n'+a[0]/a[1]+'\n'+Math.SQRT2+'\n'+(Math.SQRT2-a[0]/a[1])+'\n'+mutual_division(a[0],a[1]));
eval_code(code)
本 library 專用之 evaluate()。
若在 function 中 eval 以獲得 local variable,在舊 browser 中須加 var。
e.g., 'var local_variable=' + ..
不加 var 在舊 browser 中會變成 global 變數。
Defined in: ce.origin.js.
Defined in: ce.origin.js.
- Parameters:
- code
- script code to evaluate
- Returns:
- value that evaluate process returned
- See:
- window.eval === window.parent.eval http://stackoverflow.com/questions/3277182/how-to-get-the-global-object-in-javascript
extend(variable_set, name_space, from_name_space)
延展物件 (learned from jQuery):
將 from_name_space 下的 variable_set 延展/覆蓋到 name_space。
Defined in: ce.origin.js.
Defined in: ce.origin.js.
- Parameters:
- variable_set
- variable set
- {Object|Function} name_space
- extend to what name-space
- {Object|Function} from_name_space
- When inputing function names, we need a base name-space to search these functions.
- Since:
- 2009/11/25 21:17:44
- Returns:
- library names-pace
{Array}
factorization(number)
取得某數的質因數,因式分解/素因子分解, factorization, get floor factor.
唯一分解定理(The Unique Factorization Theorem)告訴我們素因子分解是唯一的,這即是稱為算術基本定理 (The Fundamental Theorem of Arithmeric) 的數學金科玉律。
Defined in: math.origin.js.
Defined in: math.origin.js.
- Parameters:
- {Number} number
- Returns:
- {Array} [prime1,power1,prime2,power2,..]
- Requires:
- floor_sqrt
{[HTMLElement]}
find_class(class_name, element, parent_node, tag_name, flag)
Defined in: DOM.origin.js.
- Parameters:
- {String} class_name
- class_name_1[ class_name_2 ..]
- {HTMLElement} element
- HTML elements
- {HTMLElement} parent_node
- parent node
- {String} tag_name
- tag name
- flag
- Returns:
- {[HTMLElement]} nodes
- See:
- document.getElementsByClassName in prototype.js, jquery('.class') document.querySelector() http://www.w3.org/TR/selectors-api/ http://blog.darkthread.net/blogs/darkthreadtw/archive/2008/04/17/document-queryselector-in-ie8.aspx
floor_sqrt(positive)
得到平方數,相當於 Math.floor(Math.sqrt(number)).
get integer square root
Defined in: math.origin.js.
Defined in: math.origin.js.
var p = 20374345, q = CeL.math.floor_sqrt(p = p * p - 1); CeL.log(q + '
' + (q * q) + '
' + p + '
' + (++q * q));
- Parameters:
- {Number} positive
- number
- Returns:
- r, r^2 <= number < (r+1)^2
- See:
- Paul Hsieh's Square Root page Suitable Integer Square Root Algorithm for 32-64-Bit Integers on Inexpensive Microcontroller? | Comp.Arch.Embedded | EmbeddedRelated.com
gcd(n1, n2)
Get GCD of 2 numbers
Defined in: math.origin.js.
Defined in: math.origin.js.
- Parameters:
- n1
- number 1
- n2
- number 2
- Returns:
- GCD of the 2 numbers
{String}
get_code_from_generated_various(ns, prefix, code_array)
把 get_various_from_code 生成的 namespace 轉成 code
Defined in: reorganize.origin.js.
Defined in: reorganize.origin.js.
- Parameters:
- {Object} ns
- root namespace
- {String} prefix Optional
- (TODO) prefix of root namespace
- {Array} code_array Optional
- inner use, please don't specify this value.
- Since:
- 2009/12/20 14:51:52
- Returns:
- {String} code
get_function_name(fr, ns, force_load)
獲得函數名
Defined in: ce.origin.js.
Defined in: ce.origin.js.
- Parameters:
- {Function} fr
- function reference
- {String} ns
- name-space
- {Boolean} force_load
- force reload this name-space
- Since:
- 2010/1/7 22:10:27
- Returns:
- See:
- 可能的話請改用 {@link CeL.native.parse_function}(F).funcName
{, }
get_module(module_name)
不使用 eval 的方法,get the module namespace of specific module name.
Defined in: ce.origin.js.
Defined in: ce.origin.js.
- Parameters:
- {String} module_name
- module name
- Returns:
- null some error occurred
- namespace of specific module name
{String}
get_module_path(module_name, file_name)
get the path of specified module.
Defined in: ce.origin.js.
Defined in: ce.origin.js.
// 存放 data 的 path path = library_namespace.get_module_path(this, '');
- Parameters:
- {String} module_name
- module name
- {String} file_name
- 取得在同一目錄下檔名為 file_name 之 path。若填入 '' 可取得 parent 目錄。
- Returns:
- {String} module path
{String}
get_script_base_path(JSFN)
得知 script file 之相對 base path
Defined in: ce.origin.js.
Defined in: ce.origin.js.
// 引數為本.js檔名。若是更改.js檔名,亦需要同步更動此值! var basePath=get_script_base_path('baseFunc.js'); perl: use File::Basename;
- Parameters:
- {String} JSFN
- script file name
- Returns:
- {String} relative base path
{String, }
get_script_full_name()
取得執行 script 之 path, 在 .hta 中取代 WScript.ScriptFullName。
Defined in: ce.origin.js.
Defined in: ce.origin.js.
- Returns:
- {String} 執行 script 之 path
- '' unknown environment
{String, }
get_script_name()
取得執行 script 之名稱
Defined in: ce.origin.js.
Defined in: ce.origin.js.
- Returns:
- {String} 執行 script 之 名稱
- '' unknown environment
get_variable(variable_name, name_space)
simple evaluates to get value of specified variable identifier name.
不使用 eval().
Defined in: ce.origin.js.
Defined in: ce.origin.js.
- Parameters:
- {String} variable_name
- variable identifier name. e.g., /[a-z\d$_]+(.[a-z\d_]+)+/i
- {Object|Function} name_space Optional
- initialize name-space. default: global
- Since:
- 2010/1/1 18:11:40
- Returns:
- value of specified variable identifier name
{Object}
get_various_from_code(code, fill_code)
get various from code
Defined in: reorganize.origin.js.
Defined in: reorganize.origin.js.
- Parameters:
- {String} code
- 程式碼
- {Boolean} fill_code
- (TODO) 不只是定義,在 .code 填入程式碼。
- Since:
- 2009/12/5 15:04:42, 2009/12/20 14:33:30, 2010/7/7 10:58:22
- Returns:
- {Object} root namespace
{Object}
get_window_status(node)
取得當前 window status
Defined in: DOM.origin.js.
Defined in: DOM.origin.js.
- Parameters:
- node
- HTML element or Event object
- Returns:
- {Object} status
{Boolean}
has_class(element, class_name)
If HTML element has specified class
Defined in: DOM.origin.js.
Defined in: DOM.origin.js.
- Parameters:
- {HTMLElement} element
- HTML elements
- {String} class_name
- class_name_1[ class_name_2 ..]
- Returns:
- {Boolean}
{String}
hex(number)
VBScript has a Hex() function but JScript does not.
Defined in: math.origin.js.
Defined in: math.origin.js.
alert('0x'+CeL.hex(16725))
- Parameters:
- {Number} number
- Returns:
- {String} number in hex
include_module_resource(file_name, module_name)
include resource of module.
Defined in: ce.origin.js.
Defined in: ce.origin.js.
// 外部程式使用時,通常用在 include 相對於 library 本身路徑固定的檔案。 // 例如 file_name 改成相對於 library 本身來說的路徑。 CeL.include_module_resource('../../game/game.css'); library_namespace.include_module_resource('select_input.css', this);
- Parameters:
- {String} file_name
- 與 module 位於相同目錄下的 resource file name
- {String} module_name Optional
- 呼叫的 module name。未提供則設成 library base path,此時 file_name 為相對於 library 本身路徑的檔案。
- Since:
- 2010/1/1-2 13:58:09
- Returns:
include_resource(resource, callback, use_write, type, type, use_write)
Including other JavaScript/CSS files synchronously.
TODO:
timeout for giving up
use document.createElementNS()
http://headjs.com/#theory
Defined in: ce.origin.js.
Defined in: ce.origin.js.
- Parameters:
- {String} resource
- path
- {Function|Object} callback
- use_write ? test function{return } : callback function(path) / {callback: callback function(path, module), module: module name, global: global object when run callback}
- {Boolean} use_write Optional
- use document.write() instead of insert a element to
- {Number} type Optional
- 1: is a .css file, others: script
- type
- use_write
inherit(parent_module_name, initial_arguments)
module 中模擬 inherit 時使用。
TODO:
同步載入功能
Defined in: ce.origin.js.
Defined in: ce.origin.js.
- Parameters:
- {String} parent_module_name
- 欲繼承的 module_name
- initial_arguments
- 繼承時的 initial arguments
- Returns:
initI(a)
Defined in: old.class template.origin.js.
- Parameters:
- a
{Object}
initial_env(OS_type, reset)
Setup environment variables
Defined in: ce.origin.js.
Defined in: ce.origin.js.
- Parameters:
- {String} OS_type Optional
- type of OS
- {Boolean} reset Optional
- reset the environment variables
- Returns:
- {Object} environment variables set
{Boolean}
is_Array(v)
Test if the value is a native Array.
Defined in: ce.origin.js.
Defined in: ce.origin.js.
- Parameters:
- v
- value to test
- Since:
- 2009/12/20 08:38:26
- Returns:
- {Boolean} the value is a native Array.
{Boolean, Number}
is_debug(debug_level)
Tell if it's now debugging.
Defined in: ce.origin.js.
Defined in: ce.origin.js.
- Parameters:
- {Integer} debug_level Optional
- if it's now in this debug level.
- Returns:
- {Boolean} It's now in specified debug level.
- {Number} It's now in what debug level (Integer).
{Boolean}
is_Function(v)
Test if the value is a native Function.
Defined in: ce.origin.js.
Defined in: ce.origin.js.
- Parameters:
- v
- value to test
- Since:
- 2009/12/20 08:38:26
- Returns:
- {Boolean} the value is a native Function.
{Boolean}
is_loaded(module_name, module_name)
判斷 module 是否存在,
TODO
以及是否破損。
Defined in: ce.origin.js.
Defined in: ce.origin.js.
- Parameters:
- {String} module_name
- module name
- {Array} module_name
- module name list
- Returns:
- {Boolean} 所指定 module 是否全部存在以及良好。
{Boolean}
is_module_pattern(test_string)
test 是否符合 module pattern.
TODO: improve
Defined in: ce.origin.js.
Defined in: ce.origin.js.
- Parameters:
- {String} test_string
- string to test
- Returns:
- {Boolean} 是否符合 module pattern
{Boolean, String, undefined}
is_type(value, want_type, get_Class)
判斷為何種 type。主要用在 Error, DOMException 等 native object 之判別。
Defined in: ce.origin.js.
Defined in: ce.origin.js.
CeL.is_type(value_to_test, 'Array');
- Parameters:
- value
- variable or class instance to test
- {String} want_type Optional
- type to compare: number, string, boolean, undefined, object, function
- {Boolean} get_Class Optional
- get the class name of a class(function) instance.
- Since:
- 2009/12/14 19:50:14
- Returns:
- {Boolean} The type is matched.
- {String} The type of value
- {undefined} error occurred
- See:
- JavaScript类型检测小结(下) - 岁月如歌
Perfection kills » `instanceof` considered harmful (or how to write a robust `isArray`)
library_loader_by_registry()
for 引用: include library 自 registry 中的 path
Defined in: reorganize.origin.js.
Defined in: reorganize.origin.js.
- Since:
- 2009/11/25 22:59:02
{Array}
mutual_division(n1, n2, times)
輾轉相除 n1/n2 或 小數 n1/1 轉成 整數/整數
Defined in: math.origin.js.
Defined in: math.origin.js.
- Parameters:
- {Number} n1
- number 1
- {Number} n2 Optional
- number 2
- {Number} times
- max 次數, 1,2,..
- Returns:
- {Array} 連分數序列 ** 負數視 _.mutual_division.done 而定!
name()
translate {String} code_for_including to function
Defined in: ce.origin.js.
Defined in: ce.origin.js.
{HTMLElement}
new_node(nodes, layer)
創建新的 DOM 節點(node)。
createNode() 的功能補充加強版。
TODO: 分割功能(set_attrib, add_child, ..), 簡化
Defined in: DOM.origin.js.
Defined in: DOM.origin.js.
- Parameters:
- {Object|Array} nodes
- node structure
- {String|Array|HTMLElement} layer Optional
- where to layer this node. e.g., parent node
- Since:
- 2010/6/21 13:45:02
- Returns:
- {HTMLElement} new node created
{Function}
object_tester(want_type, toString_reference)
get a type test function
Defined in: ce.origin.js.
Defined in: ce.origin.js.
// 大量驗證時,推薦另外在本身 scope 中造出捷徑: this.OtS = Object.prototype.toString; var is_Array = CeL.object_tester('Array', 'OtS'); // test if(is_Array(value)) // it's really a native Array ;
- Parameters:
- {String} want_type
- object type to compare
- {String} toString_reference Optional
- a reference name to Object.prototype.toString
- Since:
- 2009/12/20 08:38:26
- Returns:
- {Function} type test function
open_template(FN, format, io_mode)
Defined in: file.origin.js.
- Parameters:
- FN
- format
- io_mode
- Returns:
{Object, Number}
parse_require(dependency_list, separator, base_require)
解析 dependency list 以獲得所需之 module/path/variable name..
Defined in: ce.origin.js.
Defined in: ce.origin.js.
- Parameters:
- {Array|String} dependency_list
list of dependency function/module/variable required. module 須以 CeL.env.module_name_separator ('.') 結尾。若輸入 String,則以 separator 或 '|' 分割。
- separator
- base_require
- Since:
- 2011/8/6 22:10:57
- Returns:
- {Object} result { variable: {variable_name: full_name}, module: {module name: loaded or not}, module_to_load: [], URL: {}}
- {Number} error_no
pv(i, d, k)
Defined in: old.class template.origin.js.
- Parameters:
- i
- d
- k
replace_function(name_space, function_name, new_function)
workaround.
把 name_space 下的 function_name (name_space[function_name]) 換成 new_function。
for Lazy Function Definition Pattern.
惰性求值(Lazy Evaluation),又稱懶惰求值、懶漢求值
Defined in: ce.origin.js.
Defined in: ce.origin.js.
library_namespace.replace_function(_, 'to_SI_prefix', to_SI_prefix);
- Parameters:
- name_space
- in which name-space
- {String} function_name
- name_space.function_name
- {Function} new_function
- replace to what function
- Returns:
- new_function
- See:
- http://realazy.org/blog/2007/08/16/lazy-function-definition-pattern/, http://peter.michaux.ca/article/3556
{Boolean}
request_item_maybe_module(resource_string)
test function.request 的項目是否為 module.
TODO
現在還有很大問題!
Defined in: ce.origin.js.
Defined in: ce.origin.js.
- Parameters:
- {String} resource_string
- resource to test
- Returns:
- {Boolean} resource 是否為 module (true: is module, false: is URL?)
require_netscape_privilege(privilege, callback|[callback,arguments])
Ask privilege in mozilla projects: Firefox 2, 3.
get_file() 遇到需要提高權限時使用。
enablePrivilege 似乎只能在執行的 function 本身或 caller 呼叫才有效果,跳出函數即無效,不能 cache,因此提供 callback。
就算按下「記住此決定」,重開瀏覽器後需要再重新授權。
Defined in: ce.origin.js.
Defined in: ce.origin.js.
- Parameters:
- {String|Error} privilege
- privilege that asked 或因權限不足導致的 Error
- {Function|Array} callback|[callback,arguments]
- Run this callback if getting the privilege. If it's not a function but a number(經過幾層/loop層數), detect if there's a loop or run the caller.
- Since:
- 2010/1/2 00:40:42
- Throws:
- error
- Returns:
- OK / the return of callback
{Integer}
set_debug(debug_level)
Set debugging level
Defined in: ce.origin.js.
Defined in: ce.origin.js.
- Parameters:
- {Integer} debug_level Optional
- The debugging level to set.
- Returns:
- {Number} debugging level now
set_run(running)
control/setup source codes to run.
基本上使用同步(synchronous)的方式,除非所需資源已經載入,或是有辦法以 XMLHttpRequest 取得資源。
Defined in: ce.origin.js.
Defined in: ce.origin.js.
sr = CeL.set_run; sr('module_name', function(){ // ... }); TODO: sr('module_name', function(){ CeL.import('module_name', {module_function_1:0}); CeL.module_function_1('11') === module_function_1('11'); var instance=new CeL.module_name.module_class_1; instance.print(112); });
- Parameters:
- running
- sequence: list of {Function} function to run/欲執行之 function → change .to_run | {Integer} timeout (ms): 僅能保證上次 function 執行至此次 function 一定會等超過這段時間 → change .start_time, .timeout | {String} library module name to import → change .to_load_module, .module_count | {String} URL/file path (image/JavaScript files/CSS) → change .to_load_path, .path_count | {Array} 另一組同時 loading set: [{String|Function|Integer}, ..] → 拆開全部當作同時 loading | TODO: {Object} loading with additional config
- Since:
- 2011/8/4 22:31:47
{, Object, }
setup_module(module_name, code_for_including, parent_module_name)
載入 module。
Defined in: ce.origin.js.
本函數會預先準備好下層 module 定義時的環境,但請盡量先 call 上層 name-space 再定義下層的,否則可能會出現問題,如 memory leak 等。
Defined in: ce.origin.js.
- Parameters:
- {String} module_name Optional
module name to register: 本 module 之 name(id)
- {Function} code_for_including
若欲 include 整個 module 時,需囊括之 code。
code_for_including( {Function} library_namespace: namespace of library, load_arguments: 呼叫時之 argument(s) )- parent_module_name
- Returns:
- null
invalid module
- {Object}
下層 module 之 name-space
- undefined
something error, e.g., 未成功 load,code_for_including return null, ..
{String}
simplify_path(path)
轉化所有 /., /.., //
Defined in: ce.origin.js.
Defined in: ce.origin.js.
- Parameters:
- {String} path
- 欲轉化之 path
- Since:
- 2009/11/23 22:32:52
- Returns:
- {String} path
{Array}
split_module_name(module_name)
將輸入的 string 分割成各 module 單元。
need environment_adapter()
** 並沒有對 module 做完善的審核!
Defined in: ce.origin.js.
need environment_adapter()
** 並沒有對 module 做完善的審核!
Defined in: ce.origin.js.
- Parameters:
- {String} module_name
- module name
- Returns:
- {Array} module unit array
{String}
to_module_name(module, separator)
取得 module 之 name。以 library name 起始。
Defined in: ce.origin.js.
Defined in: ce.origin.js.
- Parameters:
- module
- separator
- Returns:
- {String} module name start with library name
to_rational_number(number, rate, max_no)
The best rational approximation. 取得值最接近之有理數 (use 連分數 continued fraction), 取近似值.
c.f., 調日法
在分子或分母小於下一個漸進分數的分數中,其值是最接近精確值的近似值。
Defined in: math.origin.js.
Defined in: math.origin.js.
to_rational_number(4088/783)
- Parameters:
- {Number} number
- number
- {Number} rate Optional
- 比例在 rate 以上
- {Number} max_no Optional
- 最多取至序列第 max_no 個 TODO : 並小於 l: limit
- Returns:
- [分子, 分母, 誤差]
- Requires:
- mutual_division,continued_fraction
- See:
- http://en.wikipedia.org/wiki/Continued_fraction#Best_to_rational_numbers
{RegExp}
to_RegExp_pattern(pattern, RegExp_flag, escape_pattern)
String pattern (e.g., "/a+/g") to RegExp pattern.
qq// in perl.
String.prototype.toRegExp = function(f) { return to_RegExp_pattern(this.valueOf(), f); };
Defined in: native.origin.js.
Defined in: native.origin.js.
- Parameters:
- {String} pattern
- pattern text
- {Boolean|String} RegExp_flag Optional
- flags when need to return RegExp object
- {RegExp} escape_pattern Optional
- char pattern need to escape
- Returns:
- {RegExp} RegExp object
{Error, , undefined}
use(module, callback, extend_to, force)
Include specified module.
會先嘗試以依序載入(asynchronous)的方式取得 module。 無法以 Ajax 載入時,若未設定 callback,會回傳錯誤。若設定 callback,會以同步(synchronous)的方式載入 module,於載入完成執行 callback。 若因為 browser 安全性設定而無法取得則會回傳 -1,表示將以同步的方式載入 module。因為 module 尚未載入,在此階段尚無法判別此 module 所需之 dependency list。此 list 會被作為引數傳入 callback。 注意:以下的 code 中,CeL.warn 不一定會被執行(可能會、可能不會),因為執行時 log 可能尚未被 include。
此時應該改用 CeL.set_run('application.log', callback);
code in head/script/:
Defined in: ce.origin.js.
會先嘗試以依序載入(asynchronous)的方式取得 module。 無法以 Ajax 載入時,若未設定 callback,會回傳錯誤。若設定 callback,會以同步(synchronous)的方式載入 module,於載入完成執行 callback。 若因為 browser 安全性設定而無法取得則會回傳 -1,表示將以同步的方式載入 module。因為 module 尚未載入,在此階段尚無法判別此 module 所需之 dependency list。此 list 會被作為引數傳入 callback。 注意:以下的 code 中,CeL.warn 不一定會被執行(可能會、可能不會),因為執行時 log 可能尚未被 include。
此時應該改用 CeL.set_run('application.log', callback);
code in head/script/:
CeL.use('code.log');
CeL.warn('WARNING message');
** 在指定 callback 時 name_space 無效!
** 預設會 extend 到 library 本身之下!
Defined in: ce.origin.js.
CeL.use('code.log', function(){..}); CeL.use(['code.log', 'code.debug']);
- Parameters:
- {String} module
- module name
- {Function} callback Optional
- callback function | [callback, 進度改變時之 function (TODO)]
- {Object|Boolean} extend_to Optional
- extend to which name-space
false: just load, don't extend to library name-space
this: extend to global
object: extend to specified name-space that you can use [name_space]._func_ to run it
(others, including undefined): extend to root of this library. e.g., call CeL._function_name_ and we can get the specified function. - force
- Returns:
- {Error}
- -1 will execute callback after load, 不代表 load module 了!
- {undefined} no error, OK
use_API(API, callback)
自動挑選 domain
Defined in: API.origin.js.
Defined in: API.origin.js.
- Parameters:
- API
- API name
- callback
- null: do NOT load
- Since:
- 2010/6/20 22:12:23
- Returns:
- [ API url, API key ]
- See:
{Number}
use_function(name_space, dependency_list, extend_to, no_strict)
module 中需要 include function/module/variable 時設定 local variables 使用。
本函數將把所需 function include 至當前 namespace 下。 TODO: 輸入 function name 即可
Defined in: ce.origin.js.
本函數將把所需 function include 至當前 namespace 下。 TODO: 輸入 function name 即可
Defined in: ce.origin.js.
// requires (inside module) // 事先定義 @ 'use strict'; var split_String_to_Object; // 之所以需要使用 eval 是因為要 extend 至當前 namespace 下。 // 若無法 load CeL.data,將會 throw eval(library_namespace.use_function(this, 'data.split_String_to_Object')); // use it split_String_to_Object(); // 不用 eval 的方法 1: function 預設都會 extend 至當前 library_namespace 下。 library_namespace.use_function(this, 'data.split_String_to_Object'); library_namespace.use_function(this, 'data.split_String_to_Object', false); // 若無法 load CeL.data,將會 throw // use it library_namespace.split_String_to_Object(); // 不用 eval 的方法 2: 設定 extend_to var o={}; // 若無法 load CeL.data,將會 throw library_namespace.use_function(this, 'data.split_String_to_Object', o); // use it o.split_String_to_Object();
- Parameters:
- {Function|Object} name_space
- module name-space
- {Array|String} dependency_list
- list of dependency function/module/variable required. module 須以 '.' 結尾。若輸入 String,則以 ',' 分割。
- {Function|Object} extend_to Optional
- 若設定將把 variable extend 至 extend_to
- no_strict
- Since:
- 2009/12/26 02:36:31 2009/12/31 22:21:23 add 類似 'data.' 的形式,為 module。 2010/6/14 22:58:18 避免相互 require
- Throws:
- {Error}
- 有些 module 尚未載入。
- Returns:
- {Number} error code 1: can't parse dependency_list