Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change the way that headings are applied to elements so that they no longer destroy the parent element by replacing the original tag. #5

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions css/editor.css
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,21 @@ body {
font-size: 2em;
}

.g-body .h1 {
font-weight: bold;
font-size: 2em;
}

.g-body .h2 {
font-weight: bold;
font-size: 1.5em;
}

.g-body .h3 {
font-weight: bold;
font-size: 1.17em;
}

.g-body header {
font-weight: bold;
font-size: 52px;
Expand Down
3 changes: 2 additions & 1 deletion css/menu.css
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@
margin-top: -28px;
z-index: 1000;
padding: 5px 4px 5px 5px;
width: 176px;
width: 205px;
height: 33px;

-webkit-transition: all 300ms ease-in-out;
Expand All @@ -78,6 +78,7 @@

.options.url-mode .header1,
.options.url-mode .header2,
.options.url-mode .header3,
.options.url-mode .bold,
.options.url-mode .italic,
.options.url-mode .quote,
Expand Down
1 change: 1 addition & 0 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
<button class="italic">i</button>
<button class="header1">h1</button>
<button class="header2">h2</button>
<button class="header3">h3</button>
<button class="quote">&rdquo;</button>
<button class="url useicons">&#xe001;</button>
<input class="url-input" type="text" placeholder="Paste or type a link"/>
Expand Down
19 changes: 16 additions & 3 deletions js/grande.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
"i": "italic",
"h1": "header1",
"h2": "header2",
"h3": "header3",
"a": "url",
"blockquote": "quote"
};
Expand Down Expand Up @@ -85,6 +86,7 @@
function reloadMenuState() {
var className,
focusNode = getFocusNode(),
elemClass = focusNode.parentNode.className,
tagClass,
reTag;

Expand All @@ -96,7 +98,7 @@
reTag = new RegExp(tagClass);

if (reTag.test(className)) {
if (hasParentWithTag(focusNode, tag)) {
if (hasParentWithTag(focusNode, tag) || elemClass.match(tag)) {
node.className = tagClass + " active";
} else {
node.className = tagClass;
Expand Down Expand Up @@ -192,14 +194,14 @@
case "i":
document.execCommand(tagClass, false);
return;

case "h1":
case "h2":
case "h3":
toggleFormatHeading(tag);
return;
case "blockquote":
toggleFormatBlock(tag);
return;

case "a":
toggleUrlInput();
optionsNode.className = "options url-mode";
Expand Down Expand Up @@ -250,6 +252,17 @@
}
}

function toggleFormatHeading(tag) {
node = getFocusNode().parentNode;
if (node.className.match(tag)) {
node.className = node.className.replace(new RegExp('\\b' + tag + '\\b'), '').trim();
} else {
// Remove existing class and trim
node.className = node.className.replace(new RegExp('\\b(h1|h2|h3)\\b'), '').trim();
node.className += ' ' + tag;
}
}

function toggleUrlInput() {
setTimeout(function() {
var url = getParentHref(getFocusNode());
Expand Down