update assets location

This commit is contained in:
Henrique Dias
2016-06-16 17:08:10 +01:00
parent f9ae9f2619
commit 18afaeb093
23 changed files with 7 additions and 7 deletions

744
assets/src/css/main.css Normal file
View File

@@ -0,0 +1,744 @@
body {
font-family: 'Roboto', sans-serif;
color: #212121;
background-color: #fff;
height: 100%;
width: 100%;
padding-top: 3em;
}
* {
box-sizing: border-box;
}
a {
text-decoration: none;
color: #1976D2;
}
code {
border-radius: .2em;
}
img {
max-width: 100%;
}
h2 {
margin: .83em 0;
}
.container {
margin: 0 auto;
width: 95%;
max-width: 1000px;
}
.hidden {
display: none;
}
.left {
text-align: left;
}
.right {
text-align: right;
}
#content > header {
background-color: #00BCD4;
padding: 1px 0;
}
/* NAVIGATION */
body > nav {
position: fixed;
top: 0;
left: 0;
height: 3em;
width: 100%;
background-color: #1E88E5;
padding: 0 1em;
box-sizing: border-box;
z-index: 999;
color: #eee;
}
body > nav ul {
margin: 0;
padding: 0;
display: -webkit-box;
display: -ms-flexbox;
display: -webkit-flex;
display: flex;
}
body > nav ul li {
list-style-type: none;
display: inline-block;
vertical-align: middle;
}
body > nav ul li:first-child a {
margin-left: -0.5em;
}
body > nav ul li:last-child a {
margin-right: -0.5em;
}
body > nav ul li:last-child {
margin-left: auto;
}
body > nav img {
height: 2em;
}
body > nav ul li a {
padding: .5em;
line-height: 2em;
display: block;
text-decoration: none;
color: inherit;
-webkit-transition: .5s ease background-color;
transition: .5s ease background-color;
}
body > nav ul li a:hover {
background-color: rgba(0, 0, 0, 0.1);
}
/* FOOTER */
body > footer {
background-color: #f5f5f5;
text-align: center;
padding: 1em 0;
margin-top: 1em;
}
body > footer p {
width: 95%;
max-width: 1000px;
margin: 0 auto;
color: #78909C;
font-size: .9em
}
body > footer a {
color: #aaa;
}
/* NOFICATIONS */
#noty_topRight_layout_container {
font-family: sans-serif;
top: 4em !important;
right: 1em !important;
position: fixed !important;
width: 310px;
height: auto;
margin: 0;
padding: 0;
list-style-type: none;
z-index: 10000000;
}
#noty_topRight_layout_container li {
overflow: hidden;
margin: 0 0 .25em;
}
.noty_bar {
color: #fff;
background-color: #cfd8dc;
border-radius: .3em;
}
.noty_message {
font-size: .75em;
font-weight: bold;
line-height: 1.2em;
text-align: left;
padding: 1em;
width: auto;
position: relative;
}
.noty_text {
display: block;
box-sizing: border-box;
margin-left: 3em;
top: 1em;
}
.noty_icon {
position: absolute;
left: 0;
top: 0;
box-sizing: border-box;
height: 100%;
padding: 1em;
background-color: rgba(0, 0, 0, .1);
border-top-left-radius: .3em;
border-bottom-left-radius: .3em;
text-align: center;
}
.noty_icon .fa {
width: 1em !important;
}
.noty_type_success {
background-color: #00c853;
}
.noty_type_error {
background-color: #ff5252;
}
.noty_type_warning {
background-color: #ffd600;
}
.noty_type_information {
background-color: #448aff;
}
/* EDITOR : BUTTONS */
button,
input[type="submit"] {
border-radius: 0.2em;
border: 0;
padding: .5em 1em;
color: #000;
font-weight: normal;
background-color: #FFEB3B;
-webkit-transition: .5s ease background-color;
transition: .5s ease background-color;
}
button.darker {
background-color: #F9A825;
}
button.darker:hover {
background-color: #F57F17;
}
button:hover,
input[type="submit"]:hover,
button:active,
input[type="submit"]:active,
button:focus,
input[type="submit"]:focus {
outline: 0;
background-color: #FDD835;
}
button.add,
button.delete,
button.rename {
color: #fff;
padding: 0.063em 0.375em;
border-radius: 50%;
}
button.add {
background-color: #8BC34A;
}
button.add:hover {
background-color: #689F38;
}
button.delete {
background-color: #E53935;
}
label + .delete,
h3 + .delete {
visibility: hidden;
border-radius: .13em;
padding: 0 .3em;
font-size: .8em;
border: 1px solid #D32F2F;
}
.block:hover .delete,
fieldset:hover .delete {
visibility: visible;
}
button.delete:hover {
background-color: #D32F2F;
}
button.rename {
background-color: #1565C0;
}
button.rename:hover {
background-color: #0D47A1;
}
.frontmatter > .actions {
margin-top: 0;
text-align: right;
}
.frontmatter > .actions button.add {
padding: .5em 1em;
}
.toolbar .right {
float: right;
}
.toolbar input[type="submit"] {
background-color: #00BCD4;
color: #fff;
}
.toolbar input.default {
background-color: #8BC34A;
}
.editor h1 textarea {
width: 100%;
border: 0;
font-size: 2em;
font-weight: 400;
resize: none;
overflow: hidden;
line-height: 1em;
height: 1em;
background-color: transparent;
}
.block > .actions,
fieldset > .actions {
position: absolute;
top: 0.5em;
right: 0.5em;
}
.blocks {
column-count: 2;
column-gap: 1em;
}
.block,
fieldset {
display: inline-block;
margin-bottom: .6em;
box-sizing: border-box;
position: relative;
width: 100%;
border: 0;
padding: 0;
}
.block label,
fieldset label,
fieldset h3 {
font-weight: 700;
display: block;
font-size: 1em;
margin: 0 0 .3em;
color: #424242;
display: inline-block;
}
.block textarea {
width: 100%;
background-color: transparent;
resize: vertical;
background-color: inherit;
border: 0;
overflow: hidden;
}
.block input,
.block textarea,
fieldset .itens {
background-color: #fafafa;
border: 1px solid #e2e2e2;
border-radius: .2em;
padding: .4em;
color: #616161;
}
div[data-type="array-item"],
div[data-type="array-item"] + .add {
display: inline-block;
width: auto;
background-color: #2196F3;
color: #E3F2FD;
border-radius: .6em;
margin-bottom: .2em;
}
div[data-type="array-item"] input {
padding: .2em .5em;
}
div[data-type="array-item"] .actions {
display: inline-block;
padding: .2em
}
div[data-type="array-item"] .delete {
background-color: transparent;
box-shadow: 0 0 0 0;
}
input {
border: 0;
outline: 0;
background-color: transparent;
width: 100%;
}
input[type="submit"] {
width: auto;
}
fieldset input {
display: inline-block;
width: auto;
}
.complete .block[data-content="title"] {
display: none;
}
/* TOGGLER, SOURCE AND PREVIEW */
.editor .content {
border-radius: 0.5em;
border: 1px solid #d8d8d8;
background-color: #f7f7f7;
}
.editor .content nav a {
padding: 1em 1em;
line-height: 3em;
cursor: pointer;
font-size: 1em;
color: inherit;
}
.editor .content nav a.active {
font-weight: bold;
}
#editor-preview {
padding: 4% 13%;
display: block;
background-color: rgb(255, 255, 255);
display: none;
}
.ace_editor {
margin: 0;
border-bottom-left-radius: .5em;
border-bottom-right-radius: 0.5em;
}
.ace_gutter {
background-color: #f7f7f7 !important;
}
/* BROWSE */
.browse a {
color: inherit;
text-decoration: none;
}
.browse .actions {
background-color: #00BCD4;
color: #fff;
padding: 1.5em 0;
}
.browse .actions .container {
margin: 0 auto;
display: -webkit-box;
display: -webkit-flex;
display: -ms-flexbox;
display: flex;
}
.browse .actions .container > a,
.browse .actions .container > span {
line-height: 2em;
vertical-align: middle;
}
.browse .actions .container > a {
margin-right: 0.5em;
}
.browse .actions .container > span {
font-weight: bold;
font-size: 1.1em;
}
.browse .actions .fa {
vertical-align: middle;
}
.browse .actions .go-right {
margin-left: auto;
position: relative;
}
.browse .go-right input[type="file"] {
display: none;
}
.browse table {
margin: 1em 0;
width: 100%;
}
.browse tr {
line-height: 2em;
border-bottom: 1px solid rgba(0, 0, 0, 0.03);
-webkit-transition: .2s ease background-color;
transition: .2s ease background-color;
}
.browse tr:hover {
background-color: rgba(0, 0, 0, 0.04);
}
.browse th.buttons {
width: 4em;
}
.browse tr button {
line-height: 1.5em;
border-radius: 50%;
width: 1.5em;
height: 1.5em;
padding: 0;
}
.browse #new-file {
display: none;
position: absolute;
right: 0;
top: 2.5em;
background-color: #263238;
color: rgba(255, 255, 255, .5);
border-radius: .5em;
padding: 1em;
width: 182%;
}
/* POPUS */
#foreground {
z-index: 99999;
position: fixed;
top: 0;
left: 0;
height: 100%;
width: 100%;
background-color: rgba(0, 0, 0, 0.1);
}
.popup {
z-index: 999999;
position: fixed;
margin: 0 auto;
max-width: 25em;
width: 95%;
top: 10%;
left: 50%;
-webkit-transform: translateX(-50%);
transform: translateX(-50%);
background-color: #006064;
color: #fff;
padding: 1em 2em;
border-radius: .5em;
box-shadow: 0 1px 3px rgba(0, 0, 0, .12), 0 1px 2px rgba(0, 0, 0, .24);
}
.popup input[type="text"] {
border-bottom: .15em solid white;
}
/* LOADING */
#loading {
z-index: 99999;
position: fixed;
top: 0;
left: 0;
height: 100%;
width: 100%;
background-color: rgba(0, 0, 0, 0.41);
}
#loading .centerize {
position: relative;
top: 50%;
-webkit-transform: translateY(-50%);
transform: translateY(-50%);
}
.sk-folding-cube {
margin: 20px auto;
width: 40px;
height: 40px;
position: relative;
-webkit-transform: rotateZ(45deg);
transform: rotateZ(45deg);
}
.sk-folding-cube .sk-cube {
float: left;
width: 50%;
height: 50%;
position: relative;
-webkit-transform: scale(1.1);
transform: scale(1.1);
}
.sk-folding-cube .sk-cube:before {
content: '';
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
background-color: #fff;
-webkit-animation: sk-foldCubeAngle 2.4s infinite linear both;
animation: sk-foldCubeAngle 2.4s infinite linear both;
-webkit-transform-origin: 100% 100%;
transform-origin: 100% 100%;
}
.sk-folding-cube .sk-cube2 {
-webkit-transform: scale(1.1) rotateZ(90deg);
transform: scale(1.1) rotateZ(90deg);
}
.sk-folding-cube .sk-cube3 {
-webkit-transform: scale(1.1) rotateZ(180deg);
transform: scale(1.1) rotateZ(180deg);
}
.sk-folding-cube .sk-cube4 {
-webkit-transform: scale(1.1) rotateZ(270deg);
transform: scale(1.1) rotateZ(270deg);
}
.sk-folding-cube .sk-cube2:before {
-webkit-animation-delay: 0.3s;
animation-delay: 0.3s;
}
.sk-folding-cube .sk-cube3:before {
-webkit-animation-delay: 0.6s;
animation-delay: 0.6s;
}
.sk-folding-cube .sk-cube4:before {
-webkit-animation-delay: 0.9s;
animation-delay: 0.9s;
}
@-webkit-keyframes sk-foldCubeAngle {
0%,
10% {
-webkit-transform: perspective(140px) rotateX(-180deg);
transform: perspective(140px) rotateX(-180deg);
opacity: 0;
}
25%,
75% {
-webkit-transform: perspective(140px) rotateX(0deg);
transform: perspective(140px) rotateX(0deg);
opacity: 1;
}
90%,
100% {
-webkit-transform: perspective(140px) rotateY(180deg);
transform: perspective(140px) rotateY(180deg);
opacity: 0;
}
}
@keyframes sk-foldCubeAngle {
0%,
10% {
-webkit-transform: perspective(140px) rotateX(-180deg);
transform: perspective(140px) rotateX(-180deg);
opacity: 0;
}
25%,
75% {
-webkit-transform: perspective(140px) rotateX(0deg);
transform: perspective(140px) rotateX(0deg);
opacity: 1;
}
90%,
100% {
-webkit-transform: perspective(140px) rotateY(180deg);
transform: perspective(140px) rotateY(180deg);
opacity: 0;
}
}
@media screen and (max-width: 600px) {
.blocks {
-webkit-column-count: 1;
-moz-column-count: 1;
column-count: 1;
}
body > nav span {
display: none;
}
body>nav ul li:last-child {
margin-left: 0;
}
body > nav .container {
-webkit-box-pack: justify;
-webkit-justify-content: space-between;
-ms-flex-pack: justify;
justify-content: space-between;
text-align: center;
}
.hideable {
display: none;
}
}
@media screen and (max-width: 350px) {
.browse .actions {
text-align: center;
}
.browse .actions .container {
display: block;
}
.browse .container .go-right {
display: block;
}
}

