Valerii Vasin (valerii) wrote in changelog,
Valerii Vasin
valerii
changelog

[livejournal] r23175: LJSUP-13824: Site message for unlogged u...

Committer: vvasin
LJSUP-13824: Site message for unlogged users must be shown by JS.
U   trunk/htdocs/js/basic.js
Modified: trunk/htdocs/js/basic.js
===================================================================
--- trunk/htdocs/js/basic.js	2012-10-19 13:45:26 UTC (rev 23174)
+++ trunk/htdocs/js/basic.js	2012-10-19 14:10:08 UTC (rev 23175)
@@ -143,7 +143,7 @@
 
 /**
  * Get a variable, defined especially for this page in the Site.page.
- * 
+ *
  * @param {string} name Variable name.
  * @param {boolean} global A flag to check, whether the variable is local to page or not.
  *
@@ -285,8 +285,8 @@
 };
 
 /**
- * Create function that will call target function at most once 
- * per every delay. Arguments are queued and when delay ends 
+ * Create function that will call target function at most once
+ * per every delay. Arguments are queued and when delay ends
  * function is called with last supplied arguments set. Optionally
  * arguments queue can be preserved on call, so all sheduled will be done.
  *
@@ -326,7 +326,7 @@
 					lock = false;
 					batch = batchSize;
 					callback.call(caller);
-				}, delay); 
+				}, delay);
 
 				break;
 			}
@@ -348,7 +348,7 @@
 				batch = batchSize;
 			}
 		}
-	}; 
+	};
 
 	return threshold;
 };
@@ -678,11 +678,11 @@
 	var w = _window || window,
 		head = w.document.getElementsByTagName("head")[0],
 		cssNode = w.document.createElement('link');
-	
+
 	cssNode.type = 'text/css';
 	cssNode.rel = 'stylesheet';
 	cssNode.href = fileName;
-	
+
 	head.appendChild(cssNode);
 };
 
@@ -781,7 +781,7 @@
 	if (!node.nodeName) {
 		node = node.get(0);
 	}
-	
+
 	text = ( 'value' in node ? node.value : node.text ).replace(/\r/, ''),
 	length = text.length;
 
@@ -864,7 +864,7 @@
 		html;
 
 	if (!tmplObj) {
-		LJ.console.log('Warn: template ', name, ' was called but is not defined yet.'); 
+		LJ.console.log('Warn: template ', name, ' was called but is not defined yet.');
 		return jQuery();
 	}
 
@@ -890,7 +890,7 @@
 		if (LJ.UI._mixins.hasOwnProperty(name)) {
 			return LJ.UI._mixins[name];
 		} else {
-			LJ.console.log('Warn: Mixin ', name, ' was called but is not defined yet.'); 
+			LJ.console.log('Warn: Mixin ', name, ' was called but is not defined yet.');
 		}
 	} else {
 		LJ.UI._mixins[name] = module;
@@ -1002,7 +1002,7 @@
 	};
 
 	/**
-	 * Init widgets with specific entry point or all remaining 
+	 * Init widgets with specific entry point or all remaining
 	 *
 	 * @param {String} entryPoint Entry point name
 	 */
@@ -1034,7 +1034,7 @@
 					LJ.console.warn('Widget ' + widget.name + ' was not loaded');
 					continue;
 				}
-			} 
+			}
 		}
 	};
 }());
@@ -1273,7 +1273,7 @@
 
 		return bound;
 	},
-	
+
 	bindEventListener: function(object) {
 		var method = this; // Use double closure to work around IE 6 memory leak.
 		return function(e) {
@@ -1584,10 +1584,10 @@
 					res.push(val);
 			}
 		}
-		
+
 		return res;
 	},
