ã¯ã¦ãªãã¤ã¢ãªã¼ã§JavaScriptãå®è¡ããããã®iGoogleã®ã¬ã¸ã§ããä½ã£ã¦ã¿ã
ããã«ã±ã¯å¿ãã¾ããããæ¨æ¥ãã¯ããã¦iGoogleã®ã¬ã¸ã§ãããä½ã£ã¦ã¿ã¾ããã
ãªãã ãé£ããã®ãã¨æã£ã¦ãããæå¤ã¨ç°¡åã§ã試ãã«ãã¯ã¦ãªãã¤ã¢ãªã¼ã§JavaScriptãå®è¡ããããã®iGoogleã¬ã¸ã§ãããä½ã£ã¦ã¿ã¾ããã
ä¸åº¦ä½ã£ã¦ãã¾ãã¨ãmixiã¢ããªã«ãå¿ç¨ãèãã¦ãåå¼·ãã対象ã¨ãã¦ã¯ãªããªããããªã¼ã¨æãã¾ããã
Google Gadget Editorã使ã£ã¦ä½ãã¨ãã¬ãã¥ã¼ããã£ã¦æ¥½ã§ãããã§ããopensocialã®APIã¯ãã¬ãã¥ã¼ã§ã¯åããªãã£ããªã¼ã
iGoogleã¬ã¸ã§ããã®ã½ã¼ã¹
<?xml version="1.0" encoding="UTF-8"?> <Module> <ModulePrefs title="JavaScript Eval for Hatena Diary" width="500" height="500" author="http://www.hatena.ne.jp/jdg/"> <Require feature="opensocial-0.8" /> <Require feature="dynamic-height" /> </ModulePrefs> <Content type="html"> <![CDATA[ <style type="text/css"> h1 { font-size: 1.2em; } h2 { font-size: 1em; } p { font-size: 0.7em; } input, textarea { margin-top: 1em; } </style> <script type="text/javascript"> var jsgadget = {}; jsgadget.event = (function() { if (document.addEventListener) { return function(elem, event, handler, capture) { return elem.addEventListener(event, handler, capture); } } else { return function(elem, event, handler, capture) { return elem.attachEvent('on'+event, handler); } } })(); jsgadget.init = function() { var output = document.getElementById('jsgadget_output_html'); var error = document.getElementById('jsgadget_error_html'); var setup = function(input_id, button_id, handler) { var input = document.getElementById(input_id).firstChild; var button = document.getElementById(button_id).firstChild; jsgadget.event(button, 'click', function(e) { if (!input.value) return; handler(input, output, error) }, false); }; setup('jsgadget_input_html', 'jsgadget_html_render_button', function(input, output, error) { output.innerHTML = input.value; gadgets.window.adjustHeight(); }); setup('jsgadget_input_javascript', 'jsgadget_javascript_render_button', function(input, output, error) { try { eval(input.value); error.innerHTML = ''; gadgets.window.adjustHeight(); } catch(e) { error.innerHTML = e; gadgets.window.adjustHeight(); } }); }; gadgets.util.registerOnLoadHandler(jsgadget.init); </script> <h1>JavaScriptãevalããããHTMLãã¬ã³ããªã³ã°ãããããã¬ã¸ã§ãã</h1> <p>ä¸ã®ããã¹ãããã¯ã¹ã«HTMLãå ¥åããHTMLæç»ãã¿ã³ãã¯ãªãã¯ããã¨ãã¬ã¸ã§ããä¸é¨ã®HTMLæç»ã¨ãªã¢ã«å ¥åããHTMLãæç»ããã¾ãã</p> <p>ä¸ã®ããã¹ãããã¯ã¹ã«JavaScriptã³ã¼ããå ¥åããJavaScriptå®è¡ãã¿ã³ãã¯ãªãã¯ããã¨ãå ¥åããJavaScriptã³ã¼ããå®è¡ããã¾ãã</p> <div id="jsgadget_input_html"><textarea rows="5" cols="55"></textarea></div> <div id="jsgadget_html_render_button"><input type="button" value="HTMLæç»" /></div> <div id="jsgadget_input_javascript"><textarea rows="3" cols="55"></textarea></div> <div id="jsgadget_javascript_render_button"><input type="button" value="JavaScriptå®è¡" /></div> <h2>HTMLæç»ã¨ãªã¢</h2> <div id="jsgadget_output_html"></div> <h2>ã¨ã©ã¼è¡¨ç¤ºã¨ãªã¢</h2> <div id="jsgadget_error_html"></div> ]]> </Content> </Module>
åç´ã«åä¸ã®HTMLãã¡ã¤ã«ã«HTMLãCSSãJavaScriptãè¨è¿°ãããããªæè¦ã§ä½¿ãã¾ãã*1
HTMLã使ããã®ã§ãé©å½ãªå ´æã«ãã¹ãã£ã³ã°ããJavaScriptã©ã¤ãã©ãªããã¼ãã§ããããJavaScriptã§ããªãã¦ãOKã£ã¦ã¨ããé åã§ãã
iGoogleã¬ã¸ã§ãã
æ´»ç¨æ¹æ³
åãã¯ãã¿ã¤ãã«ã©ãããã¯ã¦ãªãã¤ã¢ãªã¼ã§ãµã³ãã«ã³ã¼ããæ¸ããæã®å®è¡ç°å¢ã¨ãã¦ä½¿ã£ã¦ããããããªã¨æã£ã¦ä½ã£ããã§ãããFirebugçã®ãã¼ã«ã使ãæ £ãã¦ããªã人ã¯ããããiGoogleã«å ¥ãã¦JSéã³ããã¦ã¿ãã£ã¦ã®ãããããã¨æãã¾ãããä»ã«ã¯ãjQueryçã®ã©ã¤ãã©ãªãHTMLå´ã§èªã¿è¾¼ãã§ãã¹ããã¦ã¿ãã¨ããJavaScriptã®ãã¼ã¸ã§ã³æå®ããã¦æ°æ©è½ã使ã£ã¦ã¿ãã¨ãã®ä½¿ãæ¹ããããããªã®ã§ãå人çã«ãçµæ§ä½¿ãããã
element.getElementsByTagName('div')ã¨ãããæã«ãã¬ã¸ã§ããä¸ã«ããdivãæ°ã«å ¥ã£ã¦ãã¾ãã®ãã¡ãã£ã¨æ°ã«ãããªãç¹ã§ãã
æè§ãªã®ã§ããããæ©ã«mixiã¢ããªãããã£ã¦ã¿ãããã¨èãã¦ã¾ãã