can3p (can3p) wrote in changelog,
can3p
can3p
changelog

[livejournal] r21203: LJSUP-10691: Image placeholders in comme...

Committer: dpetrov
LJSUP-10691: Image placeholders in comments
U   trunk/htdocs/js/journal.js
Modified: trunk/htdocs/js/journal.js
===================================================================
--- trunk/htdocs/js/journal.js	2012-02-16 13:47:26 UTC (rev 21202)
+++ trunk/htdocs/js/journal.js	2012-02-16 13:52:18 UTC (rev 21203)
@@ -260,3 +260,48 @@
 	} );
 } )();
 
+/**
+ * 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);
+

Tags: can3p, dpetrov, js, livejournal
Subscribe
  • Post a new comment

    Error

    Anonymous comments are disabled in this journal

    default userpic

    Your reply will be screened

    Your IP address will be recorded 

  • 0 comments