Committer: dpetrov
LJSUP-10691: Image placeholders in commentsU trunk/htdocs/js/journal.js U trunk/htdocs/js/livejournal.js
Modified: trunk/htdocs/js/journal.js =================================================================== --- trunk/htdocs/js/journal.js 2012-02-17 07:56:55 UTC (rev 21206) +++ trunk/htdocs/js/journal.js 2012-02-17 08:02:19 UTC (rev 21207) @@ -260,48 +260,3 @@ } ); } )(); -/** - * we handle img placeholders on friends page and entry page - */ -(function($) { - var placeholders = [ - { - selector: '.b-mediaplaceholder-photo', - loading: 'b-mediaplaceholder-processing', - init: function() { - var self = this; - doc.on('click', this.selector, function(ev) { - self.handler(this, ev); - }); - }, - - handler: function(el, ev) { - var im = new Image(); - - im.onload = im.onerror = jQuery.delayedCallback(this.imgLoaded.bind(this, el, im), 500); - im.src = el.href; - el.className += ' ' + this.loading; - ev.preventDefault(); - }, - - imgLoaded: function(el, image) { - var img = jQuery('<img />').attr('src', image.src), - href = el.getAttribute('data-href'); - - if (href && href.length > 0) { - img = jQuery('<a>', { href: href }).append(img); - } - - jQuery(el).replaceWith(img); - } - } - ], - doc = $(document); - - LiveJournal.register_hook('page_load', function init() { - placeholders.forEach(function(holder) { - holder.init(); - }); - }); -})(jQuery); - Modified: trunk/htdocs/js/livejournal.js =================================================================== --- trunk/htdocs/js/livejournal.js 2012-02-17 07:56:55 UTC (rev 21206) +++ trunk/htdocs/js/livejournal.js 2012-02-17 08:02:19 UTC (rev 21207) @@ -167,14 +167,56 @@ }; // Placeholder onclick event -LiveJournal.placeholderClick = function(link, html) -{ +LiveJournal.placeholderClick = function() { + var placeholders = { + image: { + selector: '.b-mediaplaceholder-photo', + loading: 'b-mediaplaceholder-processing', + init: function() { + var self = this; + doc.on('click', this.selector, function(ev) { + self.handler(this, ev); + }); + }, + + handler: function(el, html) { + var im = new Image(); + + im.onload = im.onerror = jQuery.delayedCallback(this.imgLoaded.bind(this, el, im), 500); + im.src = el.href; + el.className += ' ' + this.loading; + }, + + imgLoaded: function(el, image) { + var img = jQuery('<img />').attr('src', image.src), + $el = jQuery(el), + href = $el.data('href'); + + if (href && href.length > 0) { + img = jQuery('<a>', { href: href }).append(img); + $el.next('.b-mediaplaceholder-external').remove(); + } + + $el.replaceWith(img); + } + }, + + video: { + handler: function(link, html) { + link.parentNode.replaceChild(jQuery(unescape(html))[0], link); + } + } + }; // use replaceChild for no blink scroll effect - link.parentNode.parentNode.replaceChild(jQuery(unescape(html))[0], link.parentNode); - - return false -} + return function(el, html) { + var type = (html === 'image') ? html : 'video'; + + placeholders[type].handler(el, html); + return false; + } +}(); + // handy utilities to create elements with just text in them function _textSpan () { return _textElements("span", arguments); } function _textDiv () { return _textElements("div", arguments); } @@ -596,3 +638,4 @@ } return function() { return forceMobile || isMobile; } }(); +