Skip to content

Commit 3da94ef

Browse files
author
Wes Cossick
committed
Better separator display/hide logic
1 parent 6b6bb40 commit 3da94ef

File tree

4 files changed

+86
-29
lines changed

4 files changed

+86
-29
lines changed

debug/simplemde.debug.js

Lines changed: 29 additions & 11 deletions
Large diffs are not rendered by default.

debug/simplemde.js

Lines changed: 28 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -13774,15 +13774,18 @@ var toolbarBuiltInButtons = {
1377413774
title: "Toggle Fullscreen",
1377513775
default: true
1377613776
},
13777+
"separator-4": {
13778+
name: "separator-4"
13779+
},
1377713780
"guide": {
1377813781
name: "guide",
1377913782
action: "http://nextstepwebs.github.io/simplemde-markdown-editor/markdown-guide",
1378013783
className: "fa fa-question-circle",
1378113784
title: "Markdown Guide",
1378213785
default: true
1378313786
},
13784-
"separator-4": {
13785-
name: "separator-4"
13787+
"separator-5": {
13788+
name: "separator-5"
1378613789
},
1378713790
"undo": {
1378813791
name: "undo",
@@ -14174,7 +14177,7 @@ SimpleMDE.prototype.createToolbar = function(items) {
1417414177

1417514178
var self = this;
1417614179

14177-
var toolbar_data = {};
14180+
var toolbarData = {};
1417814181
self.toolbar = items;
1417914182

1418014183
for(i = 0; i < items.length; i++) {
@@ -14189,6 +14192,23 @@ SimpleMDE.prototype.createToolbar = function(items) {
1418914192
if((items[i].name == "fullscreen" || items[i].name == "side-by-side") && isMobile())
1419014193
continue;
1419114194

14195+
14196+
// Don't include trailing separators
14197+
if(items[i] === "|") {
14198+
var nonSeparatorIconsFollow = false;
14199+
14200+
for(var x = (i + 1); x < items.length; x++) {
14201+
if(items[x] !== "|") {
14202+
nonSeparatorIconsFollow = true;
14203+
}
14204+
}
14205+
14206+
if(!nonSeparatorIconsFollow)
14207+
continue;
14208+
}
14209+
14210+
14211+
// Create the icon and append to the toolbar
1419214212
(function(item) {
1419314213
var el;
1419414214
if(item === "|") {
@@ -14208,20 +14228,21 @@ SimpleMDE.prototype.createToolbar = function(items) {
1420814228
el.target = "_blank";
1420914229
}
1421014230
}
14211-
toolbar_data[item.name || item] = el;
14231+
14232+
toolbarData[item.name || item] = el;
1421214233
bar.appendChild(el);
1421314234
})(items[i]);
1421414235
}
1421514236

14216-
self.toolbarElements = toolbar_data;
14237+
self.toolbarElements = toolbarData;
1421714238

1421814239
var cm = this.codemirror;
1421914240
cm.on("cursorActivity", function() {
1422014241
var stat = getState(cm);
1422114242

14222-
for(var key in toolbar_data) {
14243+
for(var key in toolbarData) {
1422314244
(function(key) {
14224-
var el = toolbar_data[key];
14245+
var el = toolbarData[key];
1422514246
if(stat[key]) {
1422614247
el.className += " active";
1422714248
} else if(key != "fullscreen" && key != "side-by-side") {
@@ -14333,9 +14354,6 @@ SimpleMDE.prototype.createStatusbar = function(status) {
1433314354
if(typeof item.onUpdate === "function") {
1433414355
// Create a closure around the span of the current action, then execute the onUpdate handler
1433514356
this.codemirror.on("update", (function(el, item) {
14336-
console.log(el);
14337-
console.log(item);
14338-
console.log("---------------");
1433914357
return function() {
1434014358
item.onUpdate(el);
1434114359
};

dist/simplemde.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/js/simplemde.js

Lines changed: 28 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -909,15 +909,18 @@ var toolbarBuiltInButtons = {
909909
title: "Toggle Fullscreen",
910910
default: true
911911
},
912+
"separator-4": {
913+
name: "separator-4"
914+
},
912915
"guide": {
913916
name: "guide",
914917
action: "http://nextstepwebs.github.io/simplemde-markdown-editor/markdown-guide",
915918
className: "fa fa-question-circle",
916919
title: "Markdown Guide",
917920
default: true
918921
},
919-
"separator-4": {
920-
name: "separator-4"
922+
"separator-5": {
923+
name: "separator-5"
921924
},
922925
"undo": {
923926
name: "undo",
@@ -1309,7 +1312,7 @@ SimpleMDE.prototype.createToolbar = function(items) {
13091312

13101313
var self = this;
13111314

1312-
var toolbar_data = {};
1315+
var toolbarData = {};
13131316
self.toolbar = items;
13141317

13151318
for(i = 0; i < items.length; i++) {
@@ -1324,6 +1327,23 @@ SimpleMDE.prototype.createToolbar = function(items) {
13241327
if((items[i].name == "fullscreen" || items[i].name == "side-by-side") && isMobile())
13251328
continue;
13261329

1330+
1331+
// Don't include trailing separators
1332+
if(items[i] === "|") {
1333+
var nonSeparatorIconsFollow = false;
1334+
1335+
for(var x = (i + 1); x < items.length; x++) {
1336+
if(items[x] !== "|") {
1337+
nonSeparatorIconsFollow = true;
1338+
}
1339+
}
1340+
1341+
if(!nonSeparatorIconsFollow)
1342+
continue;
1343+
}
1344+
1345+
1346+
// Create the icon and append to the toolbar
13271347
(function(item) {
13281348
var el;
13291349
if(item === "|") {
@@ -1343,20 +1363,21 @@ SimpleMDE.prototype.createToolbar = function(items) {
13431363
el.target = "_blank";
13441364
}
13451365
}
1346-
toolbar_data[item.name || item] = el;
1366+
1367+
toolbarData[item.name || item] = el;
13471368
bar.appendChild(el);
13481369
})(items[i]);
13491370
}
13501371

1351-
self.toolbarElements = toolbar_data;
1372+
self.toolbarElements = toolbarData;
13521373

13531374
var cm = this.codemirror;
13541375
cm.on("cursorActivity", function() {
13551376
var stat = getState(cm);
13561377

1357-
for(var key in toolbar_data) {
1378+
for(var key in toolbarData) {
13581379
(function(key) {
1359-
var el = toolbar_data[key];
1380+
var el = toolbarData[key];
13601381
if(stat[key]) {
13611382
el.className += " active";
13621383
} else if(key != "fullscreen" && key != "side-by-side") {

0 commit comments

Comments
 (0)