Browse Source

UI changes. Back button fix.

Nathaniel van Diepen 11 years ago
parent
commit
0bcb1bb237
4 changed files with 58 additions and 30 deletions
  1. 9 0
      css/style.css
  2. 3 3
      data/pages/topbar.template
  3. 1 1
      index.php
  4. 45 26
      js/index.js

+ 9 - 0
css/style.css

@@ -147,6 +147,12 @@ div#loading{
 .top{
 	z-index: 2147483638;
 }
+.overflow-hide{
+	overflow: hidden;
+}
+#topbar.overflow-hide{
+	max-height: 50px;
+}
 @media screen and (max-width: 767px){
 	div#topbar a.menuitem:not(.topbar-home){
 		padding-left: 5px;
@@ -158,6 +164,9 @@ div#loading{
 	a.topbar-home{
 		padding: 0;
 	}
+	a.topbar-current{
+		max-width: 205px;
+	}
 	div.topbar-left a.topbar-current{
 		float: right !important;
 	}

+ 3 - 3
data/pages/topbar.template

@@ -41,6 +41,9 @@
 		<div style="background-image:url(img/headers/icons/back.png);background-repeat:no-repeat;background-position:center;width:35px;height:50px;"></div>
 	</a>
 	<a class="topbar-current menuitem" href="#{{url}}">
+		<div style="background-image:url(img/headers/icons/update.png);background-repeat:no-repeat;height:50px;background-position:center;width:35px;float:left;"></div>
+	</a>
+	<a class="topbar-current menuitem">
 		{{title}}
 	</a>
 </div>
@@ -48,9 +51,6 @@
 	<a class="topbar-back menuitem" href="#{{url}}">
 		<div style="background-image:url(img/headers/icons/menu.png);background-repeat:no-repeat;height:50px;background-position:center;"></div>
 	</a>
-	<a class="topbar-current menuitem" href="#{{url}}">
-		{{title}}
-	</a>
 	{{#unless key}}
 		<a class="menuitem" href="#page-register">
 			Register

+ 1 - 1
index.php

@@ -114,7 +114,7 @@
 		<script src="js/index.js"></script>
 	</head>
 	<body lang="en">
-		<div id="topbar"></div>
+		<div id="topbar" class="overflow-hide"></div>
 		<div id="content" class="container"></div>
 		<div id="loading"></div>
 	</body>

+ 45 - 26
js/index.js

@@ -91,6 +91,7 @@
 			console.log('apiCall('+data.type+'-'+data.id+')');
 			$('#loading').show();
 			data.get = 'api';
+			data.back = State.data.back;
 			data.timestamp = +new Date;
 			if(''!=template(data.type+'-'+data.id)){
 				data.template = false;
@@ -116,7 +117,8 @@
 			$('#loading').show();
 			var data = {
 				get:'state',
-				timestamp: +new Date
+				timestamp: +new Date,
+				back: location.href
 			};
 			ajax = $.ajax(href,{
 					data: data,
@@ -133,9 +135,11 @@
 						if(exists(callback)){
 							callback(d);
 						}
-						flag('handled',true);
-						stateChange();
-						flag('handled',false);
+						if(!exists(d['error'])){
+							flag('handled',true);
+							stateChange();
+							flag('handled',false);
+						}
 					},
 					error: function(x,t,e){
 						error({
@@ -155,7 +159,8 @@
 			$('#loading').show();
 			var data = {
 				get:'state',
-				timestamp: +new Date
+				timestamp: +new Date,
+				back: State.data.back
 			};
 			$.ajax(href,{
 					data: data,
@@ -172,9 +177,11 @@
 						if(exists(callback)){
 							callback(d);
 						}
-						flag('handled',true);
-						stateChange();
-						flag('handled',false);
+						if(!exists(d['error'])){
+							flag('handled',true);
+							stateChange();
+							flag('handled',false);
+						}
 					},
 					error: function(x,t,e){
 						error({
@@ -209,22 +216,29 @@
 				switch(State.data.type){
 					case 'page':case 'user':case 'project':
 						apiCall(State.data,function(d){
-							if(exists(d.context)){
-								if(!exists(d.context.key)&&Key!==null){
-									console.log('Context detected console.logout');
-									setKey(null);
-								}
-								if(exists(d.template)){
-									template(State.data.type+'-'+State.data.id,d.template);
+							if(!exists(d.error)){
+								if(exists(d.context)){
+									if(!exists(d.context.key)&&Key!==null){
+										console.log('Context detected console.logout');
+										setKey(null);
+									}
+									if(exists(d.template)){
+										template(State.data.type+'-'+State.data.id,d.template);
+									}else{
+										d.template = template(State.data.type+'-'+State.data.id);
+									}
+									render.topbar(d.topbar.template,d.topbar.context);
+									render.content(d.template,d.context);
+									$(window).resize();
+									$('#loading').hide();
 								}else{
-									d.template = template(State.data.type+'-'+State.data.id);
+									console.error('No context given');
+									if(!History.back()){
+										location.reload();
+									}
 								}
-								render.topbar(d.topbar.template,d.topbar.context);
-								render.content(d.template,d.context);
-								$(window).resize();
-								$('#loading').hide();
 							}else{
-								console.error('No context given');
+								error(d);
 								if(!History.back()){
 									location.reload();
 								}
@@ -264,6 +278,10 @@
 				render.links('#topbar');
 				render.buttons('#topbar');
 				render.menus('#topbar');
+				if(!State.data.back || State.url == location.origin+'/page-index'){
+					$('#topbar').find('.topbar-history').hide();
+				}
+				$('#topbar').addClass('overflow-hide');
 				$(window).resize();
 			},
 			content: function(t,c){
@@ -321,13 +339,13 @@
 							try{
 								if(($(this).hasClass('topbar-home') || $(this).hasClass('topbar-back'))&&$(window).width()<767){
 									$('#topbar').children('div.topbar-right,div.topbar-left').toggle();
+									$('#topbar').toggleClass('overflow-hide');
 									$(window).resize();
 								}else if($(this).hasClass('topbar-history')){
-									if(!History.back()){
-										console.log('Reloading on failed back');
+									if(State.data.back){
+										loadState(State.data.back);
+									}else if(!History.back()){
 										location.reload();
-									}else{
-										console.log('Going back');
 									}
 								}else{
 									loadState(href);
@@ -401,7 +419,8 @@
 		});
 		var data = {
 			get: 'settings',
-			timestamp: +new Date
+			timestamp: +new Date,
+			back: false
 		};
 		$.get(location.href,data,function(d){
 			settings = d;