Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reload only if setting is modified #25

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion index.php
Expand Up @@ -144,7 +144,7 @@ public static function css() {
}
public static function js() {
$scripts = <<<'EOT'
<script>function nl2br(a){return(a+"").replace(/([^>\r\n]?)(\r\n|\n\r|\r|\n)/g,"$1<br>$2")}function fieldSave(a,b,c){$("#save").show(),$.post("",{fieldname:a,content:b,target:c},function(a){}).always(function(){window.location.reload()})}var changing=!1;$(document).ready(function(){$("span.editText").click(function(){changing||(a=$(this),title=a.attr("title")?title='"'+a.attr("title")+'" ':"",a.hasClass("editable")?a.html("<textarea "+title+' id="'+a.attr("id")+'_field" onblur="fieldSave(a.attr(\'id\'),this.value,a.data(\'target\'));">'+a.html()+"</textarea>"):a.html("<textarea "+title+' id="'+a.attr("id")+'_field" onblur="fieldSave(a.attr(\'id\'),nl2br(this.value),a.data(\'target\'));">'+a.html().replace(/<br>/gi,"\n")+"</textarea>"),a.children(":first").focus(),autosize($("textarea")),changing=!0)})});</script>
<script>function nl2br(t){return(t+"").replace(/([^>\r\n]?)(\r\n|\n\r|\r|\n)/g,"$1<br>$2")}function fieldSave(t,n,a){if(!(g_changing=g_saved!=n))return void $(this).parent().html(g_saved);$("#save").show(),$.post("",{fieldname:t,content:n,target:a},function(t){}).always(function(){window.location.reload()})}function onEdit(){if(!g_changing){var t=$(this),n=t.attr("title"),a=t.attr("id"),e=t.data("target"),i=t.hasClass("editable")?["",""]:["nl2br(",")"];g_saved=t.html(),n=n?'"'+n+'"':"",i=i.join("this.value");var r="fieldSave.call(this, "+["'"+a+"'",i,"'"+e+"'"].join(",")+")";t.html("<textarea "+n+' id="'+a+'_field" onblur="'+r+'">'+t.html()+"</textarea>"),t.children(":first").focus(),autosize($("textarea")),g_changing=!0}}function onReady(){$("span.editText").click(onEdit)}var g_changing=!1,g_saved="";$(document).ready(onReady);</script>
EOT;
return wCMS::_hook('js', $scripts)[0];
}
Expand Down
69 changes: 69 additions & 0 deletions jscss-source/css.css
@@ -0,0 +1,69 @@
#adminPanel{
background:#e5e5e5;
color:#aaa;
font-family:"Lucida Sans Unicode",Verdana;
font-size:14px;
}
#adminPanel a,.alert a{
color:#aaa;
border:0;
}
#adminPanel a.btn{
color:#fff;
}
#adminPanel span.editText{
color:#555;
}
span.editText{
border:2px dashed #ccc;
}
span.editText,.toggle{
display:block;
cursor:pointer;
}
span.editText textarea{
outline: 0;
border:none;
width:100%;
resize:none;
color:inherit;
font-size:inherit;
font-family:inherit;
background-color:transparent;
overflow:hidden;
box-sizing:content-box;
}
span.editText:empty{
min-height:20px;
}
#save{
color: #ccc;
left:0;
width:100%;
height:100%;
display:none;
position:fixed;
text-align:center;
padding-top:100px;
background:rgba(51,51,51,.8);
z-index:2448;
}
.change{
padding-left:15px;
}
.marginTop20{
margin-top:20px;
}
.padding20{
padding:20px;
}
.subTitle{
font-size:18px;
margin:10px 0 5px;
}
.fontSize24{
font-size:24px;
}
.note-editor{
border:2px dashed #ccc;
}
51 changes: 51 additions & 0 deletions jscss-source/js.js
@@ -0,0 +1,51 @@
var g_changing = false,
g_saved = '';

function nl2br(value) {
return (value + "").replace(/([^>\r\n]?)(\r\n|\n\r|\r|\n)/g, "$1<br>$2")
}

function fieldSave(id, value, dataTarget) {
g_changing = (g_saved!=value);
if (!g_changing){
$(this).parent().html(g_saved);
return
};
$("#save").show();

$.post(
"", { fieldname: id, content: value, target: dataTarget },
function(a) {}
).always(
function() {
window.location.reload();
}
)
}

function onEdit() {
if (g_changing) return;
var $this = $(this),
title = $this.attr('title'),
id = $this.attr('id'),
target= $this.data('target'),
value = $this.hasClass('editable') ? ["", ""] : ["nl2br(", ")"];

g_saved = $this.html();

title = title ? '"'+title+'"' : '';
value = value.join('this.value');

var fBlur = 'fieldSave.call(this, '+[ "'"+id+"'", value, "'"+target+"'"].join(',')+')';

$this.html('<textarea '+title+' id="'+id+'_field" onblur="'+fBlur+'">'+$this.html()+"</textarea>");
$this.children(":first").focus();
autosize($("textarea")),
g_changing = true;
}

function onReady() {
$("span.editText").click(onEdit);
}

$(document).ready(onReady);
2 changes: 1 addition & 1 deletion version
@@ -1 +1 @@
2.0.2
2.0.3