何を*見?て-も何-か?思い.出す
$('.thing').each(function() { format($(this), $(this).text()) });
- http://ermos-tily.dotcloud.com/javascripts/jquery.js
- http://ermos-tily.dotcloud.com/javascripts/rails.js
- http://ermos-tily.dotcloud.com/javascripts/jquery.oembed.js
function keypress() { var prev = ''; return function() { var ab = $(this).attr('id'); if(prev != $(this).val()) { var input = $(this).val(); var thing = $('.thing-wrapper#' + ab + ' .thing'); format(thing, input); } prev = $(this).val(); }; }; function format(container, text) { if(text.match(/^https?:/)) { container.oembed(text, { embedMethod: 'fill', maxWidth: 460, maxHeight: 200, defaultOEmbedProvider: "none", afterEmbed: function(res, oembedData) { if(res.type == 'link' || res.type == 'error') { adjustFontSize(container.get(0)); } } }); } else { container.text(text); formatText(container); } }; // based on http://la.ma.la/misc/js/takahashi_oop.html function formatText(element) { var child = element.get(0); var parent = element.parent().get(0); with(child.style) { fontSize = "10px"; display = "inline"; } var parent_w = parent.offsetWidth; var parent_h = parent.offsetHeight; var child_w = child.offsetWidth; var new_fs = Math.ceil((parent_w/child_w) * 9); if(new_fs > 10000) { return } with(child.style) { fontSize = new_fs + "px"; } var child_h = child.offsetHeight; if(child_h > parent_h) { var new_fs = Math.ceil((parent_h/child_h) * new_fs * 0.85); with(child.style) { fontSize = new_fs + "px"; } } };
繋いだ2ページ目から画像や文字が展開されなかった。
(function () { document.addEventListener('DOMNodeInserted', function (evt) { var elm = evt.target; if (elm.className == 'item') { $('.thing', elm).each(function () { format($(this), $(this).text()) }); } }); })()
↓ 失敗作。
Bookmarklet起動する前に読み込んだヤツも展開しようと思ったら、すでに展開済みのヤツが真っ白になってしまった。ちょっとめんどうだからやめた。
(function () { var hoge = function (e) { $('.thing', e).each(function () { format($(this), $(this).text()); }); } hoge(document); document.addEventListener('DOMNodeInserted', function (evt) { var elm = evt.target; if (elm.className == 'item') { hoge(elm); } }); })()
jQuery 全然わかんないんだけどたぶん DOMNodeInserted 的なの何かあるに違いない
あと、コード片拾ってきて貼りあわせてなんかやるのやっぱり楽しいな
でも this がどこを指しているのかは全然わかっていない。結果オーライ
追記: oembed から embedly に変ってる
function format(container, text) { if (text.match(/^https?:/)) { container.html($('<a />').attr('href', text)); container.embedly({ key: 'd2b9b6464bf211e1ab1c4040d3dc5c07', method: 'after', maxWidth: 460, maxHeight: 200 }); } else { container.text(text); formatText(container); } };
><