pull/20/head
Henrique Dias 2015-09-26 11:42:00 +01:00
parent d569e67642
commit 5316686d2d
6 changed files with 85 additions and 86 deletions

View File

@ -84,8 +84,7 @@ module.exports = function(grunt) {
'node_modules/codemirror/mode/javascript/javascript.js', 'node_modules/codemirror/mode/javascript/javascript.js',
'node_modules/codemirror/mode/markdown/markdown.js', 'node_modules/codemirror/mode/markdown/markdown.js',
'node_modules/codemirror/mode/sass/sass.js', 'node_modules/codemirror/mode/sass/sass.js',
'node_modules/codemirror/mode/htmlmixed/htmlmixed.js', 'node_modules/codemirror/mode/htmlmixed/htmlmixed.js'
'node_modules/js-cookie/src/js.cookie.js'
] ]
} }
}, },

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -152,64 +152,6 @@ $(document).on('ready pjax:success', function() {
} }
}); });
// If it has a textarea
if (textarea[0]) {
options = {
mode: textarea.data("mode"),
theme: 'mdn-like',
lineWrapping: true,
lineNumbers: true,
scrollbarStyle: null
}
if (textarea.data("mode") == "markdown") {
options.lineNumbers = false
}
editor = CodeMirror.fromTextArea(textarea[0], options);
codemirror = $('.CodeMirror');
// Toggles between preview and editing mode
$("#preview").click(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();
codemirror.fadeIn();
$(this).data("previewing", "false");
notification({
text: "Think, relax and do the better you can!",
type: 'information',
timeout: 2000
});
} else {
// Copy the editor content to texteare
editor.save()
// If it's in editing mode, convert the markdown to html
// and show it
var converter = new showdown.Converter(),
text = textarea.val(),
html = converter.makeHtml(text);
// Hide the editor and show the preview
codemirror.hide();
preview.html(html).fadeIn();
$(this).data("previewing", "true");
notification({
text: "This is how your post looks like.",
type: 'information',
timeout: 2000
});
}
return false;
});
}
// Submites any form in the page in JSON format // Submites any form in the page in JSON format
$('form').submit(function(event) { $('form').submit(function(event) {
event.preventDefault(); event.preventDefault();
@ -255,7 +197,8 @@ $(document).on('ready pjax:success', function() {
$("body").on('click', '.add', function(event) { $("body").on('click', '.add', function(event) {
event.preventDefault(); event.preventDefault();
if ($("#new").length) { if ($("#new-admin-item-123").length) {
console.log("oi")
return false; return false;
} }
@ -266,8 +209,8 @@ $(document).on('ready pjax:success', function() {
if (title.is('h1')) { if (title.is('h1')) {
fieldset = $('.frontmatter .container'); fieldset = $('.frontmatter .container');
fieldset.prepend('<div id="ghost"></div>'); fieldset.prepend('<div id="ghost-admin-item-123"></div>');
title = $('#ghost'); title = $('#ghost-admin-item-123');
type = "object"; type = "object";
} }
@ -276,13 +219,13 @@ $(document).on('ready pjax:success', function() {
} }
if (type == "object") { if (type == "object") {
title.after('<input id="new" placeholder="Write the field name and press enter..."></input>'); title.after('<input id="new-admin-item-123" placeholder="Write the field name and press enter..."></input>');
element = $("#new"); element = $("#new-admin-item-123");
if (!Cookies.get('placeholdertip')) { if (!document.cookie.replace(/(?:(?:^|.*;\s*)placeholdertip\s*\=\s*([^;]*).*$)|^.*$/, "$1")) {
Cookies.set('placeholdertip', 'true', { var date = new Date();
expires: 365 date.setDate(date.getDate() + 365);
}); document.cookie = 'placeholdertip=true; expires=' + date.toUTCString + '; path=/';
notification({ 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".', 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".',
@ -352,5 +295,63 @@ $(document).on('ready pjax:success', function() {
return false; return false;
}); });
// If it has a textarea
if (textarea[0]) {
options = {
mode: textarea.data("mode"),
theme: 'mdn-like',
lineWrapping: true,
lineNumbers: true,
scrollbarStyle: null
}
if (textarea.data("mode") == "markdown") {
options.lineNumbers = false
}
editor = CodeMirror.fromTextArea(textarea[0], options);
codemirror = $('.CodeMirror');
// Toggles between preview and editing mode
$("#preview").click(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();
codemirror.fadeIn();
$(this).data("previewing", "false");
notification({
text: "Think, relax and do the better you can!",
type: 'information',
timeout: 2000
});
} else {
// Copy the editor content to texteare
editor.save()
// If it's in editing mode, convert the markdown to html
// and show it
var converter = new showdown.Converter(),
text = textarea.val(),
html = converter.makeHtml(text);
// Hide the editor and show the preview
codemirror.hide();
preview.html(html).fadeIn();
$(this).data("previewing", "true");
notification({
text: "This is how your post looks like.",
type: 'information',
timeout: 2000
});
}
return false;
});
}
} }
}); });

View File

@ -69,10 +69,10 @@ notification = function(options) {
options = $.extend({}, defaults, options); options = $.extend({}, defaults, options);
noty(options); noty(options);
if (!Cookies.get('stickynoties') && !options.timeout) { if (!document.cookie.replace(/(?:(?:^|.*;\s*)stickynoties\s*\=\s*([^;]*).*$)|^.*$/, "$1") && !options.timeout) {
Cookies.set('stickynoties', 'true', { var date = new Date();
expires: 365 date.setDate(date.getDate() + 365);
}); document.cookie = 'stickynoties=true; expires=' + date.toUTCString + '; path=/';
notification({ notification({
text: "Some notifications are sticky. If it doesn't go away, click to dismiss it.", text: "Some notifications are sticky. If it doesn't go away, click to dismiss it.",

View File

@ -22,7 +22,6 @@
"font-awesome": "^4.4.0", "font-awesome": "^4.4.0",
"jquery": "^2.1.4", "jquery": "^2.1.4",
"jquery-serializejson": "^2.5.0", "jquery-serializejson": "^2.5.0",
"js-cookie": "^2.0.3",
"normalize.css": "^3.0.3", "normalize.css": "^3.0.3",
"noty": "^2.3.6", "noty": "^2.3.6",
"perfect-scrollbar": "^0.6.4", "perfect-scrollbar": "^0.6.4",