57
assets/src/js/app.js Normal file
View File

@@ -0,0 +1,57 @@
var basePath = "/";
$(document).ready(function() {
basePath += window.location.pathname.split('/')[0];
// Log out the user sending bad credentials to the server
$("#logout").click(function(event) {
event.preventDefault();
$.ajax({
type: "GET",
url: basePath + "",
async: false,
username: "username",
password: "password",
headers: {
"Authorization": "Basic xxx"
}
}).fail(function() {
window.location = "/";
});
return false;
});
$(document).pjax('a[data-pjax]', '#content');
});
$(document).on('ready pjax:end', function() {
$('#content').off();
// Update the title
document.title = document.getElementById('site-title').innerHTML;
//TODO: navbar titles changing effect when changing page
// Auto Grow Textarea
function autoGrow() {
this.style.height = '5px';
this.style.height = this.scrollHeight + 'px';
}
$("textarea").each(autoGrow);
$('textarea').keyup(autoGrow);
$(window).resize(function() {
$("textarea").each(autoGrow);
});
if ($('main').hasClass('browse')) {
$(document).trigger("page:browse");
}
if ($(".editor")[0]) {
$(document).trigger("page:editor");
}
return false;
});

379
assets/src/js/browse.js Normal file
View File

@@ -0,0 +1,379 @@
// When the page Browse is opened
$(document).on('page:browse', function() {
var foreground = '#foreground';
/* DELETE FILE */
var removeForm = 'form#delete';
var removeItem = null;
$('#content').on('click', '.delete', function(event) {
event.preventDefault();
// Gets the information about the file the user wants to delete
removeItem = new Object();
removeItem.url = $(this).data("file");
removeItem.row = $(this).parent().parent();
removeItem.filename = $(removeItem.row).find('.filename').text();
// Shows the remove form and the foreground
$(removeForm).find('span').text(removeItem.filename);
$(removeForm).fadeIn(200)
$(foreground).fadeIn(200);
return false;
});
$('#content').on('submit', removeForm, function(event) {
event.preventDefault();
// Checks if the item to remove is defined
if (removeItem == null) {
notification({
text: "Something is wrong with your form.",
type: "error"
});
return false;
}
// Makes the DELETE request to the server
var request = new XMLHttpRequest();
request.open("DELETE", removeItem.url);
request.send();
request.onreadystatechange = function() {
if (request.readyState == 4) {
var response = JSON.parse(request.responseText),
type = "success",
timeout = 5000;
$(foreground).fadeOut(200);
$(removeForm).fadeOut(200);
$(removeItem.row).fadeOut(200);
if (request.status != 200) {
type = "error";
timeout = false;
}
notification({
text: response.message,
type: type,
timeout: timeout
});
removeItem = null;
}
}
return false;
});
/* FILE UPLOAD */
$('#content').on('change', 'input[type="file"]', function(event) {
event.preventDefault();
files = event.target.files;
$('#loading').fadeIn();
// Create a formdata object and add the files
var data = new FormData();
$.each(files, function(key, value) {
data.append(key, value);
});
$.ajax({
url: window.location.pathname,
type: 'POST',
data: data,
cache: false,
dataType: 'json',
headers: {
'X-Upload': 'true',
},
processData: false,
contentType: false,
}).done(function(data) {
notification({
text: "File(s) uploaded successfully.",
type: 'success',
timeout: 5000
});
$('#loading').fadeOut();
$.pjax({
url: window.location.pathname,
container: '#content'
})
}).fail(function(data) {
$('#loading').fadeOut();
notification({
text: 'Something went wrong.',
type: 'error'
});
console.log(data);
});
return false;
});
$('#content').on('click', '#upload', function(event) {
event.preventDefault();
$('.actions input[type="file"]').click();
return false;
});
/* NEW FILE */
var createForm = 'form#new',
createInput = createForm + ' input[type="text"]';
$('#content').on('click', '.new', function(event) {
event.preventDefault();
$(foreground).fadeIn(200);
$(createForm).fadeIn(200);
return false;
});
$('#content').on('keypress', createInput, function(event) {
// If it's "enter" key, submit the
if (event.keyCode == 13) {
event.preventDefault();
$(createForm).submit();
return false;
}
});
$('#content').on('submit', createForm, function(event) {
event.preventDefault();
var value = $(createInput).val(),
splited = value.split(":"),
filename = "",
archetype = "";
if (value == "") {
notification({
text: "You have to write something. If you want to close the box, click the button again.",
type: 'warning',
timeout: 5000
});
return false;
} else if (splited.length == 1) {
filename = value;
} else if (splited.length == 2) {
filename = splited[0];
archetype = splited[1];
} else {
notification({
text: "Hmm... I don't understand you. Try writing something like 'name[:archetype]'.",
type: 'error'
});
return false;
}
var content = {
filename: filename,
archetype: archetype
}
var request = new XMLHttpRequest();
request.open("POST", window.location.pathname);
request.setRequestHeader("Content-Type", "application/json;charset=UTF-8");
request.send(JSON.stringify(content));
request.onreadystatechange = function() {
if (request.readyState == 4) {
var response = JSON.parse(request.responseText);
var type = "success";
var timeout = 5000;
if (request.status != 200) {
type = "error";
timeout = false;
}
notification({
text: response.message,
type: type,
timeout: timeout
});
if (request.status == 200) {
$.pjax({
url: response.location,
container: '#content'
})
}
}
}
return false;
});
/* RENAME FILE */
var renameForm = 'form#rename',
renameInput = renameForm + ' input[type="text"]',
renameItem = null;
$('#content').on('click', '.rename', function(event) {
event.preventDefault();
renameItem = $(this).parent().parent().find('.filename').text();
$(foreground).fadeIn(200);
$(renameForm).fadeIn(200);
$(renameForm).find('span').text(renameItem);
$(renameForm).find('input[type="text"]').val(renameItem);
return false;
});
$('#content').on('keypress', renameInput, function(event) {
if (event.keyCode == 13) {
event.preventDefault();
$(renameForm).submit();
return false;
}
});
$('#content').on('submit', renameForm, function(event) {
event.preventDefault();
var filename = $(this).find('input[type="text"]').val();
if (filename === "") {
return false;
}
if (filename.substring(0, 1) != "/") {
filename = window.location.pathname.replace(basePath + "/browse/", "") + '/' + filename;
}
var content = {
filename: filename
};
var request = new XMLHttpRequest();
request.open("PUT", renameItem);
request.setRequestHeader("Content-Type", "application/json;charset=UTF-8");
request.send(JSON.stringify(content));
request.onreadystatechange = function() {
if (request.readyState == 4) {
var response = JSON.parse(request.responseText),
type = "success",
timeout = 5000;
if (request.status != 200) {
type = "error";
timeout = false;
}
$.pjax({
url: window.location.pathname,
container: '#content'
});
notification({
text: response.message,
type: type,
timeout: timeout
});
renameItem = null;
}
}
return false;
});
/* GIT ACTIONS */
var gitButton = 'button.git',
gitForm = 'form#git',
gitInput = gitForm + ' input[type="text"]';
$('#content').on('click', gitButton, function(event) {
event.preventDefault();
$(foreground).fadeIn(200);
$(gitForm).fadeIn(200);
return false;
});
$('#content').on('keypress', gitInput, function(event) {
if (event.keyCode == 13) {
event.preventDefault();
$(gitForm).submit();
return false;
}
});
$('#content').on('submit', gitForm, function(event) {
event.preventDefault();
var value = $(this).find('input[type="text"]').val();
if (value == "") {
notification({
text: "You have to write something. If you want to close the box, click outside of it.",
type: 'warning',
timeout: 5000
});
return false;
}
var request = new XMLHttpRequest();
request.open("POST", basePath + "/git");
request.setRequestHeader("Content-Type", "application/json;charset=UTF-8");
request.send(JSON.stringify({
command: value
}));
request.onreadystatechange = function() {
if (request.readyState == 4) {
var data = JSON.parse(request.responseText);
if (request.status == 200) {
notification({
text: data.message,
type: "success",
timeout: 5000
});
$(gitForm).fadeOut(200);
$(foreground).fadeOut(200);
$.pjax({
url: window.location.pathname,
container: '#content'
});
} else {
notification({
text: data.message,
type: "error"
});
}
}
}
return false;
});
/* $(foreground) AND STUFF */
$('#content').on('click', '.close', function(event) {
event.preventDefault();
$(this).parent().parent().fadeOut(200);
$(foreground).click();
return false;
});
$('#content').on('click', foreground, function(event) {
event.preventDefault();
$(foreground).fadeOut(200);
$(createForm).fadeOut(200);
$(renameForm).fadeOut(200);
$(removeForm).fadeOut(200);
$(gitForm).fadeOut(200);
return false;
});
});

