← Back to team overview

nuvola-player-devel team mailing list archive

[Merge] lp:~mpdeimos/nuvola-player/bug-1212167 into lp:nuvola-player

 

mpdeimos has proposed merging lp:~mpdeimos/nuvola-player/bug-1212167 into lp:nuvola-player.

Requested reviews:
  Jiří Janoušek (fenryxo)

For more details, see:
https://code.launchpad.net/~mpdeimos/nuvola-player/bug-1212167/+merge/200249

Implements Bug #1212167: Back/forward buttons in UI (default off) for Google Play
-- 
https://code.launchpad.net/~mpdeimos/nuvola-player/bug-1212167/+merge/200249
Your team Nuvola Player Development is subscribed to branch lp:nuvola-player.
=== modified file 'data/nuvolaplayer/services/googleplay/integration.js'
--- data/nuvolaplayer/services/googleplay/integration.js	2013-12-23 18:26:42 +0000
+++ data/nuvolaplayer/services/googleplay/integration.js	2014-01-01 09:51:32 +0000
@@ -277,8 +277,81 @@
 			head.appendChild(style);
 		}
 		
+		if (Nuvola.config.navigationButtons === true)
+		{
+			this.addNavigationButtons();
+		}
+		
 		if (Nuvola.config.simulateActivity === true)
+		{
 			setTimeout(Nuvola.bind(this, this.simulateActivity), ACTIVITY_INTERVAL);
+		}
+	}
+	
+	Integration.prototype.addNavigationButtons = function(){
+		var queryBar = document.getElementById("gbq2");
+		if (!queryBar)
+		{
+			console.log("Could not find the query bar.");
+			return;
+		}
+		
+		var queryBarFirstChild = queryBar.firstChild;
+		
+		var navigateBack = Nuvola.makeElement("button", {disabled: true}, "<");
+		navigateBack.className = "button small vertical-align";
+		navigateBack.style.float = "left";
+		navigateBack.style.marginRight = "0px";
+		navigateBack.style.borderTopRightRadius = "2px";
+		navigateBack.style.borderBottomRightRadius = "2px";
+		navigateBack.addEventListener('click', function() {window.history.back();});
+		queryBar.insertBefore(navigateBack, queryBarFirstChild);
+		
+		var navigateFwd = Nuvola.makeElement("button", {disabled: true}, ">");
+		navigateFwd.className = "button small vertical-align";
+		navigateFwd.style.float = "left";
+		navigateFwd.style.marginRight = "15px";
+		navigateFwd.style.borderLeft = "none";
+		navigateFwd.style.borderTopLeftRadius = "2px";
+		navigateFwd.style.borderLeftRightRadius = "2px";
+		navigateFwd.addEventListener('click', function() {window.history.forward();});
+		queryBar.insertBefore(navigateFwd, queryBarFirstChild);
+		
+		var navigationStack = [];
+		var updateNavigationButtons = function(evt)
+		{
+			var pageIndex; // one-based
+			var found = false;
+			for (pageIndex = navigationStack.length; pageIndex > 0; pageIndex--)
+			{
+				var url = navigationStack[pageIndex - 1];
+				if (url === evt.newURL)
+				{
+					found = true;
+					break;
+				}
+			}
+			if (!found)
+			{
+				for (pageIndex = navigationStack.length; pageIndex > 0; pageIndex--)
+				{
+					var url = navigationStack[pageIndex - 1];
+					if (url === evt.oldURL)
+					{
+						// this means a new site is added to the top of the stack,
+						// and the rest can safely be removed.
+						navigationStack = navigationStack.slice(0, pageIndex);
+						navigationStack.push(evt.newURL);
+						pageIndex++; // advance to current page
+						break;
+					}
+				}
+			}
+			navigateBack.disabled = pageIndex == 1;
+			navigateFwd.disabled = pageIndex == navigationStack.length;
+		};
+		navigationStack.push(document.location.toString());
+		window.addEventListener('hashchange', updateNavigationButtons)
 	}
 	
 	Integration.prototype.simulateActivity = function(){

=== modified file 'data/nuvolaplayer/services/googleplay/settings.js'
--- data/nuvolaplayer/services/googleplay/settings.js	2012-07-31 13:46:59 +0000
+++ data/nuvolaplayer/services/googleplay/settings.js	2014-01-01 09:51:32 +0000
@@ -37,6 +37,15 @@
 	}
 ));
 
+form.append(new Nuvola.Checkbox(_("Integrate navigation buttons"),
+	Nuvola.config.navigationButtons === true,
+	function(){
+		Nuvola.config.navigationButtons = this.checked ? true : false;
+		Nuvola.saveConfig();
+		form.showReloadNotice();
+	}
+));
+
 form.append(new Nuvola.Checkbox(_("Don't stop playback due to inactivity"),
 	Nuvola.config.simulateActivity === true,
 	function(){


Follow ups