Download - RubyからJavaScriptへ (!tDiary会議 2011)
http://sho.tdiary.net/20110607.html
JavaScript
2
JavaScript
http://sho.tdiary.net/20110716.html#p02
3
jQueryプラグインhttp://plugins.jquery.com/project/socialbutton
10
71 function socialbutton(target) { 72 $('.socialbuttons').css('height', '1em'); 73 $('.section', target).each(function() { 74 var url = $(this).children('h3').children('a').get(0).href; 75 var title = $(this).children('h3').children('a').attr('title'); 76 var socialbuttons = $(this).find('.socialbuttons'); 77 78 append_button(url, title, socialbuttons); 79 }); 80 } 81 82 function append_button(url, title, socialbuttons) { 83 $.each(config.enables, function(i, service) { 84 var options = callbacks[service](url, title.replace(/"/g, '"')); 85 $.extend(options, config.options[service]); 86 $('<div class="socialbutton"></div>') 87 .css("float", "left") 88 .css("margin-right", "0.5em") 89 .appendTo(socialbuttons) 90 .socialbutton(service, options); 91 }); 92 }
← これだけでおk
11
function socialbutton(target) { 72 $('.socialbuttons').css('height', '1em'); 73 $('.section', target).each(function() { 74 var url = $(this).children('h3').children('a').get(0).href; 75 var title = $(this).children('h3').children('a').attr('title'); 76 var socialbuttons = $(this).find('.socialbuttons'); 77 78 append_button(url, title, socialbuttons); 79 }); 80 } 81 82 function append_button(url, title, socialbuttons) { 83 $.each(config.enables, function(i, service) { 84 var options = callbacks[service](url, title.replace(/"/g, '"')); 85 $.extend(options, config.options[service]); 86 $('<div class="socialbutton"></div>') 87 .css("float", "left") 88 .css("margin-right", "0.5em") 89 .appendTo(socialbuttons) 90 .socialbutton(service, options); 91 }); 92 }
DOMから取得
14
$tDiaryでの値の受け渡し
Rubyプラグイン
(social_button.rb)
JavaScriptプラグイン
(social_button.js)
enable_js(‘social_button.js’)add_js_setting(’$tDiary.plugin.social_button’, “‘test’”)
$tDiary
x = $tDiary.plugin.social_button;
15
課題: JSONエスケープ
add_js_setting('$tDiary.plugin.socialbutton')
# convert array to jsonadd_js_setting('$tDiary.plugin.socialbutton.enables', %Q|["#{@conf['socialbutton.enables'].split(',').join('", "')}"]|)
options = "{ twitter: { via: '#{@conf['socialbutton.twitter.via']}' } }"
→ それto_jsonで(ry
16
jQueryの落とし穴
http://subtech.g.hatena.ne.jp/mala/20110624/1308881526
19
http://www.tdiary.org/doc/HOWTO-testing-tDiary.html23