ææ°ã 1.5.0_pre0 ã«ãªã£ã¦ãã®ã§èª¿æ» (èªåç¨ã®ã¡ã¢ãªã®ã§èªã¿ã«ããã¦ãã´ã¡ã³ãªããã£ã¦ãã¨ã§)
Prototype.js 1.4.0 ããã®å¤æ´ç¹
CHANGELOG ãã
- String.prototype.truncateã追å
- String.prototype.gsub, String.prototype.sub, String.prototype.scan ã追å ã
- Template ã¯ã©ã¹ã追å ã
- $$ é¢æ°ã追å ã
- Selector ã¯ã©ã¹ã追å ã
- Element.childOf ã追å ã
- String.prototype.inspect ãä¿®æ£ã
- String.prototype.strip ã追å ã
String
String.prototype.truncate
æç« ãçãããã
var text = 'ã¨ã£ã¦ãé·ãæç« ã§ããèªãã®ãããããããã§ããæ¦è¦ã ããæããããããçããããã¨æãã¾ãã'; // å ã®æç« ãç¢ºèª alert(text.inspect()); alert(text.length); // çãããã('...' ãå«ãã§30æå) alert(text.truncate().inspect()); alert(text.truncate().length); // çãããã('...' ãå«ãã§10æå) alert(text.truncate(10).inspect()); alert(text.truncate(10).length); // çãããã('<以ä¸ç¥>' ãå«ã10æå alert(text.truncate(10, ' <以ä¸ç¥>').inspect()); alert(text.truncate(10, ' <以ä¸ç¥>').length);
String.prototype.gsub
æååå ¨ä½ãç½®æããã
var text = '天é å±±ä¸ åé 天é å±±ä¸ åé'; alert(text); var replacer1 = function(t){ return '<b>' + t + '</b>';}; var replacer2 = '<b>天é</b>'; var replacer3 = '<b>#{1}</b><b>#{2}</b>'; alert(text.gsub('天é', replacer1)); alert(text.gsub('天é', replacer2)); alert(text.gsub('(天)(.)', replacer3));
String.prototype.sub
æååã®æåã«ãããããç®æãç½®æããã
var text = '天é å±±ä¸ åé 天é å±±ä¸ åé'; alert(text); var replacer1 = function(t){ return '<b>' + t + '</b>';}; var replacer2 = '<b>天é</b>'; var replacer3 = '<b>#{1}</b><b>#{2}</b>'; alert(text.sub('天é', replacer1)); alert(text.sub('天é', replacer2)); alert(text.sub('(天)(.)', replacer3));
String.prototype.scan
æç« ãããããããæååãæ½åºããã
var text = '天é å±±ä¸ åé 天é å±±ä¸ åé'; text.scan('天.', alert);
String.prototype.strip
æç« ã®åå¾ã®ã¹ãã¼ã¹ (æ¹è¡ãã¿ããã¹ãã¼ã¹) ãåé¤ããã
var text = ' \n\t \n\ttext \n\t \n\ttext \n\t \n\t'; // å ã®æç« ãç¢ºèª alert(text); alert(text.length); // ã¹ãã¼ã¹ãåé¤ alert(text.strip()); alert(text.strip().length);
$$
CSS ã©ã¤ã¯ã®ã»ã¬ã¯ã¿ã§è¦ç´ ãé¸æããã
Event.observe(window, 'load', function() { // CSS ã©ã¤ã¯ãªã»ã¬ã¯ã¿ãæå®ãã(è¤æ°å¯)ã var elements = $$('div.class1 div.class2', '#id .class3'); for(var i = 0, len = elements.length; i < len; i ++) { alert(elements[i]); } });
Selector
CSS ã©ã¤ã¯ã®ã»ã¬ã¯ã¿(ã²ã¨ã¤ã®ãã¼ã¯ã³)ã§è¦ç´ ãé¸æããã
Event.observe(window, 'load', function() { // CSS ã©ã¤ã¯ãªã»ã¬ã¯ã¿ãæå®ãã(ã²ã¨ã¤ã®ãã¼ã¯ã³ã ã)ã var selector = new Selector('div.class1.class2'); // selector ã«ã¹ã³ã¼ãã¨ãªãè¦ç´ ãæå®ããã(çç¥æã¯ã¹ã³ã¼ãã document ã¨ããã) var elements = selector.findElements(document.body); for(var i = 0, len = elements.length; i < len; i ++) { alert(elements[i]); } });
Template
ç°¡æãã³ãã¬ã¼ãã¨ã³ã¸ã³
var template1 = new Template('åã®ååã¯#{name}ã§ãã趣å³ã¯#{hobby}ã§ãã\\#{gufufu}'); var message1 = template1.evaluate({ name: '天é', hobby: 'åå¼·' }); var message2 = template1.evaluate({ name: 'å±±ä¸', hobby: 'éã¶ãã¨' }); alert(message1); alert(message2); var template2 = new Template('åã®ååã¯*nameã§ãã趣å³ã¯*hobbyã§ãã\\*gufufu', /(^|.|\r|\n)(\*([a-zA-Z_]+))/); var message3 = template2.evaluate({ name: 'åé', hobby: 'ãã³ã' }); var message4 = template2.evaluate({ name: 'é¾ä¹ä»', hobby: '女ã¨éã¶ãã¨' }); alert(message3); alert(message4);
Element
Element.childOf
è¦ç´ ãããè¦ç´ ã®åå«ã«å½ãããã調ã¹ãã
Event.observe(window, 'load', function() { // è¦ç´ ã® ID ãæå®ããã var result = Element.childOf('element_id', 'parent_id'); alert(result); var element = $('element_id'); var parent = $('parent_id'); // è¦ç´ ã®ãªãã¸ã§ã¯ããæå®ããã result = Element.childOf(element, parent); alert(result); });