Prechádzať zdrojové kódy

Added templating cache types

Nathaniel van Diepen 10 rokov pred
rodič
commit
6d1fb3ae8e
3 zmenil súbory, kde vykonal 34 pridanie a 19 odobranie
  1. 16 5
      api.php
  2. 2 2
      data/topbars/default.template
  3. 16 12
      js/index.js

+ 16 - 5
api.php

@@ -9,7 +9,10 @@
 			switch($_GET['type']){
 				case 'user':
 					back(true);
-					$ret['template'] = 'user';
+					$ret['template'] = array(
+						'type'=>'pages',
+						'name'=>'user'
+					);
 					if($user = userObj($id)){
 						$context = array(
 							'name'=>$user['name'],
@@ -65,7 +68,10 @@
 				break;
 				case 'project':
 					back(true);
-					$ret['template'] = 'project';
+					$ret['template'] = array(
+						'type'=>'pages',
+						'name'=>'project'
+					);
 					if($context = projectObj($id)){
 						$context['user'] = userObj($context['user']);
 						if($LOGGEDIN){
@@ -107,7 +113,10 @@
 					$title = $id;
 					if(file_exists(PATH_DATA.'pages/'.$id.'.template')){
 						$context = array();
-						$ret['template'] = $id;
+						$ret['template'] = array(
+							'type'=>'pages',
+							'name'=>$id
+						);
 						if($LOGGEDIN){
 							$context['key'] = true;
 							$context['user'] = userObj($_SESSION['username']);
@@ -173,7 +182,8 @@
 								}
 							}
 							retj(array(
-								'manifest'=>$manifest
+								'manifest'=>$manifest,
+								'type'=>$_GET['id']
 							));
 						}else{
 							retj(array(
@@ -186,7 +196,8 @@
 					if(isset($_GET['name'])){
 						retj(array(
 							'template'=>file_get_contents(PATH_DATA.'/'.$_GET['id'].'/'.$_GET['name'].'.template'),
-							'name'=>$_GET['name']
+							'name'=>$_GET['name'],
+							'type'=>$_GET['id']
 						));
 					}else{
 						retj(array(

+ 2 - 2
data/topbars/default.template

@@ -7,8 +7,8 @@
 		🔙	Arrow with back under
 -->
 <div class="topbar-left">
-	<a class="topbar-home menuitem" href="#page-index">
-		<span class="screen-small" style="background-image:url(img/headers/icons/menu.png);background-repeat:no-repeat;height:50px;background-position:center;"></span>
+	<a class="topbar-home menuitem" href="#page-index" style="min-width: 20px;">
+		<span class="screen-small" style="background-image:url(img/headers/icons/menu.png);background-repeat:no-repeat;height:50px;background-position:center;margin-left:-10px;"></span>
 	</a>
 	<a href="#page-messages" class="topbar-notifications menuitem screen-small"></a>
 	{{#if key}}

+ 16 - 12
js/index.js

@@ -41,16 +41,16 @@
 		getKey = window.getKey = function(){
 			return Key;
 		},
-		template = window.template = function(name,template){
+		template = window.template = function(type,name,template){
 			var d = +new Date,
-				id = (function(name){
+				id = (function(type,name){
 					for(var i in templates){
-						if(templates[i].name == name){
+						if(templates[i].name == name && templates[i].type == type){
 							return i;
 						}
 					}
 					return false;
-				})(name);
+				})(type,name);
 			if(exists(template)){
 				if(template === null){
 					if(id!==false){
@@ -63,7 +63,8 @@
 					var o = {
 						name: name,
 						template: template,
-						date: get('expire')+d
+						type: type,
+						date: Number(get('expire'))+Number(d)
 					}
 					if(id===false){
 						console.log('Storing new template for: '+name);
@@ -83,7 +84,7 @@
 				}
 				return template;
 			}else{
-				console.log('No cached template stored for: '+name);
+				console.log('No cached template stored for: '+type+':'+name);
 				return '';
 			}
 		},
@@ -244,8 +245,8 @@
 									}
 									render.topbar(d.topbar.template,d.topbar.context);
 									if(exists(d.template)){
-										console.log('Using template: '+d.template);
-										d.template = template(d.template);
+										console.log('Using template: '+d.template.type+':'+d.template.name);
+										d.template = template(d.template.type,d.template.name);
 										render.content(d.template,d.context);
 									}else{
 										console.log('No template used');
@@ -639,16 +640,17 @@
 				}
 			}
 		},
-		getTemplates = window.getTemplates = function(callback){
+		getTemplates = function(callback){
 			$.get('api.php',{
 					type: 'manifest',
 					id: 'pages'
 				},function(d){
 				if(!exists(d.error)){
-					var count = d.manifest.length;
+					var count = d.manifest.length,
+						m = +new Date;
 					for(var i in d.manifest){
 						console.log('Loading template('+(Number(i)+1)+'/'+d.manifest.length+'): '+d.manifest[i]);
-						if(template(d.manifest[i]) === ''){
+						if(template('pages',d.manifest[i]) === ''){
 							$.get('api.php',{
 								type: 'template',
 								id: 'pages',
@@ -656,7 +658,9 @@
 							},function(d){
 								templates.push({
 									name: d.name,
-									template: d.template
+									template: d.template,
+									type: d.type,
+									date: Number(get('expire'))+Number(m)
 								});
 								$.localStorage('templates',templates);
 								count--;