X-Git-Url: http://git.osdn.jp/view?a=blobdiff_plain;f=0.6.x%2Fjs%2F01_core%2F03_XType.js;h=84bca3d2c863746bd796adea4ce1dcc41512a823;hb=24f935c7a129b0a00d800e4983da6491a913aeef;hp=212a803d2260d36b7525437226bc089df34029f2;hpb=29f2a2e24ee1eea5a80e1345570fd75de6dcdbf4;p=pettanr%2FclientJs.git diff --git a/0.6.x/js/01_core/03_XType.js b/0.6.x/js/01_core/03_XType.js index 212a803..84bca3d 100644 --- a/0.6.x/js/01_core/03_XType.js +++ b/0.6.x/js/01_core/03_XType.js @@ -1,90 +1,150 @@ -/* - * http://pettanr.sourceforge.jp/test/type.html - * - * need xua - */ - -X.Type = { - isObject : function( v ){ - return v && typeof v === 'object'; // typeof null === 'object' ã«å¯¾ç - }, - - isFunction : function( v ){ - return typeof v === 'function'; - }, - - isUnknown : function( v ){ - return typeof v === 'unknown'; // ie ã® XHR.open ãªã© - }, - - isArray : + /** + * Array ãï¼å¤å®ãããargumnets çã®ãã§ã¤ã¯ Array 㯠false ãªã®ã§æ³¨æã + * @function + * @alias X.Type.isArray + */ +var X_Type_isArray = new Function( 'v', - X_UA.IE < 5.5 || X_UA.NetFront < 4 ? // netfront3.4 㯠html ã« instanceof ããã㨠error ã«ãªã + X_UA[ 'IE' ] < 5.5 || X_UA[ 'NetFront' ] < 4 ? // netfront3.4 㯠html ã« instanceof ããã㨠error ã«ãªã 'return v&&v.push===Array.prototype.push' : // win ie5-, MacIE5.2 - X_UA.IE ? + X_UA[ 'IE' ] ? 'return v&&Object.prototype.toString.call(v)==="[object Array]"' : 'return v instanceof Array' ), - - isBoolean : function( v ){ - return v === true || v === false; - }, - - isString : function( v ){ - return typeof v === 'string'; // v === v + ''; - }, - - isNumber : function( v ){ - return typeof v === 'number'; // v !== v || v + 0 === v; - }, - - isFinite : function( v ){ - return typeof v === 'number' && isFinite( v ); // isFinite( '123' ) === true ã«å¯¾ç - }, - - isNaN : function( v ){ - return v !== v; // isNaN( 'NaN' ) === true ã«å¯¾ç - }, - - isHTMLElement : + + /** + * HTMLElement ãï¼å¤å®ãããã¡ãªã¿ã« return v instanceof Element 㯠ie8 ã§ã¨ã©ã¼ã + * @function + * @alias X.Type.isHTMLElement + */ + X_Type_isHTMLElement = new Function( 'v', - ( X_UA.IE4 || X_UA.MacIE ) ? - 'return v&&v.tagName&&v.insertAdjacentHTML&&true' : // ie4 or MacIE5.23, v.all <- error - X_UA.NetFront < 4 ? - 'return v&&v.nodeType===1' : // instanceof not a function. + ( X_UA[ 'IE4' ] || X_UA[ 'MacIE' ] ) ? + 'return v&&v.tagName&&v.insertAdjacentHTML&&!0' : // ie4 or MacIE5.23, v.all <- error + X_UA[ 'NetFront' ] < 4 ? + 'return v&&v.nodeType===1' : // instanceof not a function. netfront3.4 㯠html ã« instanceof ããã㨠error ã«ãªã window[ 'HTMLElement' ] ? 'return v instanceof HTMLElement' : - //window[ 'Element' ] ? - // 'return v instanceof Element' : // error @ie8 'return v&&v.appendChild&&v.nodeType===1' - ), + ); + + + +/** + *
ãã«ãã¤ã³åã®å¤å®ã«ä½¿ç¨ããé¢æ°ãéãããã®ããã©ã¦ã¶ã®ãã¤ãã£ããªå¤å®é¢æ°ã«ã¯ä¸å¯è§£ãªæåãããã®ã§ãX.Type ã使ç¨ããã»ããããã + * http://pettanr.sourceforge.jp/test/type.html + * @namespace X.Type + * @alias X.Type + */ +X[ 'Type' ] = { + 'isObject' : X_Type_isObject, + 'isFunction' : X_Type_isFunction, + 'isUnknown' : X_Type_isUnknown, + 'isArray' : X_Type_isArray, + 'isBoolean' : X_Type_isBoolean, + 'isString' : X_Type_isString, + 'isNumber' : X_Type_isNumber, + 'isFinite' : X_Type_isFinite, + 'isNaN' : X_Type_isNaN, + 'isHTMLElement' : X_Type_isHTMLElement, + 'isImage' : X_Type_isImage, + 'isNull' : X_Type_isNull, + 'isUndefined' : X_Type_isUndefined +}; + + /** + *
Object ãï¼å¤å®ããã + *
typeof null === 'object' ã«å¯¾çæ¸ãªã®ã§ null 㯠Object ã§ã¯ãªãã + *
new String(), new Number(), new Boolean() ã typeof object ãªã®ã§å¯¾ç + * @alias X.Type.isObject + */ + function X_Type_isObject( v ){ + return v && typeof v === 'object' && v !== v + '' && v !== v + 0 && v !== true; // typeof null === 'object' ã«å¯¾ç + }; + /** + * Function ãï¼å¤å®ããã + * @alias X.Type.isFunction + */ + function X_Type_isFunction( v ){ + return typeof v === 'function'; + }; + /** + * ie ã® XHR.open çãã«ãã¤ã³ãªãã¸ã§ã¯ããï¼å¤å®ããã + * @alias X.Type.isUnknown + */ + function X_Type_isUnknown( v ){ + return typeof v === 'unknown'; + }; + + /** + * çå½å¤ãï¼å¤å®ããã + * @alias X.Type.isBoolean + */ + function X_Type_isBoolean( v ){ + return v === true || v === false; + }; + /** + * æååãï¼å¤å®ããã + * @alias X.Type.isString + */ + function X_Type_isString( v ){ + return /* typeof v === 'string'; */ v === v + ''; // æååã®å ç®ã¯ IE ã§é ãããã + }; + /** + * æ°å¤ãï¼å¤å®ããã + * @alias X.Type.isNumber + */ + function X_Type_isNumber( v ){ + return /* typeof v === 'number'; */ v + 0 === v || v !== v; + }; + /** + * finite ãï¼å¤å®ãããisFinite( '123' ) === true ã«å¯¾çæ¸ã + * @alias X.Type.isFinite + */ + function X_Type_isFinite( v ){ + return v + 0 === v && isFinite( v ); + }; + /** + * NaN ãï¼å¤å®ãããisNaN( 'NaN' ) === true ã«å¯¾çæ¸ã + * @alias X.Type.isNaN + */ + function X_Type_isNaN( v ){ + return v !== v; + }; + /* - * new Image ããå ´åã« HTMLElement ã® img ãä½ããããã©ã¦ã¶ããã + * new Image ããå ´åã« HTMLImageElement ãä½ããããã©ã¦ã¶ã¨,ããã§ãªããã©ã¦ã¶(IE8-)ããã + * @alias X.Type.isImage */ - isImage : - function( v ){ - if( v && v.constructor === window.Image ) return true; - if( v && window.HTMLImageElement && v.constructor === window.HTMLImageElement ) return true; // ie6- 㯠constructor ããundefãHTMLImageElement ããundef ãªã®ã§ãHTMLElement ã®åå¨ç¢ºèªãå¿ è¦ - if( X_UA.WebKit < 525.13 ){ // Safari3- - if( v && v.src !== undefined && v.onload !== undefined && X.Type.isNumber( v.height ) && X.Type.isNumber( v.width ) && X.Type.isBoolean( v.complete ) ){ - return true; - }; + function X_Type_isImage( v ){ + if( v && v.constructor === window.Image ) return true; + if( v && window.HTMLImageElement && v.constructor === window.HTMLImageElement ) return true; // ie6- 㯠constructor ã undefãHTMLImageElement ã undef ãªã®ã§ãHTMLElement ã®åå¨ç¢ºèªãå¿ è¦ + if( X_UA[ 'WebKit' ] < 525.13 ){ // Safari3- + if( v && v.src !== undefined && v.onload !== undefined && X_Type_isNumber( v.height ) && X_Type_isNumber( v.width ) && X_Type_isBoolean( v.complete ) ){ + return true; }; - return false; - }, + }; + return false; + }; /* isElementCollection : function(v) { return (Object.prototype.toString.call(v) === "[object HTMLCollection]"); }, */ - isNull : function( v ){ + /** + * Null ãï¼å¤å®ããã + * @alias X.Type.isNull + */ + function X_Type_isNull( v ){ return v === null; - }, - - isUndefined : function( v ){ - return v === void 0; - } -}; + }; + /** + * undefined ãï¼å¤å®ããã + * @alias X.Type.isUndefined + */ + function X_Type_isUndefined( v ){ + return v === undefined; + }; console.log( 'X.Core.Type' );