spacevillain (spacevillain) wrote in changelog,
spacevillain
spacevillain
changelog

[livejournal] r23058: LJSUP-13668: To implement JS for Journal...

Committer: atyurin
LJSUP-13668: To implement JS for Journal Promo blocks (S2 styles and S1 comments page)
U   trunk/htdocs/js/journal.js
Modified: trunk/htdocs/js/journal.js
===================================================================
--- trunk/htdocs/js/journal.js	2012-10-05 12:22:37 UTC (rev 23057)
+++ trunk/htdocs/js/journal.js	2012-10-05 15:40:04 UTC (rev 23058)
@@ -449,3 +449,82 @@
 	}
 	
 })();
+
+/*
+ * Handlers for info/delete buttons (journalpromo)
+ *
+ */
+(function($) {
+	'use strict';
+
+	var selectors = {
+		'popup': {
+			'info': '.journalpromo-popup-content-info',
+			'delete': '.journalpromo-popup-content:first'
+		},
+
+		'button': '#journalpromo-popup-btn',
+
+		'icon': {
+			'info': '.journalpromo-info-icon',
+			'delete': '.b-journalpromo-actions-delete',
+			'close': '.w-promostrip-actions-close'
+		},
+
+		'options': '.b-journalpromo-header-options',
+		'promoItem': '.b-journalpromo-item'
+	};
+
+	var template = "<dt><a href='{rules_link}'>{subject}</a> {ljuser}</dt><dd>{body}</dd>";
+
+	LiveJournal.register_hook('page_load', function() {
+		
+		var deleteBubble = $(selectors.popup['delete']).bubble({
+			target: selectors.icon['delete'],
+			showOn: 'click'
+		});
+
+		$(selectors.button).on('click', function() {
+			var that = this;
+
+			LJ.Api.call('journalpromo.admin_cancel', {
+				object_url: $(that).data('url'),
+				user: Site.currentJournal,
+				get_slot: 1,
+				ban_user: document.getElementById('journalpromo-user-ban').checked
+			}, function(result) {
+				if (!result.error && result.entry) {
+					var entry = result.entry[0];
+
+					if (!entry || !entry.object || !entry.object[0]) {
+						console.error('Wrong data', result);
+						return;
+					}
+
+					// re-render item and hide controls
+					jQuery(selectors.promoItem).html(
+						template.supplant({
+							'rules_link': entry.object[0].object_url,
+							'subject': entry.object[0].subject,
+							'body': entry.object[0].body,
+							'ljuser': entry.ljuser
+						})
+					);
+					$(selectors.options).hide();
+				}
+
+				deleteBubble.bubble('hide');
+			});
+		});
+
+		$(selectors.popup.info).bubble({
+			target: selectors.icon.info,
+			showOn: 'hover'
+		});
+
+		// promostrip close
+		$(selectors.icon.close).on('click', function() {
+
+		});
+	});
+})(jQuery);
\ No newline at end of file

Tags: atyurin, js, livejournal, spacevillain
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