mirror of
https://github.com/getformwork/formwork.git
synced 2025-02-24 09:42:43 +01:00
Cleanup JavaScript
This commit is contained in:
parent
4395b602fd
commit
a1e37ee9e8
35
admin/assets/js/app.js
Executable file → Normal file
35
admin/assets/js/app.js
Executable file → Normal file
@ -126,26 +126,20 @@ Formwork.Editor = function(id) {
|
|||||||
});
|
});
|
||||||
|
|
||||||
$('[data-command=ul]', $toolbar).click(function() {
|
$('[data-command=ul]', $toolbar).click(function() {
|
||||||
var prevChar = prevCursorChar();
|
insertAtCursor(prependSequence() + '- ', '');
|
||||||
var prepend = prevChar === '\n' ? '\n' : '\n\n';
|
|
||||||
insertAtCursor(prevChar === undefined ? '- ' : prepend + '- ', '');
|
|
||||||
});
|
});
|
||||||
|
|
||||||
$('[data-command=ol]', $toolbar).click(function() {
|
$('[data-command=ol]', $toolbar).click(function() {
|
||||||
var prevChar = prevCursorChar();
|
|
||||||
var prepend = prevChar === '\n' ? '\n' : '\n\n';
|
|
||||||
var num = /^\d+\./.exec(lastLine(textarea.value));
|
var num = /^\d+\./.exec(lastLine(textarea.value));
|
||||||
if (num) {
|
if (num) {
|
||||||
insertAtCursor('\n' + (parseInt(num) + 1) + '. ', '');
|
insertAtCursor('\n' + (parseInt(num) + 1) + '. ', '');
|
||||||
} else {
|
} else {
|
||||||
insertAtCursor(prevChar === undefined ? '1. ' : prepend + '1. ', '');
|
insertAtCursor(prependSequence() + '1. ', '');
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
$('[data-command=quote]', $toolbar).click(function() {
|
$('[data-command=quote]', $toolbar).click(function() {
|
||||||
var prevChar = prevCursorChar();
|
insertAtCursor(prependSequence() + '> ', '');
|
||||||
var prepend = prevChar === '\n' ? '\n' : '\n\n';
|
|
||||||
insertAtCursor(prevChar === undefined ? '> ' : prepend + '> ', '');
|
|
||||||
});
|
});
|
||||||
|
|
||||||
$('[data-command=link]', $toolbar).click(function() {
|
$('[data-command=link]', $toolbar).click(function() {
|
||||||
@ -168,20 +162,12 @@ Formwork.Editor = function(id) {
|
|||||||
});
|
});
|
||||||
|
|
||||||
$('[data-command=image]', $toolbar).click(function() {
|
$('[data-command=image]', $toolbar).click(function() {
|
||||||
var prevChar = prevCursorChar();
|
insertAtCursor(prependSequence() + '');
|
||||||
var prepend = '\n\n';
|
|
||||||
if (prevChar === '\n') {
|
|
||||||
prepend = '\n';
|
|
||||||
} else if (prevChar === undefined) {
|
|
||||||
prepend = '';
|
|
||||||
}
|
|
||||||
insertAtCursor(prepend + '');
|
|
||||||
});
|
});
|
||||||
|
|
||||||
$('[data-command=summary]', $toolbar).click(function() {
|
$('[data-command=summary]', $toolbar).click(function() {
|
||||||
var prevChar = prevCursorChar();
|
|
||||||
if (!hasSummarySequence()) {
|
if (!hasSummarySequence()) {
|
||||||
console.log(prevChar);
|
var prevChar = prevCursorChar();
|
||||||
var prepend = (prevChar === undefined || prevChar === '\n') ? '' : '\n';
|
var prepend = (prevChar === undefined || prevChar === '\n') ? '' : '\n';
|
||||||
insertAtCursor(prepend + '\n===\n\n', '');
|
insertAtCursor(prepend + '\n===\n\n', '');
|
||||||
$(this).attr('disabled', true);
|
$(this).attr('disabled', true);
|
||||||
@ -252,6 +238,17 @@ Formwork.Editor = function(id) {
|
|||||||
return startPos === 0 ? undefined : textarea.value.substring(startPos - 1, startPos);
|
return startPos === 0 ? undefined : textarea.value.substring(startPos - 1, startPos);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function prependSequence() {
|
||||||
|
switch (prevCursorChar()) {
|
||||||
|
case undefined:
|
||||||
|
return '';
|
||||||
|
case '\n':
|
||||||
|
return '\n';
|
||||||
|
default:
|
||||||
|
return '\n\n';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
function insertAtCursor(leftValue, rightValue) {
|
function insertAtCursor(leftValue, rightValue) {
|
||||||
if (rightValue === undefined) {
|
if (rightValue === undefined) {
|
||||||
rightValue = leftValue;
|
rightValue = leftValue;
|
||||||
|
2
admin/assets/js/app.min.js
vendored
Executable file → Normal file
2
admin/assets/js/app.min.js
vendored
Executable file → Normal file
File diff suppressed because one or more lines are too long
@ -12,26 +12,20 @@ Formwork.Editor = function(id) {
|
|||||||
});
|
});
|
||||||
|
|
||||||
$('[data-command=ul]', $toolbar).click(function() {
|
$('[data-command=ul]', $toolbar).click(function() {
|
||||||
var prevChar = prevCursorChar();
|
insertAtCursor(prependSequence() + '- ', '');
|
||||||
var prepend = prevChar === '\n' ? '\n' : '\n\n';
|
|
||||||
insertAtCursor(prevChar === undefined ? '- ' : prepend + '- ', '');
|
|
||||||
});
|
});
|
||||||
|
|
||||||
$('[data-command=ol]', $toolbar).click(function() {
|
$('[data-command=ol]', $toolbar).click(function() {
|
||||||
var prevChar = prevCursorChar();
|
|
||||||
var prepend = prevChar === '\n' ? '\n' : '\n\n';
|
|
||||||
var num = /^\d+\./.exec(lastLine(textarea.value));
|
var num = /^\d+\./.exec(lastLine(textarea.value));
|
||||||
if (num) {
|
if (num) {
|
||||||
insertAtCursor('\n' + (parseInt(num) + 1) + '. ', '');
|
insertAtCursor('\n' + (parseInt(num) + 1) + '. ', '');
|
||||||
} else {
|
} else {
|
||||||
insertAtCursor(prevChar === undefined ? '1. ' : prepend + '1. ', '');
|
insertAtCursor(prependSequence() + '1. ', '');
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
$('[data-command=quote]', $toolbar).click(function() {
|
$('[data-command=quote]', $toolbar).click(function() {
|
||||||
var prevChar = prevCursorChar();
|
insertAtCursor(prependSequence() + '> ', '');
|
||||||
var prepend = prevChar === '\n' ? '\n' : '\n\n';
|
|
||||||
insertAtCursor(prevChar === undefined ? '> ' : prepend + '> ', '');
|
|
||||||
});
|
});
|
||||||
|
|
||||||
$('[data-command=link]', $toolbar).click(function() {
|
$('[data-command=link]', $toolbar).click(function() {
|
||||||
@ -54,20 +48,12 @@ Formwork.Editor = function(id) {
|
|||||||
});
|
});
|
||||||
|
|
||||||
$('[data-command=image]', $toolbar).click(function() {
|
$('[data-command=image]', $toolbar).click(function() {
|
||||||
var prevChar = prevCursorChar();
|
insertAtCursor(prependSequence() + '');
|
||||||
var prepend = '\n\n';
|
|
||||||
if (prevChar === '\n') {
|
|
||||||
prepend = '\n';
|
|
||||||
} else if (prevChar === undefined) {
|
|
||||||
prepend = '';
|
|
||||||
}
|
|
||||||
insertAtCursor(prepend + '');
|
|
||||||
});
|
});
|
||||||
|
|
||||||
$('[data-command=summary]', $toolbar).click(function() {
|
$('[data-command=summary]', $toolbar).click(function() {
|
||||||
var prevChar = prevCursorChar();
|
|
||||||
if (!hasSummarySequence()) {
|
if (!hasSummarySequence()) {
|
||||||
console.log(prevChar);
|
var prevChar = prevCursorChar();
|
||||||
var prepend = (prevChar === undefined || prevChar === '\n') ? '' : '\n';
|
var prepend = (prevChar === undefined || prevChar === '\n') ? '' : '\n';
|
||||||
insertAtCursor(prepend + '\n===\n\n', '');
|
insertAtCursor(prepend + '\n===\n\n', '');
|
||||||
$(this).attr('disabled', true);
|
$(this).attr('disabled', true);
|
||||||
@ -138,6 +124,17 @@ Formwork.Editor = function(id) {
|
|||||||
return startPos === 0 ? undefined : textarea.value.substring(startPos - 1, startPos);
|
return startPos === 0 ? undefined : textarea.value.substring(startPos - 1, startPos);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function prependSequence() {
|
||||||
|
switch (prevCursorChar()) {
|
||||||
|
case undefined:
|
||||||
|
return '';
|
||||||
|
case '\n':
|
||||||
|
return '\n';
|
||||||
|
default:
|
||||||
|
return '\n\n';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
function insertAtCursor(leftValue, rightValue) {
|
function insertAtCursor(leftValue, rightValue) {
|
||||||
if (rightValue === undefined) {
|
if (rightValue === undefined) {
|
||||||
rightValue = leftValue;
|
rightValue = leftValue;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user