mirror of
https://github.com/fastmail/Squire.git
synced 2025-01-03 05:00:13 -05:00
Added makeHeading and removeHeading to Squire, implemented in Squire-UI
This commit is contained in:
parent
9e3fa11d4c
commit
c85bcd7d48
6 changed files with 50 additions and 12 deletions
|
@ -124,6 +124,7 @@ $(document).ready(function() {
|
||||||
testQuote: editor.testPresenceinSelection(
|
testQuote: editor.testPresenceinSelection(
|
||||||
'increaseQuoteLevel', action, 'blockquote', (
|
'increaseQuoteLevel', action, 'blockquote', (
|
||||||
/>blockquote\b/)),
|
/>blockquote\b/)),
|
||||||
|
testHeading: editor.testPresenceinSelection('makeHeading', action, 'H1', (/>H1\b/)),
|
||||||
isNotValue: function (a) {return (a == action && this.value !== ''); }
|
isNotValue: function (a) {return (a == action && this.value !== ''); }
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -131,20 +132,20 @@ $(document).ready(function() {
|
||||||
editor.alignCenter = function () { editor.setTextAlignment('center'); };
|
editor.alignCenter = function () { editor.setTextAlignment('center'); };
|
||||||
editor.alignLeft = function () { editor.setTextAlignment('left'); };
|
editor.alignLeft = function () { editor.setTextAlignment('left'); };
|
||||||
editor.alignJustify = function () { editor.setTextAlignment('justify'); };
|
editor.alignJustify = function () { editor.setTextAlignment('justify'); };
|
||||||
editor.makeHeading = function () { editor.setFontSize('2em'); editor.bold(); };
|
|
||||||
|
|
||||||
if (test.testBold | test.testItalic | test.testUnderline | test.testOrderedList | test.testLink | test.testQuote) {
|
if (test.testBold | test.testItalic | test.testUnderline | test.testOrderedList | test.testLink | test.testQuote | test.testHeading) {
|
||||||
if (test.testBold) editor.removeBold();
|
if (test.testBold) editor.removeBold();
|
||||||
if (test.testItalic) editor.removeItalic();
|
if (test.testItalic) editor.removeItalic();
|
||||||
if (test.testUnderline) editor.removeUnderline();
|
if (test.testUnderline) editor.removeUnderline();
|
||||||
if (test.testLink) editor.removeLink();
|
if (test.testLink) editor.removeLink();
|
||||||
if (test.testOrderedList) editor.removeList();
|
if (test.testOrderedList) editor.removeList();
|
||||||
if (test.testQuote) editor.decreaseQuoteLevel();
|
if (test.testQuote) editor.decreaseQuoteLevel();
|
||||||
|
if (test.testHeading) editor.removeHeading();
|
||||||
} else if (test.isNotValue('makeLink') | test.isNotValue('insertImage') | test.isNotValue('selectFont')) {
|
} else if (test.isNotValue('makeLink') | test.isNotValue('insertImage') | test.isNotValue('selectFont')) {
|
||||||
// do nothing these are dropdowns.
|
// do nothing these are dropdowns.
|
||||||
} else {
|
} else {
|
||||||
if (editor.getSelectedText() === '' && !(action == 'insertImage' || action == 'makeOrderedList' || action == 'increaseQuoteLevel' || action == 'redo' || action == 'undo')) return;
|
if (editor.getSelectedText() === '' && !(action == 'insertImage' || action == 'makeOrderedList' || action == 'increaseQuoteLevel' || action == 'redo' || action == 'undo' || action == "makeHeading")) return;
|
||||||
editor[action]();
|
editor[action]();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
|
@ -138,7 +138,7 @@ TreeWalker.prototype.previousNode = function () {
|
||||||
};
|
};
|
||||||
/*jshint strict:false, undef:false, unused:false */
|
/*jshint strict:false, undef:false, unused:false */
|
||||||
|
|
||||||
var inlineNodeNames = /^(?:#text|A(?:BBR|CRONYM)?|B(?:R|D[IO])?|C(?:ITE|ODE)|D(?:ATA|FN|EL)|EM|FONT|HR|I(?:NPUT|MG|NS)?|KBD|Q|R(?:P|T|UBY)|S(?:U[BP]|PAN|TR(?:IKE|ONG)|MALL|AMP)?|U|VAR|WBR)$/;
|
var inlineNodeNames = /^(?:#text|A(?:BBR|CRONYM)?|B(?:R|D[IO])?|C(?:ITE|ODE)|D(?:ATA|FN|EL)|EM|FONT|HR|H1|I(?:NPUT|MG|NS)?|KBD|Q|R(?:P|T|UBY)|S(?:U[BP]|PAN|TR(?:IKE|ONG)|MALL|AMP)?|U|VAR|WBR)$/;
|
||||||
|
|
||||||
var leafNodeNames = {
|
var leafNodeNames = {
|
||||||
BR: 1,
|
BR: 1,
|
||||||
|
@ -2060,6 +2060,7 @@ var makeOrderedList = function ( frag ) {
|
||||||
return frag;
|
return frag;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
var removeList = function ( frag ) {
|
var removeList = function ( frag ) {
|
||||||
var lists = frag.querySelectorAll( 'UL, OL' ),
|
var lists = frag.querySelectorAll( 'UL, OL' ),
|
||||||
i, l, ll, list, listFrag, children, child;
|
i, l, ll, list, listFrag, children, child;
|
||||||
|
@ -3411,6 +3412,23 @@ proto.setTextDirection = function ( direction ) {
|
||||||
return this.focus();
|
return this.focus();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
proto.makeHeading = function () {
|
||||||
|
var range = this.getSelection();
|
||||||
|
this.changeFormat({
|
||||||
|
tag: 'H1',
|
||||||
|
}, null, range );
|
||||||
|
return this.focus();
|
||||||
|
};
|
||||||
|
|
||||||
|
proto.removeHeading = function () {
|
||||||
|
var range = this.getSelection();
|
||||||
|
this.changeFormat( null, {
|
||||||
|
tag: 'H1',
|
||||||
|
attributes: {}
|
||||||
|
}, range, false);
|
||||||
|
return this.focus();
|
||||||
|
};
|
||||||
|
|
||||||
proto.increaseQuoteLevel = command( 'modifyBlocks', increaseBlockQuoteLevel );
|
proto.increaseQuoteLevel = command( 'modifyBlocks', increaseBlockQuoteLevel );
|
||||||
proto.decreaseQuoteLevel = command( 'modifyBlocks', decreaseBlockQuoteLevel );
|
proto.decreaseQuoteLevel = command( 'modifyBlocks', decreaseBlockQuoteLevel );
|
||||||
|
|
||||||
|
|
File diff suppressed because one or more lines are too long
|
@ -975,6 +975,7 @@ var makeOrderedList = function ( frag ) {
|
||||||
return frag;
|
return frag;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
var removeList = function ( frag ) {
|
var removeList = function ( frag ) {
|
||||||
var lists = frag.querySelectorAll( 'UL, OL' ),
|
var lists = frag.querySelectorAll( 'UL, OL' ),
|
||||||
i, l, ll, list, listFrag, children, child;
|
i, l, ll, list, listFrag, children, child;
|
||||||
|
@ -2326,6 +2327,23 @@ proto.setTextDirection = function ( direction ) {
|
||||||
return this.focus();
|
return this.focus();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
proto.makeHeading = function () {
|
||||||
|
var range = this.getSelection();
|
||||||
|
this.changeFormat({
|
||||||
|
tag: 'H1',
|
||||||
|
}, null, range );
|
||||||
|
return this.focus();
|
||||||
|
};
|
||||||
|
|
||||||
|
proto.removeHeading = function () {
|
||||||
|
var range = this.getSelection();
|
||||||
|
this.changeFormat( null, {
|
||||||
|
tag: 'H1',
|
||||||
|
attributes: {}
|
||||||
|
}, range, false);
|
||||||
|
return this.focus();
|
||||||
|
};
|
||||||
|
|
||||||
proto.increaseQuoteLevel = command( 'modifyBlocks', increaseBlockQuoteLevel );
|
proto.increaseQuoteLevel = command( 'modifyBlocks', increaseBlockQuoteLevel );
|
||||||
proto.decreaseQuoteLevel = command( 'modifyBlocks', decreaseBlockQuoteLevel );
|
proto.decreaseQuoteLevel = command( 'modifyBlocks', decreaseBlockQuoteLevel );
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
/*jshint strict:false, undef:false, unused:false */
|
/*jshint strict:false, undef:false, unused:false */
|
||||||
|
|
||||||
var inlineNodeNames = /^(?:#text|A(?:BBR|CRONYM)?|B(?:R|D[IO])?|C(?:ITE|ODE)|D(?:ATA|FN|EL)|EM|FONT|HR|I(?:NPUT|MG|NS)?|KBD|Q|R(?:P|T|UBY)|S(?:U[BP]|PAN|TR(?:IKE|ONG)|MALL|AMP)?|U|VAR|WBR)$/;
|
var inlineNodeNames = /^(?:#text|A(?:BBR|CRONYM)?|B(?:R|D[IO])?|C(?:ITE|ODE)|D(?:ATA|FN|EL)|EM|FONT|HR|H1|I(?:NPUT|MG|NS)?|KBD|Q|R(?:P|T|UBY)|S(?:U[BP]|PAN|TR(?:IKE|ONG)|MALL|AMP)?|U|VAR|WBR)$/;
|
||||||
|
|
||||||
var leafNodeNames = {
|
var leafNodeNames = {
|
||||||
BR: 1,
|
BR: 1,
|
||||||
|
|
|
@ -124,6 +124,7 @@ $(document).ready(function() {
|
||||||
testQuote: editor.testPresenceinSelection(
|
testQuote: editor.testPresenceinSelection(
|
||||||
'increaseQuoteLevel', action, 'blockquote', (
|
'increaseQuoteLevel', action, 'blockquote', (
|
||||||
/>blockquote\b/)),
|
/>blockquote\b/)),
|
||||||
|
testHeading: editor.testPresenceinSelection('makeHeading', action, 'H1', (/>H1\b/)),
|
||||||
isNotValue: function (a) {return (a == action && this.value !== ''); }
|
isNotValue: function (a) {return (a == action && this.value !== ''); }
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -131,20 +132,20 @@ $(document).ready(function() {
|
||||||
editor.alignCenter = function () { editor.setTextAlignment('center'); };
|
editor.alignCenter = function () { editor.setTextAlignment('center'); };
|
||||||
editor.alignLeft = function () { editor.setTextAlignment('left'); };
|
editor.alignLeft = function () { editor.setTextAlignment('left'); };
|
||||||
editor.alignJustify = function () { editor.setTextAlignment('justify'); };
|
editor.alignJustify = function () { editor.setTextAlignment('justify'); };
|
||||||
editor.makeHeading = function () { editor.setFontSize('2em'); editor.bold(); };
|
|
||||||
|
|
||||||
if (test.testBold | test.testItalic | test.testUnderline | test.testOrderedList | test.testLink | test.testQuote) {
|
if (test.testBold | test.testItalic | test.testUnderline | test.testOrderedList | test.testLink | test.testQuote | test.testHeading) {
|
||||||
if (test.testBold) editor.removeBold();
|
if (test.testBold) editor.removeBold();
|
||||||
if (test.testItalic) editor.removeItalic();
|
if (test.testItalic) editor.removeItalic();
|
||||||
if (test.testUnderline) editor.removeUnderline();
|
if (test.testUnderline) editor.removeUnderline();
|
||||||
if (test.testLink) editor.removeLink();
|
if (test.testLink) editor.removeLink();
|
||||||
if (test.testOrderedList) editor.removeList();
|
if (test.testOrderedList) editor.removeList();
|
||||||
if (test.testQuote) editor.decreaseQuoteLevel();
|
if (test.testQuote) editor.decreaseQuoteLevel();
|
||||||
|
if (test.testHeading) editor.removeHeading();
|
||||||
} else if (test.isNotValue('makeLink') | test.isNotValue('insertImage') | test.isNotValue('selectFont')) {
|
} else if (test.isNotValue('makeLink') | test.isNotValue('insertImage') | test.isNotValue('selectFont')) {
|
||||||
// do nothing these are dropdowns.
|
// do nothing these are dropdowns.
|
||||||
} else {
|
} else {
|
||||||
if (editor.getSelectedText() === '' && !(action == 'insertImage' || action == 'makeOrderedList' || action == 'increaseQuoteLevel' || action == 'redo' || action == 'undo')) return;
|
if (editor.getSelectedText() === '' && !(action == 'insertImage' || action == 'makeOrderedList' || action == 'increaseQuoteLevel' || action == 'redo' || action == 'undo' || action == "makeHeading")) return;
|
||||||
editor[action]();
|
editor[action]();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in a new issue