268
assets/src/js/editor.js Normal file
View File

@@ -0,0 +1,268 @@
$(document).on('page:editor', function() {
var container = $('.editor');
var preview = $('#editor-preview');
var editor = $('#editor-source');
if (container.hasClass('complete')) {
// Change title field when editing the header
$('#content').on('keyup', '#site-title', function() {
$('.frontmatter #title').val($(this).val());
});
}
if (!container.hasClass('frontmatter-only')) {
// Setup ace editor
var mode = $("#editor-source").data('mode');
var textarea = $('textarea[name="content"]').hide();
var aceEditor = ace.edit('editor-source');
aceEditor.getSession().setMode("ace/mode/" + mode);
aceEditor.getSession().setValue(textarea.val());
aceEditor.getSession().on('change', function() {
textarea.val(aceEditor.getSession().getValue());
});
aceEditor.setOptions({
wrap: true,
maxLines: Infinity,
theme: "ace/theme/github",
showPrintMargin: false,
fontSize: "1em",
minLines: 20
});
$('#content').on('click', '#see-source', function(event) {
event.preventDefault();
preview.hide();
editor.fadeIn();
$(this).addClass('active');
$("#see-preview").removeClass('active');
$("#see-preview").data("previewing", "false");
})
// Toggles between preview and editing mode
$('#content').on('click', '#see-preview', function(event) {
event.preventDefault();
// If it currently in the preview mode, hide the preview
// and show the editor
if ($(this).data("previewing") == "true") {
preview.hide();
editor.fadeIn();
$(this).removeClass('active');
$("#see-source").addClass('active');
$(this).data("previewing", "false");
} else {
// If it's in editing mode, convert the markdown to html
// and show it
var converter = new showdown.Converter(),
text = aceEditor.getValue(),
html = converter.makeHtml(text);
// Hide the editor and show the preview
editor.hide();
preview.html(html).fadeIn();
$(this).addClass('active');
$("#see-source").removeClass('active');
$(this).data("previewing", "true");
}
return false;
});
}
$('#content').on('keypress', 'input', function(event) {
if (event.keyCode == 13) {
event.preventDefault();
$('input[value="Save"]').focus().click();
return false;
}
});
var submitActor = null;
$('#content').on('click', 'form input[type=submit]', function(event) {
submitActor = this;
});
// Submites any form in the page in JSON format
$('#content').on('submit', 'form', function(event) {
event.preventDefault();
if (!container.hasClass('frontmatter-only')) {
// Reset preview area and button to make sure it will
// not serialize any form inside the preview
preview.html('').fadeOut();
$("#see-preview").data("previewing", "false");
editor.fadeIn();
}
var button = $(submitActor);
var data = {
content: $(this).serializeJSON(),
contentType: button.data("type"),
schedule: button.data("schedule"),
regenerate: button.data("regenerate")
}
console.log(JSON.stringify(data));
var request = new XMLHttpRequest();
request.open("POST", window.location);
request.setRequestHeader("Content-Type", "application/json;charset=UTF-8");
request.send(JSON.stringify(data));
request.onreadystatechange = function() {
if (request.readyState == 4) {
var response = JSON.parse(request.responseText),
type = "success",
timeout = 5000;
if (request.status == 200) {
response.message = button.data("message");
}
if (request.status != 200) {
type = "error";
timeout = false;
}
notification({
text: response.message,
type: type,
timeout: timeout
});
}
}
return false;
});
// Adds one more field to the current group
$("#content").on('click', '.add', function(event) {
event.preventDefault();
defaultID = "lorem-ipsum-sin-dolor-amet";
// Remove if there is an incomplete new item
newItem = $("#" + defaultID);
if (newItem.length) {
newItem.remove();
}
block = $(this).parent().parent();
blockType = block.data("type");
blockID = block.attr("id");
// If the Block Type is an array
if (blockType == "array") {
newID = blockID + "[]";
input = blockID;
input = input.replace(/\[/, '\\[');
input = input.replace(/\]/, '\\]');
block.append('<div id="' + newID + '-' + $('#' + input + ' > div').length + '" data-type="array-item"><input name="' + newID + ':auto" id="' + newID + '"></input><span class="actions"> <button class="delete">&#8722;</button></span></div></div>');
}
// Main add button, after all blocks
if (block.is('div') && block.hasClass("frontmatter")) {
block = $('.blocks');
blockType = "object";
}
// If the Block is an object
if (blockType == "object") {
block.append('<div class="block" id="' + defaultID + '"></div>');
newItem = $("#" + defaultID);
newItem.html('<input id="name-' + defaultID + '" placeholder="Write the field name and press enter..."></input>');
field = $("#name-" + defaultID);
// Show a notification with some information for newbies
if (!document.cookie.replace(/(?:(?:^|.*;\s*)placeholdertip\s*\=\s*([^;]*).*$)|^.*$/, "$1")) {
var date = new Date();
date.setDate(date.getDate() + 365);
document.cookie = 'placeholdertip=true; expires=' + date.toUTCString + '; path=/';
notification({
text: 'Write the field name and then press enter. If you want to create an array or an object, end the name with ":array" or ":object".',
type: 'information'
});
}
$(field).keypress(function(event) {
// When you press enter within the new name field:
if (event.which == 13) {
event.preventDefault();
// This var should have a value of the type "name[:array, :object]"
value = field.val();
if (value == "") {
newItem.remove();
return false;
}
elements = value.split(":")
if (elements.length > 2) {
notification({
text: "Invalid syntax. It must be 'name[:type]'.",
type: 'error'
});
return false;
}
if (elements.length == 2 && elements[1] != "array" && elements[1] != "object") {
notification({
text: "Only arrays and objects are allowed.",
type: 'error'
});
return false;
}
field.remove();
if (typeof blockID === "undefined") {
blockID = elements[0];
} else {
blockID = blockID + '[' + elements[0] + ']';
}
if (elements.length == 1) {
newItem.attr('id', 'block-' + blockID);
newItem.append('<input name="' + blockID + ':auto" id="' + blockID + '"></input><br>');
newItem.prepend('<label for="' + blockID + '">' + value + '</label> <span class="actions"><button class="delete">&#8722;</button></span>');
} else {
type = "";
if (elements[1] == "array") {
type = "array";
} else {
type = "object"
}
template = "<fieldset id=\"${blockID}\" data-type=\"${type}\"> <h3>${elements[0]}</h3> <span class=\"actions\"> <button class=\"add\">&#43;</button> <button class=\"delete\">&#8722;</button> </span> </fieldset>"
template = template.replace("${blockID}", blockID);
template = template.replace("${elements[0]}", elements[0]);
template = template.replace("${type}", type);
newItem.after(template);
newItem.remove();
}
return false;
}
});
}
return false;
});
$("#content").on('click', '.delete', function(event) {
event.preventDefault();
button = $(this);
name = button.parent().parent().attr("for") || button.parent().parent().attr("id") || button.parent().parent().parent().attr("id");
name = name.replace(/\[/, '\\[');
name = name.replace(/\]/, '\\]');
$('label[for="' + name + '"]').fadeOut().remove();
$('#' + name).fadeOut().remove();
return false;
});
});

