public
Last active

TiddlySpaceBackstage.js

  • Download Gist
gistfile1.js
JavaScript
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425
/***
|''Name''|TiddlySpaceBackstage|
|''Version''|0.8.0|
|''Description''|Provides a TiddlySpace version of the backstage and a homeLink macro|
|''Status''|@@beta@@|
|''Contributors''|Jon Lister, Jon Robson, Colm Britton|
|''Source''|http://github.com/TiddlySpace/tiddlyspace/raw/master/src/plugins/TiddlySpaceBackstage.js|
|''Requires''|TiddlySpaceConfig ImageMacroPlugin TiddlySpaceViewTypes|
!StyleSheet
.tiddler .error.annotation .button{
display: inline-block;
}
 
#backstageArea {
z-index: 49;
color: white;
background-color: black;
background: -webkit-gradient(linear,left bottom,left top,color-stop(0, #222),color-stop(0.5, #333),color-stop(1, #555));
background: -moz-linear-gradient(center bottom,#222 0%, #333 50%, #555 100%);
filter: progid:DXImageTransform.Microsoft.gradient(startColorstr=#ff555555, endColorstr=#ff222222);
-ms-filter: "progid:DXImageTransform.Microsoft.gradient(startColorstr=#ff555555, endColorstr=#ff222222)";
height: 25px;
padding: 0;
}
 
#backstageButton {
overflow: hidden;
}
 
#backstageButton #backstageShow,
#backstageButton #backstageHide {
margin: 0px;
padding: 0px;
}
 
#backstageButton #backstageShow:hover,
#backstageButton #backstageHide:hover {
background: none;
color: none;
}
 
#backstageButton img,
#backstageButton svg {
width: 24px;
height: 24px;
}
 
#messageArea {
top: 50px;
}
 
#backstageToolbar {
position: relative;
}
 
#backstageArea a {
padding: 0px;
margin-left: 0px;
color: white;
background: none;
}
 
#backstageArea a:hover {
background-color: white;
}
 
#backstage ol,
#backstage ul {
padding: auto;
}
 
#backstageButton a {
margin: 0;
}
 
.backstagePanelBody ul {
padding: 5px;
margin: 5px;
}
 
#backstage #backstagePanel {
margin-left: 5%;
padding: 0em;
margin-right: 5%;
}
 
#backstageToolbar a {
position: relative;
}
 
#backstageArea a.backstageSelTab,
#backstageToolbar .backstageTask {
line-height: 25px;
color: #767676;
}
 
.backstageTask .externalImage,
.backstageTask .image {
display: inline;
}
 
#backstageToolbar a span {
z-index: 2;
}
 
a.backstageTask {
display: inline;
margin-left: 1em !important;
}
 
.backstagePanelBody .button {
display: inline-block;
margin-right: 10px;
}
 
.backstagePanelBody {
margin: 0 0 0 0.6em;
padding: 0.4em 0.5em 1px 0.5em;
}
 
#backstage table {
margin: auto;
}
 
#backstage .wizard table {
border: 0px;
margin: 0;
}
 
#backstage div li.listLink {
border: 0px;
width: 78%;
font-size: 0.7em;
}
 
#backstage div li.listTitle {
font-weight: bold;
text-decoration: underline;
font-size: 1em;
background: #ccc;
width: 100%;
}
 
#backstage fieldset {
border: solid 1px [[ColorPalette::Background]];
}
 
#backstage .viewer table,#backstage table.twtable {
border: 0px;
}
 
#backstageToolbar img {
padding: 0;
}
 
#backstage .wizard,
#backstage .wizardFooter {
background: none;
}
 
.viewer td, .viewer tr, .twtable td, .twtable tr {
border: 1px solid #eee;
}
 
#backstage .inlineList ul li {
background-color: [[ColorPalette::Background]];
border: solid 1px [[ColorPalette::TertiaryMid]];
display: block;
float: left;
list-style: none;
margin-right: 1em;
padding: 0.5em;
}
 
.backstageClear, .inlineList form {
clear: both;
display: block;
margin-top: 3em;
}
 
.tiddlyspaceMenu {
text-align: center;
}
 
span.chunkyButton {
display: inline-block;
padding: 0;
margin: 0;
border: solid 2px #000;
background-color: #04b;
}
 
span.chunkyButton a.button, span.chunkyButton a:active.button {
white-space: nowrap;
font-weight: bold;
font-size: 1.8em;
color: #fff;
text-align: center;
padding: 0.5em 0.5em;
margin: 0;
border-style: none;
display: block;
}
 
span.chunkyButton:hover {
background-color: #014;
}
 
span.chunkyButton a.button:hover {
border-style: none;
background: none;
color: #fff;
}
 
#backstage .unpluggedSpaceTab .wizard,
.unpluggedSpaceTab .wizard {
background: white;
border: 2px solid #CCC;
padding: 5px;
}
 
.syncKey .keyItem {
border: 1px solid black;
display: inline-block;
margin: 0.2em;
padding: 0.1em 0.1em 0.1em 0.1em;
}
 
.keyHeading {
font-size: 2em;
font-weight: bold;
margin: 0.4em 0em -0.2em;
}
 
.unpluggedSpaceTab .putToServer,
.unpluggedSpaceTab .notChanged {
display: none;
}
 
.tiddlyspaceMenu ul {
margin: 0;
padding: 0;
}
 
.tiddlyspaceMenu ul li {
list-style: none;
}
 
.unsyncedChanges .unsyncedList {
display: block;
}
 
.unsyncedList {
display: none;
}
!Code
***/
//{{{
(function($) {
var name = "StyleSheet" + tiddler.title;
config.shadowTiddlers[name] = "/*{{{*/\n%0\n/*}}}*/".
format(store.getTiddlerText(tiddler.title + "##StyleSheet")); // this accesses the StyleSheet section of the current tiddler (the plugin that contains it)
store.addNotification(name, refreshStyles);
 
if(!config.extensions.tiddlyweb.status.tiddlyspace_version) { // unplugged
config.extensions.tiddlyweb.status.tiddlyspace_version = "<unknown>";
config.extensions.tiddlyweb.status.server_host = {
url: config.extensions.tiddlyweb.host }; // TiddlySpaceLinkPlugin expects this
}
var disabled_tasks_for_nonmembers = ["tiddlers", "plugins", "batch", "sync"];
 
var tweb = config.extensions.tiddlyweb;
var tiddlyspace = config.extensions.tiddlyspace;
var currentSpace = tiddlyspace.currentSpace.name;
var imageMacro = config.macros.image;
 
if(config.options.chkBackstage === undefined) {
config.options.chkBackstage = false;
}
 
// Set up Backstage
config.tasks = {};
config.tasks.status = {
text: "status",
tooltip: "TiddlySpace Info",
content: "<<tiddler Backstage##Menu>>"
};
config.tasks.tiddlers = {
text: "tiddlers",
tooltip: "tiddlers control panel",
content: "<<tiddler Backstage##BackstageTiddlers>>"
};
config.tasks.plugins = {
text: "plugins",
tooltip: "Manage installed plugins",
content: "<<tiddler Backstage##Plugins>>"
};
config.tasks.batch = {
text: "batch",
tooltip: "Batch manage public/private tiddlers",
content: "<<tiddler Backstage##BatchOps>>"
};
config.tasks.tweaks = {
text: "tweaks",
tooltip: "Tweak TiddlyWiki behaviors",
content: "<<tiddler Backstage##Tweaks>>"
};
config.tasks.exportTiddlers = {
text: "import/export",
tooltip: "Import/export tiddlers from/to a TiddlyWiki",
content: "<<tiddler Backstage##ImportExport>>"
};
config.tasks.sync = {
text: "sync",
tooltip: "Check Sync status",
content: "<<tiddler Backstage##SpaceUnplugged>>"
};
 
if (window.location.protocol === "file:") {
config.unplugged = true;
}
 
config.backstageTasks = ["status", "tiddlers", "plugins",
"batch", "tweaks", "exportTiddlers", "sync"];
 
config.messages.backstage.prompt = "";
// initialize state
var _show = backstage.show;
backstage.show = function() {
// selectively hide backstage tasks and tabs based on user status
var tasks = $("#backstageToolbar .backstageTask").show();
var bs = backstage.tiddlyspace;
if(!config.unplugged) {
tweb.getUserInfo(function(user) {
if(user.anon) {
jQuery.each(disabled_tasks_for_nonmembers, function(i, task) {
var taskIndex = config.backstageTasks.indexOf(task);
if (taskIndex !== -1) {
config.backstageTasks.splice(taskIndex, 1);
}
});
config.messages.memberStatus = bs.locale.loggedout;
} else {
config.messages.memberStatus = readOnly ?
bs.locale.nonmember : bs.locale.member;
}
});
} else {
config.messages.memberStatus = bs.locale.unplugged;
}
 
// display backstage
return _show.apply(this, arguments);
};
if(readOnly) {
jQuery.each(disabled_tasks_for_nonmembers, function(i, task) {
var taskIndex = config.backstageTasks.indexOf(task);
if (taskIndex !== -1) {
config.backstageTasks.splice(taskIndex, 1);
}
});
}
 
var tasks = config.tasks;
var commonUrl = "/bags/common/tiddlers/%0";
 
backstage.tiddlyspace = {
locale: {
member: "You are a member of this space.",
nonmember: "You are not a member of this space.",
loggedout: "You are currently logged out of TiddlySpace.",
unplugged: "You are unplugged."
},
showButton: function() {
var showBtn = $("#backstageShow")[0];
var altText = $(showBtn).text();
$(showBtn).empty();
imageMacro.renderImage(showBtn, "backstage.svg",
{ altImage: commonUrl.format("backstage.png"), alt: altText});
},
hideButton: function() {
var hideBtn = $("#backstageHide")[0];
var altText = $(hideBtn).text();
$(hideBtn).empty();
imageMacro.renderImage(hideBtn, "close.svg",
{ altImage: commonUrl.format("close.png"), alt: altText, width: 24, height: 24 });
}
};
 
var _init = backstage.init;
backstage.init = function() {
_init.apply(this, arguments);
var init = function(user) {
var bs = backstage.tiddlyspace;
bs.showButton();
bs.hideButton();
};
tweb.getUserInfo(init);
};
 
var home = config.macros.homeLink = {
locale: {
linkText: "your home space"
},
handler: function(place) {
var container = $("<span />").appendTo(place)[0];
tweb.getUserInfo(function(user) {
if(!user.anon && user.name !== currentSpace) {
createSpaceLink(container, user.name, null, home.locale.linkText);
}
});
}
};
 
config.macros.exportSpace = {
handler: function(place, macroName, params) {
var filename = params[0] ||
"/tiddlers.wiki?download=%0.html".format(currentSpace);
$('<a class="button">download</a>'). // XXX: i18n
attr("href", filename).appendTo(place);
}
};
 
}(jQuery));
//}}}

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.