Skip to content

Commit

Permalink
Themes are now cached using sessionStorage in browsers that support it.
Browse files Browse the repository at this point in the history
  • Loading branch information
meltingice committed Mar 16, 2010
1 parent 73f79be commit 681c976
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 11 deletions.
23 changes: 15 additions & 8 deletions osimo_editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ OsimoEditor.prototype.init = function(){

this.options.theme_path = this.options.editor_path + "themes/" + this.options.theme + "/";
this.template = '';
this.template_size = 0;
this.controls = new OsimoEditorControls();

this.injectCSS();
Expand All @@ -122,11 +123,14 @@ OsimoEditor.prototype.injectCSS = function(){
}

OsimoEditor.prototype.loadTheme = function(){
/*if(this.template == '' && window.sessionStorage){
if(sessionStorage.osimo_bbeditor_theme != null){
this.template = sessionStorage.osimo_bbeditor_theme;
if(this.template == '' && 'sessionStorage' in window){
var temp = window.sessionStorage.osimo_bbeditor_theme;
var temp_size = window.sessionStorage.osimo_bbeditor_theme_size;
if(temp != null && temp_size != null && temp_size > 0 && temp.length == temp_size){
this.template = temp;
this.template_size = temp_size;
}
}*/
}

if(this.template == ''){
var obj = this;
Expand All @@ -135,11 +139,14 @@ OsimoEditor.prototype.loadTheme = function(){
type:'POST',
url:obj.options.editor_path+"theme_loader.php",
data:postData,
dataType:'json',
success:function(data){
obj.template = data;
/*if(window.sessionStorage){
sessionStorage.osimo_bbeditor_theme = data;
}*/
obj.template = data.html;
obj.template_size = data.size;
if('sessionStorage' in window){
window.sessionStorage.osimo_bbeditor_theme = data.html;
window.sessionStorage.osimo_bbeditor_theme_size = data.size;
}
obj.buildEditor();
}
});
Expand Down
20 changes: 17 additions & 3 deletions theme_loader.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,11 @@
$path = pathinfo($_SERVER['PHP_SELF'],PATHINFO_DIRNAME);
define("THEMEPATH",$basepath.$path."/themes/".$_POST['theme']."/");

echo "<div class=\"osimo-editor\">";
include("themes/".$_POST['theme']."/template.php");
echo "</div>";
$html = "<div class=\"osimo-editor\">";
$html .= include_contents("themes/".$_POST['theme']."/template.php");
$html .= "</div>";

echo json_encode(array('html'=>$html,'size'=>strlen($html))); exit;
}

function getFontSelectorItems(){
Expand Down Expand Up @@ -71,4 +73,16 @@ function getColorPickerItems(){
}
}
}

function include_contents($filename){
if (is_file($filename)) {
ob_start();
include $filename;
$contents = ob_get_contents();
ob_end_clean();
return $contents;
}

return false;
}
?>

0 comments on commit 681c976

Please sign in to comment.