Browse Source

API updates. Auto updates.

Nathaniel van Diepen 10 years ago
parent
commit
430e593f6a

+ 2 - 3
bugs.appcache

@@ -1,6 +1,4 @@
 CACHE MANIFEST
-# Version 2013-10-21 11:49am
-
 js/handlebars.js
 js/index.js
 js/jquery-ui.min.js
@@ -112,4 +110,5 @@ img/toolbars/ui/background.png
 NETWORK:
 *
 
-FALLBACK:
+FALLBACK:
+Version Sat, Oct 26, 2013 10:07:51 PM

+ 1 - 1
data/pages/index.template

@@ -13,7 +13,7 @@
 						// install the app
 						var installLocFind = navigator.mozApps.install(location.origin+'/bugs.webapp');
 						installLocFind.onsuccess = function(data){
-							apiState('page-index');
+							replaceState('page-index');
 						};
 						installLocFind.onerror = function(){
 							// App wasn't installed, info is in

+ 29 - 24
data/pages/login.template

@@ -1,4 +1,9 @@
-<form id="form">
+<script>
+	{{#if key}}
+		History.back();
+	{{/if}}
+</script>
+<form id="form" style="display:none;">
 	<div>
 		<input name="username" class="fill-width" placeholder="Username" id="login-username" type="text"/>
 	</div>
@@ -11,31 +16,31 @@
 	</div>
 </form>
 <script>
-	{{#if key}}
-		History.back();
-	{{else}}
-		$('form#form').submit(function(){
-			var data = $(this).serializeObject(),
-				State = History.getState();
-			for(var i in State.data){
-				data[i] = State.data;
-			}
-			data.type = 'action';
-			data.id = 'login';
-			apiCall(data,function(d){
-				if(!d.error){
-					setKey(d.key);
-					History.go(-1);
-				}else{
-					setKey(null);
-					$('#loading').hide();
+	{{#unless key}}
+		$(document).ready(function(){
+			$('form#form').show().submit(function(){
+				var data = $(this).serializeObject(),
+					State = History.getState();
+				for(var i in State.data){
+					data[i] = State.data;
 				}
+				data.type = 'action';
+				data.id = 'login';
+				apiCall(data,function(d){
+					if(!d.error){
+						setKey(d.key);
+						History.go(-1);
+					}else{
+						setKey(null);
+						$('#loading').hide();
+					}
+					return false;
+				});
+				return false;
+			}).find('.cancel').click(function(){
+				back();
 				return false;
 			});
-			return false;
-		}).find('.cancel').click(function(){
-			back();
-			return false;
 		});
-	{{/if}}
+	{{/unless}}
 </script>

+ 1 - 1
data/pages/logout.template

@@ -1,4 +1,4 @@
 <script>
 	setKey(null);
-	apiState('page-index');
+	replaceState('page-index');
 </script>

+ 9 - 6
data/pages/register.template

@@ -1,4 +1,9 @@
-<form id="form">
+<script>
+	{{#if key}}
+		History.back();
+	{{/if}}
+</script>
+<form id="form" style="display:none;">
 	<div>
 		<input name="email" class="fill-width" placeholder="Email" type="text"/>
 	</div>
@@ -21,16 +26,14 @@
 	</div>
 </form>
 <script>
-	{{#if key}}
-		replaceState('page-index');
-	{{else}}
+	{{#unless key}}
 		$(document).ready(function(){
 			var reloadCaptcha = function(){
 				$('#captcha').css('background-image','url(index.php?get=captcha&timestamp='+(+new Date)+')');
 				$('input[name=captcha]').val('');
 			};
 			reloadCaptcha();
-			$('form#form').submit(function(){
+			$('form#form').show().submit(function(){
 				var data = $(this).serializeObject(),
 						State = History.getState();
 					for(var i in State.data){
@@ -54,5 +57,5 @@
 				return false;
 			});
 		});
-	{{/if}}
+	{{/unless}}
 </script>

+ 1 - 0
data/version

@@ -0,0 +1 @@
+Sat, Oct 26, 2013 10:07:51 PM

+ 4 - 1
index.php

@@ -45,7 +45,10 @@
 				foreach($keys as $key){
 					$settings[$key] = get($key);
 				}
-				die(json_encode($settings));
+				die(json_encode(Array(
+					'settings'=>$settings,
+					'version'=>file_get_contents(PATH_DATA.'version');
+				)));
 			break;
 			case 'captcha':
 				generate_captcha();

+ 27 - 18
js/index.js

@@ -158,7 +158,7 @@
 				});
 			}
 		},
-		apiState = window.apiState = function(href,callback){
+		replaceState = window.replaceState = function(href,callback){
 			console.log('apiState('+href+')');
 			if(!flag('error')){
 				loading(true);
@@ -337,7 +337,8 @@
 			},
 			inputs: function(selector){
 				$(selector).find('input[type=text],input[type=password]').each(function(){
-					var input = $(this);
+					var input = $(this),
+						height = input.height()>=17?17:input.height();
 					input.siblings('.input-clear').remove();
 					input.after(
 						$('<div>').css({
@@ -346,12 +347,10 @@
 							top: input.position().top+2,
 							'background-image': 'url(img/headers/icons/clear.png)',
 							'background-position': 'center',
-							'background-size': '17px 17px',
-							'background-repeat': 'no repeat',
-							width: input.outerHeight(),
-							height: input.outerHeight(),
-							'max-width':  '17px',
-							'max-height': '17px',
+							'background-size': height+'px '+height+'px',
+							'background-repeat': 'no-repeat',
+							width: input.height(),
+							height: input.height(),
 							cursor: 'pointer'
 						}).addClass('input-clear').click(function(){
 							input.val('');
@@ -462,10 +461,6 @@
 		 $(document).ajaxError(function(event, request, settings) {
 			error({error:'Request timed out'});
 		});
-		templates = $.localStorage('templates');
-		if(templates === null){
-			templates = [];
-		}
 		if(!exists($.support.touch)){
 			$.support.touch = 'ontouchstart' in window || 'onmsgesturechange' in window;
 		}
@@ -488,16 +483,30 @@
 			}
 			$('#content').height($('body').height()-$('#topbar').height());
 			$('#content').getNiceScroll().resize();
-			render.form('#content');
+			render.inputs('#content');
+			render.inputs('#topbar');
 		});
-		var data = {
+		$.get(location.href,{
 			get: 'settings',
 			timestamp: +new Date,
 			back: false
-		};
-		$.get(location.href,data,function(d){
-			settings = d;
-			apiState(location.href);
+		},function(d){
+			if(!exists(d.error)){
+				settings = d.settings;
+				if(d.version != $.localStorage('version')){
+					$.localStorage('version',d.version);
+					$.localStorage('templates',null);
+					templates = [];
+				}else{
+					templates = $.localStorage('templates');
+					if(templates === null){
+						templates = [];
+					}
+				}
+				replaceState(location.href);
+			}else{
+				error(d.error);
+			}
 		},'json');
 		$(window).on('statechange',function(){
 			if(!flag('handled')){

+ 27 - 0
js/jquery.clearable.js

@@ -0,0 +1,27 @@
+jQuery.fn.clearable = function() {
+	$('.morelink').click(function(){
+		var $this = $(this);
+		if($this.hasClass('less')){
+			$this.removeClass('less');
+			$this.html(config.moreText);
+		}else{
+			$this.addClass('less');
+			$this.html(config.lessText);
+		}
+		$this.parent().prev().toggle();
+		$this.prev().toggle();
+		return false;
+	});
+	return this.each(function(){
+		$(this).css({'border-width': '0px', 'outline': 'none'})
+			.wrap('<div id="sq" class="divclearable"></div>')
+			.parent()
+			.attr('class', $(this).attr('class') + ' divclearable')
+			.append('<a class="clearlink" href="javascript:"></a>');
+		$('.clearlink')
+			.attr('title', 'Click to clear this textbox')
+			.click(function(){
+				$(this).prev().val('').focus();
+			});
+	});
+}

+ 3 - 0
update-version.sh

@@ -0,0 +1,3 @@
+#!/bin/bash
+date > data/version;
+sed -i -e "s/Version .*/Version $(date)/g" bugs.appcache