Pot.js 1.21 and PotLite.js 1.38 released.
Pot.js 1.21 ãš PotLite.js 1.38 ãªãªãŒã¹ããŸããã Pot.js ã¯éåæåŠçãäžå¿ãšãã JavaScript ã©ã€ãã©ãªã§ãã æŠèŠãªã©ã®è©³ãã詳现ã¯ä»¥äžã®ãªãã¡ã¬ã³ã¹ãåç §ãã ããã
Pot.js + PotLite.js - Document and Reference
Download
Pot.js+PotLite.js-zip
Changelog
ja:
Pot.Deferred ã³ãŒã«ããã¯å ã§ FileReader ãè¿ãããšãã®äžå ·åãä¿®æ£
JSDoc ã³ã¡ã³ããå€ã ã£ãã®ãä¿®æ£
Blob ã³ã³ã¹ãã©ã¯ã¿ãš BlobBuilder ã®å®è£ ã®éããåžåãã Pot.createBlob() 颿°ãå®è£
Pot.equals() ã«é·ãã®éããªããžã§ã¯ããæž¡ããæã«äžæ£ãªçµæã«ãªãäžå ·åãä¿®æ£
jQuery.ajax ã Pot.Deferred åãã Pot.deferrizejQueryAjax() ãã¹ã¯ãªããã®èªã¿èŸŒã¿é åºã«é¢ä¿ãªãå®è¡ã§ãããã調æŽ
Pot.serializeToQueryString() ã§ Boolean ããã®ãŸãŸæåååãããã倿Ž
èŠçŽ ã®ãªãµã€ãºå€ãååŸã§ãã Pot.getResizeSize() ãå®è£
DOM èŠçŽ ãç»é¢äžã«èŠããŠããå€å¥ãã Pot.isElementInView() 颿°ãå®è£
ãªããžã§ã¯ããæååã§ãã³ãããçµæãè¿ã Pot.dump() 颿°ãå®è£
æ¢åã³ã³ã¹ãã©ã¯ã¿ã®ããããã£ã«äžå ·åããã£ãã®ãä¿®æ£
prototype ãšå ±ã«ã³ã³ã¹ãã©ã¯ã¿ãçæã§ãã Pot.createConstructor() ãå®è£
Pot.debug() ã®ãšã©ãŒçãšãªã Pot.error() ã远å
Image ã€ã³ã¹ã¿ã³ã¹ãã©ããå€å¥ãã Pot.isImage() ãå®è£
Pot.maybeDeferred() ã« jQuery.Deferred ã JSDeferred ãªã©ä»ã® Deferred ã€ã³ã¹ã¿ã³ã¹ãæž¡ããš Pot.Deferred ã€ã³ã¹ã¿ã³ã¹åããããæ¹èš
Pot.Deferred ã³ãŒã«ããã¯å ã§ Image ã€ã³ã¹ã¿ã³ã¹ãè¿ããš then() ã§ onloadãrescue() ã§ onerror ãæŸããããæ¹èš
en:
Fixed Deferred when returned FileReader with event callback.
Fixed JSDoc comment and return value.
Added Pot.createBlob() function for browser compatibility with BlobBuilder and Blob constructor.
Fixed bug: Pot.equals() will return true for objects that have different lengths.
Improved Pot.deferrizejQueryAjax() for jQuery plugin.
Changed Pot.serializeToQueryString() to handle as it is Boolean (true and false).
Added Pot.getResizeSize() function.
Added Pot.isElementInView() function.
Added Pot.dump() function.
Fixed the constructor property initialization.
Added Pot.createConstructor() function.
Added Pot.error() function.
Added Pot.isImage() function.
Improved Pot.maybeDeferred() to convert to an instance of Pot.Deferred from jQuery.Deferred and JSDeferred.
Improved Pot.Deferred callback to ensure an instance of Image loading.
Pot.createBlob() ã¯ããã©ãŠã¶ç°å¢ã« Blob ãå®è£ ãããŠããã Blob ããBlobBuilder ãå®è£ ãããŠããã BlobBuilder ã䜿ã£ãŠ Blob ãçæããŸãã
Pot.begin(function() { var blob = Pot.createBlob('hoge', 'text/plain'); // 第2åŒæ°ã¯ä»»æ var reader = new FileReader(); reader.readAsText(blob); return reader; }).then(function(res) { Pot.debug(res); // 'hoge' });
Pot.serializeToQueryString() ã¯ã以å㯠true ã false ã空æå '' ãšæ±ã£ãŠããã®ãã'true', 'false' ãšããŠæ±ãããã«ãªããŸããã ããã¯ãPot.request() ã§ã®ãã©ã¡ãŒã¿ã®æå®ã§ãåãã§ãã Pot.dump() ã¯ããªããžã§ã¯ããªã©ä»»æã®å€ããã³ãããæååãè¿ããŸãã åç §ã¯ #1 ãªã©ã®è¡šçŸã«ãªããŸãã
var reg = /^[a-z]+$/g; var err = new Error('error!'); var str = new String('hello'); var arr = [1, 2, 3, {a: 4, b: 5, c: true}, false, null, void 0]; var obj = { key1 : 'val1', key2 : 'val2', arr : arr, arr2 : arr, strs : [str, str], err : err, err2 : err, reg1 : reg, reg2 : reg, reg3 : reg }; obj.obj = obj; Pot.debug( Pot.dump(obj) ); // #0 { // key1: "val1", // key2: "val2", // arr: #3 [ // 1, // 2, // 3, // { // a: 4, // b: 5, // c: true // }, // false, // null, // undefined // ], // arr2: #3, // strs: [ // #5 (new String("hello")), // #5 // ], // err: #6 (new Error("error!")), // err2: #6, // reg1: #8 (new RegExp(/^[a-z]+$/g)), // reg2: #8, // reg3: #8, // obj: #0 // }
Pot.createConstructor() ã¯ãprototype ãšå ±ã«ã³ã³ã¹ãã©ã¯ã¿ãçæããŠè¿ããŸãã {Function} Pot.createConstructor([name ,] proto [, init]); name ãæå®ããããšãtoString ã«äœ¿ãããŸãã init ã¯åæåãã颿°åãŸãã¯é¢æ°ãä»»æã§æå®ããŸãã åŒæ° init ãçç¥ãããŠãproto å ã« 'init' ãšããã¡ãœããããããšããããåæåãã颿°ãšæ±ããŸãã
// proto å ã« init ã§åæåã¡ãœãããæå® var Hoge = Pot.createConstructor('Hoge', { init : function(a, b, c) { this.value = a + b + c; }, getHoge : function() { return 'hogehoge'; } }); Pot.debug(new Hoge(1, 2, 3).value); // 6 Pot.debug(new Hoge().getHoge()); // 'hogehoge'
// åæå颿°ã颿°ã§æå® var Fuga = Pot.createConstructor({ value : 1, addValue : function(v) { this.value += v; return this; }, getValue : function() { return this.value; } }, function(a, b, c) { this.value += a + b + c; }); Pot.debug(new Fuga(1, 2, 3).value); // 7 Pot.debug(new Fuga(1, 2, 3).addValue(10).getValue()); // 17
// initialize ãšããååã§åæå颿°ãæå® var Piyo = Pot.createConstructor('Piyo', { initialize : function(a, b, c) { this.value = a + b + c; }, getValue : function() { return this.value; } }, 'initialize'); Pot.debug(new Piyo(10, 20, 30).getValue()); // 60
Pot.maybeDeferred() ã¯ãjQuery.Deferred ã JSDeferred ãªã©ãä»ã®ã©ã€ãã©ãªã® Deferred ã€ã³ã¹ã¿ã³ã¹ã Pot.Deferred ã€ã³ã¹ã¿ã³ã¹åã§ããããã«ãªããŸããã
// jQuery.Deferred ã Pot.Deferred å var d = $.Deferred(); d.done(function() { Pot.debug(1); }).done(function() { Pot.debug(2); }); // Pot.Deferred ã€ã³ã¹ã¿ã³ã¹å Pot.maybeDeferred(d).then(function() { Pot.debug(3); }).ensure(function() { Pot.debug(4); }); d.resolve(); // output: // 1 // 2 // 3 // 4
JSDeferred ãšå€ã®åãæž¡ã
// JSDeferred ã€ã³ã¹ã¿ã³ã¹ var d = new Deferred().next(function(res) { Pot.debug(res); // 1 return res + 1; }); // Pot.Deferred ã€ã³ã¹ã¿ã³ã¹å Pot.maybeDeferred(d).then(function(res) { Pot.debug(res); // 2 return res + 1; }).ensure(function(res) { Pot.debug(res); // 3 }); d.call(1);
FileReader ãšåãã Pot.Deferred ã³ãŒã«ããã¯å ã§ Image ã€ã³ã¹ã¿ã³ã¹ãè¿ããš then() ã§ onloadãrescue() ã§ onerror ãæŸããããã«ãªããŸããã
Pot.begin(function() { var img = new Image(); img.src = 'http://api.polygonpla.net/img/logo/pot.js.mini.png'; return img; }).then(function(img) { // ããŒãå®äºæ (onload) Pot.debug(img.width); // 300 }).rescue(function(err) { Pot.debug(err); // ãšã©ãŒæ (onerror) });
詳ãã詳现ã¯ä»¥äžã®ãªãã¡ã¬ã³ã¹ãåç §ãã ããã
Reference
Pot.js + PotLite.js - Document and Reference
Repository
polygonplanet/Pot.js - GitHub