View File

@@ -0,0 +1,82 @@
$.noty.themes.admin = {
name: 'admin',
helpers: {},
modal: {
css: {
position: 'fixed',
width: '100%',
height: '100%',
backgroundColor: '#000',
zIndex: 10000,
opacity: 0.6,
display: 'none',
left: 0,
top: 0
}
}
};
$.noty.defaults = {
layout: 'topRight',
theme: 'admin',
dismissQueue: true,
animation: {
open: 'animated bounceInRight',
close: 'animated fadeOut',
easing: 'swing',
speed: 500 // opening & closing animation speed
},
timeout: false, // delay for closing event. Set false for sticky notifications
force: false, // adds notification to the beginning of queue when set to true
modal: false,
maxVisible: 5, // you can set max visible notification for dismissQueue true option,
killer: false, // for close all notifications before show
closeWith: ['click'], // ['click', 'button', 'hover', 'backdrop'] // backdrop click will close all notifications
callback: {
onShow: function() {},
afterShow: function() {},
onClose: function() {},
afterClose: function() {},
onCloseClick: function() {},
},
buttons: false // an array of buttons
};
notification = function(options) {
var icon;
switch (options.type) {
case "success":
icon = '<i class="fa fa-check"></i>';
break;
case "error":
icon = '<i class="fa fa-times"></i>';
break;
case "warning":
icon = '<i class="fa fa-exclamation"></i>';
break;
case "information":
icon = '<i class="fa fa-info"></i>';
break;
default:
icon = '<i class="fa fa-bell"></i>';
}
var defaults = {
template: '<div class="noty_message"><span class="noty_icon">' + icon + '</span><span class="noty_text"></span></div>'
}
options = $.extend({}, defaults, options);
noty(options);
if (!document.cookie.replace(/(?:(?:^|.*;\s*)stickynoties\s*\=\s*([^;]*).*$)|^.*$/, "$1") && !options.timeout) {
var date = new Date();
date.setDate(date.getDate() + 365);
document.cookie = 'stickynoties=true; expires=' + date.toUTCString + '; path=/';
notification({
text: "Some notifications are sticky. If it doesn't go away, click to dismiss it.",
type: 'information'
});
}
}