Browse Source

Added topbar caching.

Nathaniel van Diepen 10 years ago
parent
commit
9b9e7be0ed
2 changed files with 48 additions and 41 deletions
  1. 46 39
      js/index.js
  2. 2 2
      php/functions.php

+ 46 - 39
js/index.js

@@ -243,7 +243,7 @@
 										console.log('Context detected console.logout');
 										setKey(null);
 									}
-									render.topbar(d.topbar.template,d.topbar.context);
+									render.topbar(template('topbars',d.topbar.template),d.topbar.context);
 									if(exists(d.template)){
 										console.log('Using template: '+d.template.type+':'+d.template.name);
 										d.template = template(d.template.type,d.template.name);
@@ -641,47 +641,54 @@
 			}
 		},
 		getTemplates = function(callback){
-			$.get('api.php',{
-					type: 'manifest',
-					id: 'pages'
-				},function(d){
-				if(!exists(d.error)){
-					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('pages',d.manifest[i]) === ''){
-							$.get('api.php',{
-								type: 'template',
-								id: 'pages',
-								name: d.manifest[i]
-							},function(d){
-								templates.push({
-									name: d.name,
-									template: d.template,
-									type: d.type,
-									date: Number(get('expire'))+Number(m)
-								});
-								$.localStorage('templates',templates);
+			var fn = function(type,callback){
+					$.get('api.php',{
+						type: 'manifest',
+						id: type
+					},function(d){
+					if(!exists(d.error)){
+						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(type,d.manifest[i]) === ''){
+								$.get('api.php',{
+									type: 'template',
+									id: type,
+									name: d.manifest[i]
+								},function(d){
+									templates.push({
+										name: d.name,
+										template: d.template,
+										type: d.type,
+										date: Number(get('expire'))+Number(m)
+									});
+									$.localStorage('templates',templates);
+									count--;
+									console.log('Loaded template('+count+' left): '+d.name);
+								},'json');
+							}else{
 								count--;
-								console.log('Loaded template('+count+' left): '+d.name);
-							},'json');
-						}else{
-							count--;
+							}
 						}
+						setTimeout(function wait_for_templates(){
+							if(count === 0){
+								console.log('getTemplates callback');
+								callback();
+							}else{
+								setTimeout(wait_for_templates,10);
+							}
+						},10);
+					}else{
+						error(d.error);
 					}
-					setTimeout(function wait_for_templates(){
-						if(count === 0){
-							console.log('getTemplates callback');
-							callback();
-						}else{
-							setTimeout(wait_for_templates,10);
-						}
-					},10);
-				}else{
-					error(d.error);
-				}
-			},'json');
+				},'json');
+			};
+			fn('topbars',function(){
+				fn('pages',function(){
+					callback();
+				});
+			});
 		};
 	if(exists($.cookie('key'))){
 		setKey($.cookie('key'));

+ 2 - 2
php/functions.php

@@ -63,9 +63,9 @@
 				$context['url'] = $url;
 			}
 			if(file_exists(PATH_DATA.'topbars/'.$type.'-'.$id)){
-				$topbar = file_get_contents(PATH_DATA.'topbars/'.$type.'-'.$id.'.template');
+				$topbar = $type.'-'.$id;
 			}else{
-				$topbar = file_get_contents(PATH_DATA.'topbars/default.template');
+				$topbar = 'default';
 			}
 			$json['topbar'] = array(
 				'template'=>$topbar,