can3p (can3p) wrote in changelog,
can3p
can3p
changelog

[livejournal] r19100: LJSUP-8848: Number is widget (autopost) ...

Committer: dpetrov
LJSUP-8848: Number is widget (autopost) should be dynamically connected to DB
U   trunk/htdocs/js/journal.js
Modified: trunk/htdocs/js/journal.js
===================================================================
--- trunk/htdocs/js/journal.js	2011-05-23 09:07:17 UTC (rev 19099)
+++ trunk/htdocs/js/journal.js	2011-05-23 09:15:52 UTC (rev 19100)
@@ -283,3 +283,47 @@
 		}
 	}
 });
+
+(function() {
+	var options = {
+		blockSelector: '.yota-contest'
+	};
+
+	function retrieveContestInfo( element ) {
+		var journal = element.attr( 'data-user' );
+		jQuery.getJSON( LiveJournal.getAjaxUrl( 'yota_widget_post' ),
+						{ json: 1, journal: journal }, function( answer ) {
+			if( 'collected' in answer ) {
+				var collected = answer.collected;
+				for( var i = 0; i < collected.length; i += 2 ) {
+					element.find( "." + collected[ i ] ).html( collected[ i + 1 ] );
+				}
+			}
+
+			if( 'rating' in answer ) {
+				i = 5;
+				var key;
+				while( --i > 0) {
+					key = "" + i;
+					if( key in answer.rating ) {
+						element.find( '.c' + i ).html( answer.rating[ key ] );
+					}
+				}
+			}
+		} );
+	}
+
+	function findElement( onload ) {
+		var element = jQuery( options.blockSelector );
+
+		if( element.length ) {
+			retrieveContestInfo( element );
+		} else if( !onload ) {
+			jQuery( function() {
+				findElement( true );
+			} );
+		}
+	}
+
+	setTimeout( findElement, 0 );
+} )();

Tags: can3p, 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