Implemented first basic version of layout option for switching display of skin edit controls, ie. a button that appears next to every editable skin and directly leads to the skin editor when clicked.
This commit is contained in:
parent
99b771f8af
commit
b21d98211e
9 changed files with 154 additions and 15 deletions
|
@ -25,9 +25,14 @@ $(function() {
|
||||||
...
|
...
|
||||||
<% layout.link images <% gettext Images %> %>
|
<% layout.link images <% gettext Images %> %>
|
||||||
<% layout.link skins <% gettext Skins %> prefix=" | " %>
|
<% layout.link skins <% gettext Skins %> prefix=" | " %>
|
||||||
|
<% //layout.link sandbox <% gettext Sandbox %> prefix=" | " %>
|
||||||
<br /><br />
|
<br /><br />
|
||||||
<form id="prefs" method="post" action="<% response.action %>">
|
<form id="prefs" method="post" action="<% response.action %>">
|
||||||
<table border="0" cellspacing="0" cellpadding="2">
|
<table border="0" cellspacing="0" cellpadding="2">
|
||||||
|
<tr>
|
||||||
|
<td class='small'>Show Controls:</td>
|
||||||
|
<td><input name='sandbox' type='checkbox' <% if <% layout.sandbox %> is true then checked %>></td>
|
||||||
|
</tr>
|
||||||
<% layout.values %>
|
<% layout.values %>
|
||||||
<tr id="addValueFields">
|
<tr id="addValueFields">
|
||||||
<td id="newKey" class="small"></td>
|
<td id="newKey" class="small"></td>
|
||||||
|
|
|
@ -93,6 +93,22 @@ Layout.remove = function(options) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Layout.sandbox = function(value) {
|
||||||
|
var cookie = User.COOKIE + 'LayoutSandbox';
|
||||||
|
var id = res.handlers.site._id;
|
||||||
|
if (typeof value === 'undefined') {
|
||||||
|
return req.cookies[cookie] === id;
|
||||||
|
}
|
||||||
|
if (value === true) {
|
||||||
|
res.setCookie(cookie, id);
|
||||||
|
//session.data.layout = new Layout;
|
||||||
|
} else if (value === false) {
|
||||||
|
res.unsetCookie(cookie);
|
||||||
|
//delete session.data.layout;
|
||||||
|
}
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @function
|
* @function
|
||||||
* @returns {String[]}
|
* @returns {String[]}
|
||||||
|
@ -140,6 +156,7 @@ Layout.prototype.getPermission = function(action) {
|
||||||
case "import":
|
case "import":
|
||||||
case "reset":
|
case "reset":
|
||||||
case "skins":
|
case "skins":
|
||||||
|
case "sandbox":
|
||||||
return res.handlers.site.getPermission("main") &&
|
return res.handlers.site.getPermission("main") &&
|
||||||
Membership.require(Membership.OWNER) ||
|
Membership.require(Membership.OWNER) ||
|
||||||
User.require(User.PRIVILEGED);
|
User.require(User.PRIVILEGED);
|
||||||
|
@ -216,6 +233,9 @@ Layout.prototype.update = function(data) {
|
||||||
}
|
}
|
||||||
res.write("\n");
|
res.write("\n");
|
||||||
skin.setSource(res.pop());
|
skin.setSource(res.pop());
|
||||||
|
|
||||||
|
Layout.sandbox(!!data.sandbox);
|
||||||
|
|
||||||
this.description = data.description;
|
this.description = data.description;
|
||||||
this.mode = data.mode;
|
this.mode = data.mode;
|
||||||
this.touch();
|
this.touch();
|
||||||
|
@ -297,6 +317,17 @@ Layout.prototype.import_action = function() {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Layout.prototype.sandbox_action = function() {
|
||||||
|
Layout.sandbox(!Layout.sandbox());
|
||||||
|
res.redirect(req.data.http_referer);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
Layout.prototype.sandbox_macro = function() {
|
||||||
|
res.write(Layout.sandbox());
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @param {String} name
|
* @param {String} name
|
||||||
|
|
|
@ -274,6 +274,22 @@ div.skin div.title {
|
||||||
border: 1px solid #cc0000;
|
border: 1px solid #cc0000;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.layout-sandbox {
|
||||||
|
height: 22px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.layout-sandbox div {
|
||||||
|
position: fixed;
|
||||||
|
top: 0;
|
||||||
|
left: 0;
|
||||||
|
right: 0;
|
||||||
|
height: 22px;
|
||||||
|
padding: 0 20px;
|
||||||
|
background: url('<% root.static sandbox.png %>');
|
||||||
|
background-position: 0 23px;
|
||||||
|
text-align: left;
|
||||||
|
}
|
||||||
|
|
||||||
<% #FIXME %>
|
<% #FIXME %>
|
||||||
<div class="boxline"> </div>
|
<div class="boxline"> </div>
|
||||||
<div class="box">
|
<div class="box">
|
||||||
|
|
|
@ -191,6 +191,7 @@ Root.prototype.sites_action = function() {
|
||||||
}
|
}
|
||||||
|
|
||||||
Root.prototype.updates_xml_action = function() {
|
Root.prototype.updates_xml_action = function() {
|
||||||
|
res.contentType = "text/xml";
|
||||||
var now = new Date;
|
var now = new Date;
|
||||||
var feed = new rome.SyndFeedImpl();
|
var feed = new rome.SyndFeedImpl();
|
||||||
feed.setFeedType("rss_2.0");
|
feed.setFeedType("rss_2.0");
|
||||||
|
@ -219,7 +220,6 @@ Root.prototype.updates_xml_action = function() {
|
||||||
var output = new rome.SyndFeedOutput();
|
var output = new rome.SyndFeedOutput();
|
||||||
//output.output(feed, res.servletResponse.writer); return;
|
//output.output(feed, res.servletResponse.writer); return;
|
||||||
var xml = output.outputString(feed);
|
var xml = output.outputString(feed);
|
||||||
res.contentType = "text/xml";
|
|
||||||
res.write(xml); //injectXslDeclaration(xml));
|
res.write(xml); //injectXslDeclaration(xml));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
|
@ -407,8 +407,9 @@ Site.prototype.main_js_action = function() {
|
||||||
res.dependsOn(String(Root.VERSION));
|
res.dependsOn(String(Root.VERSION));
|
||||||
res.digest();
|
res.digest();
|
||||||
this.renderSkin("$Site#include",
|
this.renderSkin("$Site#include",
|
||||||
{href:"http://ajax.googleapis.com/ajax/libs/jquery/1.5/jquery.min.js"});
|
{href:"http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"});
|
||||||
this.renderSkin("$Site#include", {href: root.getStaticUrl("antville.js?v=1.3")});
|
this.renderSkin("$Site#include", {href: root.getStaticUrl("jquery.cookie.js")});
|
||||||
|
this.renderSkin("$Site#include", {href: root.getStaticUrl("antville.js?v=" + Root.VERSION)});
|
||||||
this.renderSkin("$Site#include", {href: this.href("user.js")});
|
this.renderSkin("$Site#include", {href: this.href("user.js")});
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -437,25 +438,25 @@ Site.prototype.backup_js_action = function() {
|
||||||
}
|
}
|
||||||
|
|
||||||
Site.prototype.rss_xml_action = function() {
|
Site.prototype.rss_xml_action = function() {
|
||||||
|
res.contentType = "text/xml";
|
||||||
res.dependsOn(this.modified);
|
res.dependsOn(this.modified);
|
||||||
res.digest();
|
res.digest();
|
||||||
res.contentType = "text/xml";
|
|
||||||
res.write(this.getXml(this.stories.union));
|
res.write(this.getXml(this.stories.union));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
Site.prototype.stories_xml_action = function() {
|
Site.prototype.stories_xml_action = function() {
|
||||||
|
res.contentType = "text/xml";
|
||||||
res.dependsOn(this.modified);
|
res.dependsOn(this.modified);
|
||||||
res.digest();
|
res.digest();
|
||||||
res.contentType = "text/xml";
|
|
||||||
res.write(this.getXml(this.stories.recent));
|
res.write(this.getXml(this.stories.recent));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
Site.prototype.comments_xml_action = function() {
|
Site.prototype.comments_xml_action = function() {
|
||||||
|
res.contentType = "text/xml";
|
||||||
res.dependsOn(this.modified);
|
res.dependsOn(this.modified);
|
||||||
res.digest();
|
res.digest();
|
||||||
res.contentType = "text/xml";
|
|
||||||
res.write(this.getXml(this.stories.comments));
|
res.write(this.getXml(this.stories.comments));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
|
@ -187,10 +187,7 @@ Skin.prototype.update = function(data) {
|
||||||
var macro = "response.body";
|
var macro = "response.body";
|
||||||
if (!createSkin(data.source).containsMacro(macro)) {
|
if (!createSkin(data.source).containsMacro(macro)) {
|
||||||
var macro = ["<code><%", macro, "%></code>"].join(String.EMPTY);
|
var macro = ["<code><%", macro, "%></code>"].join(String.EMPTY);
|
||||||
throw Error(gettext("The {0} macro is missing. It is essential for accessing the site and must be present in this skin.",
|
throw Error(gettext("The {0} macro is missing. It is essential for accessing the site and must be present in this skin.", macro));
|
||||||
macro));
|
|
||||||
//data.source = ["<% // ", gettext("The following macro was automatically added to prevent the site from becoming inacessible."),
|
|
||||||
// " %>\n<% ", macro, " %>\n\n", data.source].join(String.EMPTY);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
this.setSource(data.source);
|
this.setSource(data.source);
|
||||||
|
@ -221,7 +218,7 @@ Skin.prototype.reset_action = function() {
|
||||||
|
|
||||||
Skin.prototype.compare_action = function() {
|
Skin.prototype.compare_action = function() {
|
||||||
var originalSkin = this.source || String.EMPTY;
|
var originalSkin = this.source || String.EMPTY;
|
||||||
var diff = originalSkin.diff(this.getSource());
|
var diff = this.getSource().diff(originalSkin);
|
||||||
if (!diff) {
|
if (!diff) {
|
||||||
res.message = gettext("No differences were found.");
|
res.message = gettext("No differences were found.");
|
||||||
} else {
|
} else {
|
||||||
|
@ -230,7 +227,7 @@ Skin.prototype.compare_action = function() {
|
||||||
for each (let line in diff) {
|
for each (let line in diff) {
|
||||||
if (line.deleted) {
|
if (line.deleted) {
|
||||||
param.right = encode(line.value);
|
param.right = encode(line.value);
|
||||||
param.leftStatus = "removed";
|
param.leftStatus = "added";
|
||||||
param.rightStatus = '';
|
param.rightStatus = '';
|
||||||
for (let i=0; i<line.deleted.length; i++) {
|
for (let i=0; i<line.deleted.length; i++) {
|
||||||
leftLineNumber += 1;
|
leftLineNumber += 1;
|
||||||
|
@ -244,7 +241,7 @@ Skin.prototype.compare_action = function() {
|
||||||
if (line.inserted) {
|
if (line.inserted) {
|
||||||
param.left = encode(line.value);
|
param.left = encode(line.value);
|
||||||
param.leftStatus = '';
|
param.leftStatus = '';
|
||||||
param.rightStatus = 'added';
|
param.rightStatus = 'removed';
|
||||||
for (let i=0; i<line.inserted.length; i++) {
|
for (let i=0; i<line.inserted.length; i++) {
|
||||||
rightLineNumber += 1;
|
rightLineNumber += 1;
|
||||||
param.leftLineNumber = '';
|
param.leftLineNumber = '';
|
||||||
|
|
|
@ -268,8 +268,9 @@ User.login = function(data) {
|
||||||
*/
|
*/
|
||||||
User.logout = function() {
|
User.logout = function() {
|
||||||
session.logout();
|
session.logout();
|
||||||
res.setCookie(User.COOKIE, String.EMPTY);
|
res.unsetCookie(User.COOKIE);
|
||||||
res.setCookie(User.HASHCOOKIE, String.EMPTY);
|
res.unsetCookie(User.HASHCOOKIE);
|
||||||
|
Layout.sandbox(false);
|
||||||
User.getLocation();
|
User.getLocation();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,4 +1,8 @@
|
||||||
$(function() {
|
$(function() {
|
||||||
|
|
||||||
|
if ($.cookie('antvilleUserLayoutSandbox')) {
|
||||||
|
toggleLayoutMode();
|
||||||
|
}
|
||||||
|
|
||||||
// Extend jQuery with selectText() method.
|
// Extend jQuery with selectText() method.
|
||||||
$.fn.selectText = function() {
|
$.fn.selectText = function() {
|
||||||
|
@ -51,6 +55,43 @@ $(function() {
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
function toggleLayoutMode() {
|
||||||
|
if ($('.skin-control').length > 0) {
|
||||||
|
$('.skin-control').remove();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
/*$('body').prepend($('<div>').attr('class', 'layout-sandbox')
|
||||||
|
.append($('<div>')
|
||||||
|
.append($('<button>')
|
||||||
|
.html('Exit Sandbox')
|
||||||
|
.click(function() {
|
||||||
|
location.replace($('a[href$="sandbox"]').attr('href'));
|
||||||
|
}))));*/
|
||||||
|
$('.skin').each(function() {
|
||||||
|
var skinButton = $('<div><a>');
|
||||||
|
skinButton.css({
|
||||||
|
'margin-top': '5px',
|
||||||
|
font: 'bold 9px arial',
|
||||||
|
'line-height': '15px',
|
||||||
|
'letter-spacing': '1px'
|
||||||
|
}).find('a').attr({
|
||||||
|
'class': 'skin-control',
|
||||||
|
href: $(this).data('href'),
|
||||||
|
title: 'Click to edit ' + $(this).data('name') + ' skin'
|
||||||
|
}).css({
|
||||||
|
padding: '2px',
|
||||||
|
background: '#ccc',
|
||||||
|
color: '#fff',
|
||||||
|
'text-decoration': 'none'
|
||||||
|
}).mouseover(function() {
|
||||||
|
$(this).parents('.skin').eq(0).css('background-color', '#ccc');
|
||||||
|
}).mouseout(function() {
|
||||||
|
$(this).parents('.skin').eq(0).css('background-color', '');
|
||||||
|
}).html('Edit');
|
||||||
|
$(this).append(skinButton);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* MD5 (Message-Digest Algorithm)
|
* MD5 (Message-Digest Algorithm)
|
||||||
* http://www.webtoolkit.info/
|
* http://www.webtoolkit.info/
|
||||||
|
|
47
static/www/jquery.cookie.js
Normal file
47
static/www/jquery.cookie.js
Normal file
|
@ -0,0 +1,47 @@
|
||||||
|
/*!
|
||||||
|
* jQuery Cookie Plugin
|
||||||
|
* https://github.com/carhartl/jquery-cookie
|
||||||
|
*
|
||||||
|
* Copyright 2011, Klaus Hartl
|
||||||
|
* Dual licensed under the MIT or GPL Version 2 licenses.
|
||||||
|
* http://www.opensource.org/licenses/mit-license.php
|
||||||
|
* http://www.opensource.org/licenses/GPL-2.0
|
||||||
|
*/
|
||||||
|
(function($) {
|
||||||
|
$.cookie = function(key, value, options) {
|
||||||
|
|
||||||
|
// key and at least value given, set cookie...
|
||||||
|
if (arguments.length > 1 && (!/Object/.test(Object.prototype.toString.call(value)) || value === null || value === undefined)) {
|
||||||
|
options = $.extend({}, options);
|
||||||
|
|
||||||
|
if (value === null || value === undefined) {
|
||||||
|
options.expires = -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (typeof options.expires === 'number') {
|
||||||
|
var days = options.expires, t = options.expires = new Date();
|
||||||
|
t.setDate(t.getDate() + days);
|
||||||
|
}
|
||||||
|
|
||||||
|
value = String(value);
|
||||||
|
|
||||||
|
return (document.cookie = [
|
||||||
|
encodeURIComponent(key), '=', options.raw ? value : encodeURIComponent(value),
|
||||||
|
options.expires ? '; expires=' + options.expires.toUTCString() : '', // use expires attribute, max-age is not supported by IE
|
||||||
|
options.path ? '; path=' + options.path : '',
|
||||||
|
options.domain ? '; domain=' + options.domain : '',
|
||||||
|
options.secure ? '; secure' : ''
|
||||||
|
].join(''));
|
||||||
|
}
|
||||||
|
|
||||||
|
// key and possibly options given, get cookie...
|
||||||
|
options = value || {};
|
||||||
|
var decode = options.raw ? function(s) { return s; } : decodeURIComponent;
|
||||||
|
|
||||||
|
var pairs = document.cookie.split('; ');
|
||||||
|
for (var i = 0, pair; pair = pairs[i] && pairs[i].split('='); i++) {
|
||||||
|
if (decode(pair[0]) === key) return decode(pair[1] || ''); // IE saves cookies with empty string as "c; ", e.g. without "=" as opposed to EOMB, thus pair[1] may be undefined
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
};
|
||||||
|
})(jQuery);
|
Loading…
Add table
Reference in a new issue