can3p (can3p) wrote in changelog,
can3p
can3p
changelog

[livejournal] r21948: LJSUP-12165: Mobile improvement for cont...

Committer: dpetrov
LJSUP-12165: Mobile improvement for contextual hover menu
U   trunk/htdocs/js/basic.js
U   trunk/htdocs/js/contextualhover.js
Modified: trunk/htdocs/js/basic.js
===================================================================
--- trunk/htdocs/js/basic.js	2012-05-14 12:12:06 UTC (rev 21947)
+++ trunk/htdocs/js/basic.js	2012-05-14 13:21:13 UTC (rev 21948)
@@ -422,10 +422,14 @@
 
 /**
  * @namespace LJ.Support The namespace should contain variables to check whether some funcionality is availible in the current browser.
+ * If this part will become hige enough, we should switch to modernizr.
+ * All fields should have the same names as in modernizr
  */
 LJ.Support = LJ.Support || {};
 
 LJ.Support.geoLocation = 'geolocation' in navigator;
+//Incomplete implementation from modernizr
+LJ.Support.touch = ('ontouchstart' in window) || window.DocumentTouch && document instanceof DocumentTouch;
 
 
 /* object extensions */

Modified: trunk/htdocs/js/contextualhover.js
===================================================================
--- trunk/htdocs/js/contextualhover.js	2012-05-14 12:12:06 UTC (rev 21947)
+++ trunk/htdocs/js/contextualhover.js	2012-05-14 13:21:13 UTC (rev 21948)
@@ -130,20 +130,25 @@
 		},
 		templates: {
 			wrapper: '<div class="b-contextualhover"></div>',
-			loading: 'Loading...',
-			content: ''
+			content: 'templates-Widgets-contextualhover',
+			loading: 'Loading...'
 		},
 
 		init: function() {
 			var wrapper = jQuery(this.templates.wrapper),
 				self = this;
 
+			this._visible = false;
+
 			this.element = jQuery(wrapper).bubble({
-				// showDelay: 500,
+				alwaysShowUnderTarget: true,
 				closeControl: false,
-				// showOn: 'hover',
+				show: function() {
+					ContextualPopup._visible = true;
+				},
 				hide: function() {
 					ContextualPopup.hideHourglass();
+					ContextualPopup._visible = false;
 				},
 				classNames: {
 					containerAddClass: this.classNames.popup
@@ -441,13 +446,13 @@
 
 
 			buildObject.socialCap = {
-                first: !!data.first
-            }
-            if (data.value) buildObject.socialCap.value = data.value;
+				first: !!data.first
+			}
+			if (data.value) buildObject.socialCap.value = data.value;
 
 			this.element
 				.empty()
-				.append(LJ.UI.template('templates-Widgets-contextualhover', buildObject));
+				.append(LJ.UI.template(this.templates.content, buildObject));
 
 			if (this.element.is(':visible')) {
 				//show method forces bubble to reposition with respect to the new content
@@ -508,9 +513,15 @@
 			if (!Site.ctx_popup) return;
 
 			popup.init();
-			jQuery(document.body)
+			var body = jQuery(document.body);
+
+			body
 				.mouseover(ContextualPopup.mouseOver)
 				.ljAddContextualPopup();
+
+			if (LJ.Support.touch) {
+				body.on('click', ContextualPopup.touchStart);
+			}
 		},
 
 		/**
@@ -559,7 +570,7 @@
 			}
 		},
 
-		mouseOver: function(e) {
+		activate: function(e) {
 			var target = e.target,
 				ctxPopupId = target.username || target.userid || target.up_url,
 				t = ContextualPopup;
@@ -581,9 +592,28 @@
 				} else {
 					popup.show();
 				}
+
+				return true;
 			}
+
+			return false;
 		},
 
+		mouseOver: function(e) {
+			ContextualPopup.activate(e);
+		},
+
+		touchStart: function(e) {
+			var current = ContextualPopup.currentElement;
+
+			//if popup is activated then currentElement property is rewriten somewhere inside the activate
+			//function and this condition works;
+			if (ContextualPopup.activate(e) && (!ContextualPopup._visible || current !== ContextualPopup.currentElement)) {
+				e.preventDefault();
+				e.stopPropagation();
+			}
+		},
+
 		showPopup: function(ctxPopupId, ele) {
 			var showNow = popup.element.is(':visible');
 

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