-	
+
 	/**
 	 * Executes a provided function once per array element.
 	 *
@@ -1609,7 +1609,7 @@
 			}
 		}
 	},
-	
+
 	/**
 	 * Returns the first index at which a given element can be found in the array,
 	 * or -1 if it is not present.
@@ -1632,7 +1632,7 @@
 		}
 
 		var len = this.length >>> 0;
-		
+
 		var from = Number(arguments[1]) || 0;
 		from = from < 0
 				? Math.ceil(from)
@@ -1647,7 +1647,7 @@
 		}
 		return -1;
 	},
-	
+
 	/**
 	 * Returns the last index at which a given element can be found in the array,
 	 * or -1 if it is not present. The array is searched backwards, starting at fromIndex.
@@ -1659,7 +1659,7 @@
 	 *     searched. If negative, it is taken as the offset from the end of the array.
 	 *     Note that even when the index is negative, the array is still searched from
 	 *     back to front. If the calculated index is less than 0, -1 is returned, i.e.
-	 *     the array will not be searched. 
+	 *     the array will not be searched.
 	 *
 	 * @return {Number} Array index.
 	 */
@@ -1669,7 +1669,7 @@
 		if (len === 1) {
 			return -1;
 		}
-		
+
 		var from = Number(arguments[1]);
 
 		if (arguments.length === 1) {
@@ -1692,7 +1692,7 @@
 				}
 			}
 		}
-		
+
 		for (; from > -1; from--) {
 			if (((from in this) || (len > from + 1 && this[from] === void 0)) && this[from] === elt) {
 				return from;
@@ -1818,7 +1818,7 @@
 	 */
 	reduce: function(accumulator/*, initial */) {
 		var i, l = Number(this.length), curr;
-		
+
 		if (typeof accumulator !== "function") { // ES5 : "If IsCallable(callbackfn) is false, throw a TypeError exception."
 			throw new TypeError("First argument is not callable");
 		}
@@ -1834,20 +1834,20 @@
 		if (l === null && (arguments.length <= 1)) {// == on purpose to test 0 and false.
 			throw new TypeError("Array length is 0 and no second argument");
 		}
-		
+
 		if (arguments.length <= 1) {
 			curr = this[0]; // Increase i to start searching the secondly defined element in the array
 			i = 1; // start accumulating at the second element
 		} else {
 			curr = arguments[1];
 		}
-		
+
 		for (i = i || 0 ; i < l ; ++i) {
 			if(i in this) {
 				curr = accumulator.call(undefined, curr, this[i], i, this);
 			}
 		}
-		
+
 		return curr;
 	},
 
@@ -2326,3 +2326,63 @@
 		addCounter: addCounter
 	};
 }(jQuery));
+
+LJ.siteMessage = (function ($) {
+	'use strict';
+
+	var scheme = LJ.pageVar('scheme'),
+		messageSelector = '.appwidget-sitemessages',
+		selectors = {
+			lanzelot: { selector: '#main_body', method: 'before' },
+			horizon: { selector: '#big-content-wrapper', method: 'prepend' },
+			lynx: { selector: 'body', method: 'prepend' },
+
+			// for journal pages
+			journal: { selector: '#lj_controlstrip_new', method: 'after' }
+		},
+		// placeholder for methods to return
+		methods = null;
+
+	// we should run code only when document is ready and only for user
+	// that is not currently logged in
+	$(function () {
+		if (!Site.remoteUser) {
+			// wait for API initialization (inside of livejournal.js)
+			setTimeout(methods.get.bind(methods), 0);
+		}
+	});
+
+	methods = {
+		/**
+		 * Retrieve message from server and show it
+		 */
+		get: function () {
+			var that = this;
+
+			LJ.Api.call('sitemessage.get_message', {}, function (content) {
+				that.show(content);
+			});
+		},
+
+		/**
+		 * Show content as message
+		 * @param  {String} content Html representation of the message
+		 */
+		show: function (content) {
+			var type = selectors[ scheme ? scheme : 'journal' ];
+
+			// we should do nothing for this scheme yet
+			if (scheme === 'schemius') {
+				return;
+			}
+
+			// remove existed messages
+			$(messageSelector).remove();
+
+			// add message on the page
+			$(type.selector)[type.method](content);
+		}
+	};
+
+	return methods;
+}(jQuery));

Tags: invis89, js, livejournal, vvasin
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