dante-editor 0.0.13 → 0.0.14
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +4 -1
- data/app/assets/javascripts/dante/editor.js.coffee +71 -56
- data/app/assets/javascripts/dante/tooltip_widgets/uploader.js.coffee +22 -15
- data/app/assets/stylesheets/dante/_scaffold.scss +4 -0
- data/bower.json +1 -1
- data/dist/css/dante-editor.css +156 -152
- data/dist/js/dante-editor.js +76 -56
- data/lib/dante-editor/version.rb +1 -1
- metadata +3 -3
data/dist/js/dante-editor.js
CHANGED
@@ -8,7 +8,7 @@
|
|
8
8
|
defaults: {
|
9
9
|
image_placeholder: '../images/dante/media-loading-placeholder.png'
|
10
10
|
},
|
11
|
-
version: "0.0.
|
11
|
+
version: "0.0.14"
|
12
12
|
};
|
13
13
|
|
14
14
|
}).call(this);
|
@@ -747,24 +747,24 @@
|
|
747
747
|
return a === b;
|
748
748
|
};
|
749
749
|
|
750
|
-
Editor.prototype.setRangeAt = function(element,
|
750
|
+
Editor.prototype.setRangeAt = function(element, pos) {
|
751
751
|
var range, sel;
|
752
|
-
if (
|
753
|
-
|
752
|
+
if (pos == null) {
|
753
|
+
pos = 0;
|
754
754
|
}
|
755
755
|
range = document.createRange();
|
756
756
|
sel = window.getSelection();
|
757
|
-
range.setStart(element,
|
757
|
+
range.setStart(element, pos);
|
758
758
|
range.collapse(true);
|
759
759
|
sel.removeAllRanges();
|
760
760
|
sel.addRange(range);
|
761
761
|
return element.focus();
|
762
762
|
};
|
763
763
|
|
764
|
-
Editor.prototype.setRangeAtText = function(element,
|
764
|
+
Editor.prototype.setRangeAtText = function(element, pos) {
|
765
765
|
var node, range, sel;
|
766
|
-
if (
|
767
|
-
|
766
|
+
if (pos == null) {
|
767
|
+
pos = 0;
|
768
768
|
}
|
769
769
|
range = document.createRange();
|
770
770
|
sel = window.getSelection();
|
@@ -1002,7 +1002,7 @@
|
|
1002
1002
|
break;
|
1003
1003
|
case "Up":
|
1004
1004
|
prev_node = current_node.prev();
|
1005
|
-
utils.log("PREV NODE IS " + (prev_node.attr('class')));
|
1005
|
+
utils.log("PREV NODE IS " + (prev_node.attr('class')) + " " + (prev_node.attr('name')));
|
1006
1006
|
utils.log("CURRENT NODE IS up " + (current_node.attr('class')));
|
1007
1007
|
if (!$(current_node).hasClass("graf")) {
|
1008
1008
|
return;
|
@@ -1047,8 +1047,8 @@
|
|
1047
1047
|
|
1048
1048
|
Editor.prototype.parseInitialMess = function() {
|
1049
1049
|
return this.setupElementsClasses($(this.el).find('.section-inner'), (function(_this) {
|
1050
|
-
return function() {
|
1051
|
-
return _this.handleUnwrappedImages(
|
1050
|
+
return function(e) {
|
1051
|
+
return _this.handleUnwrappedImages(e);
|
1052
1052
|
};
|
1053
1053
|
})(this));
|
1054
1054
|
};
|
@@ -1079,24 +1079,24 @@
|
|
1079
1079
|
utils.log("HTML DETECTED ON PASTE");
|
1080
1080
|
pastedText = pastedText.replace(/&.*;/g, "");
|
1081
1081
|
pastedText = pastedText.replace(/<div>([\w\W]*?)<\/div>/gi, '<p>$1</p>');
|
1082
|
-
document.body.appendChild($("<div id='" + (this.paste_element_id.replace('#', '')) + "'></div>")[0]);
|
1082
|
+
document.body.appendChild($("<div id='" + (this.paste_element_id.replace('#', '')) + "' class='dante-paste'></div>")[0]);
|
1083
1083
|
$(this.paste_element_id).html("<span>" + pastedText + "</span>");
|
1084
1084
|
this.setupElementsClasses($(this.paste_element_id), (function(_this) {
|
1085
|
-
return function() {
|
1085
|
+
return function(e) {
|
1086
1086
|
var last_node, new_node, nodes, num, top;
|
1087
|
-
nodes = $(
|
1088
|
-
|
1087
|
+
nodes = $(e.html()).insertAfter($(_this.aa));
|
1088
|
+
e.remove();
|
1089
1089
|
last_node = nodes.last()[0];
|
1090
1090
|
num = last_node.childNodes.length;
|
1091
1091
|
_this.setRangeAt(last_node, num);
|
1092
1092
|
new_node = $(_this.getNode());
|
1093
|
-
top = new_node.offset().top;
|
1094
1093
|
_this.markAsSelected(new_node);
|
1095
1094
|
_this.displayTooltipAt($(_this.el).find(".is-selected"));
|
1096
1095
|
_this.handleUnwrappedImages(nodes);
|
1096
|
+
top = new_node.offset().top;
|
1097
1097
|
return $('html, body').animate({
|
1098
1098
|
scrollTop: top
|
1099
|
-
},
|
1099
|
+
}, 20);
|
1100
1100
|
};
|
1101
1101
|
})(this));
|
1102
1102
|
return false;
|
@@ -1156,6 +1156,7 @@
|
|
1156
1156
|
node = $(range.commonAncestorContainer);
|
1157
1157
|
prev = node.prev();
|
1158
1158
|
num = prev[0].childNodes.length;
|
1159
|
+
utils.log("PREV NODE");
|
1159
1160
|
utils.log(prev);
|
1160
1161
|
if (prev.hasClass("graf")) {
|
1161
1162
|
this.setRangeAt(prev[0], num);
|
@@ -1165,6 +1166,8 @@
|
|
1165
1166
|
this.setRangeAt(prev[0], num);
|
1166
1167
|
node.remove();
|
1167
1168
|
this.markAsSelected(this.getNode());
|
1169
|
+
} else if (prev.hasClass("postList")) {
|
1170
|
+
this.setRangeAt(prev.find("li").last()[0]);
|
1168
1171
|
} else if (!prev) {
|
1169
1172
|
this.setRangeAt(this.$el.find(".section-inner p")[0]);
|
1170
1173
|
}
|
@@ -1304,21 +1307,22 @@
|
|
1304
1307
|
utils.log("HANDLING WIDGET BACKSPACES");
|
1305
1308
|
_.each(this.widgets, (function(_this) {
|
1306
1309
|
return function(w) {
|
1307
|
-
|
1308
|
-
|
1309
|
-
return
|
1310
|
+
if (_.isFunction(w.handleBackspaceKey) && !eventHandled) {
|
1311
|
+
eventHandled = w.handleBackspaceKey(e, anchor_node);
|
1312
|
+
return utils.log(eventHandled);
|
1310
1313
|
}
|
1311
1314
|
};
|
1312
1315
|
})(this));
|
1313
1316
|
if (eventHandled) {
|
1314
1317
|
e.preventDefault();
|
1318
|
+
utils.log("SCAPE FROM BACKSPACE HANDLER");
|
1315
1319
|
return false;
|
1316
1320
|
}
|
1317
1321
|
if (parent.hasClass("graf--li") && this.getCharacterPrecedingCaret().length === 0) {
|
1318
1322
|
return this.handleListBackspace(parent, e);
|
1319
1323
|
}
|
1320
|
-
if ($(anchor_node).hasClass("graf--p") && this.isFirstChar) {
|
1321
|
-
if ($(anchor_node).prev().hasClass("graf--figure")) {
|
1324
|
+
if ($(anchor_node).hasClass("graf--p") && this.isFirstChar()) {
|
1325
|
+
if ($(anchor_node).prev().hasClass("graf--figure") && this.getSelectedText().length === 0) {
|
1322
1326
|
e.preventDefault();
|
1323
1327
|
$(anchor_node).prev().find("img").click();
|
1324
1328
|
utils.log("Focus on the previous image");
|
@@ -1468,6 +1472,7 @@
|
|
1468
1472
|
};
|
1469
1473
|
|
1470
1474
|
Editor.prototype.markAsSelected = function(element) {
|
1475
|
+
utils.log(element);
|
1471
1476
|
if (_.isUndefined(element)) {
|
1472
1477
|
return;
|
1473
1478
|
}
|
@@ -1555,36 +1560,37 @@
|
|
1555
1560
|
|
1556
1561
|
Editor.prototype.setupElementsClasses = function(element, cb) {
|
1557
1562
|
if (_.isUndefined(element)) {
|
1558
|
-
|
1563
|
+
element = $(this.el).find('.section-inner');
|
1559
1564
|
} else {
|
1560
|
-
|
1565
|
+
element = element;
|
1561
1566
|
}
|
1562
|
-
|
1563
|
-
|
1564
|
-
|
1565
|
-
|
1566
|
-
|
1567
|
-
|
1568
|
-
|
1569
|
-
|
1570
|
-
return _this.setElementName(n);
|
1571
|
-
});
|
1572
|
-
_this.setupLinks(_this.element.find("a"));
|
1573
|
-
_this.setupFirstAndLast();
|
1574
|
-
if (_.isFunction(cb)) {
|
1575
|
-
return cb();
|
1576
|
-
}
|
1567
|
+
this.cleanContents(element);
|
1568
|
+
this.wrapTextNodes(element);
|
1569
|
+
_.each(element.children(), (function(_this) {
|
1570
|
+
return function(n) {
|
1571
|
+
var name;
|
1572
|
+
name = $(n).prop("tagName").toLowerCase();
|
1573
|
+
n = _this.addClassesToElement(n);
|
1574
|
+
return _this.setElementName(n);
|
1577
1575
|
};
|
1578
|
-
})(this)
|
1576
|
+
})(this));
|
1577
|
+
this.setupLinks(element.find("a"));
|
1578
|
+
this.setupFirstAndLast();
|
1579
|
+
if (_.isFunction(cb)) {
|
1580
|
+
return cb(element);
|
1581
|
+
}
|
1579
1582
|
};
|
1580
1583
|
|
1581
1584
|
Editor.prototype.cleanContents = function(element) {
|
1582
|
-
var s;
|
1585
|
+
var paste_div, s;
|
1586
|
+
utils.log("ti");
|
1587
|
+
utils.log(element);
|
1583
1588
|
if (_.isUndefined(element)) {
|
1584
|
-
|
1589
|
+
element = $(this.el).find('.section-inner');
|
1585
1590
|
} else {
|
1586
|
-
|
1591
|
+
element = element;
|
1587
1592
|
}
|
1593
|
+
paste_div = this.paste_element_id;
|
1588
1594
|
s = new Sanitize({
|
1589
1595
|
elements: ['strong', 'img', 'em', 'br', 'a', 'blockquote', 'b', 'u', 'i', 'pre', 'p', 'h1', 'h2', 'h3', 'h4', 'ul', 'ol', 'li'],
|
1590
1596
|
attributes: {
|
@@ -1603,6 +1609,11 @@
|
|
1603
1609
|
return {
|
1604
1610
|
whitelist_nodes: [input.node]
|
1605
1611
|
};
|
1612
|
+
}
|
1613
|
+
if ($(input.node).hasClass("dante-paste")) {
|
1614
|
+
return {
|
1615
|
+
whitelist_nodes: [input.node]
|
1616
|
+
};
|
1606
1617
|
} else {
|
1607
1618
|
return null;
|
1608
1619
|
}
|
@@ -1673,9 +1684,9 @@
|
|
1673
1684
|
}
|
1674
1685
|
]
|
1675
1686
|
});
|
1676
|
-
if (
|
1677
|
-
utils.log("CLEAN HTML " +
|
1678
|
-
return
|
1687
|
+
if (element.exists()) {
|
1688
|
+
utils.log("CLEAN HTML " + element[0].tagName);
|
1689
|
+
return element.html(s.clean_node(element[0]));
|
1679
1690
|
}
|
1680
1691
|
};
|
1681
1692
|
|
@@ -1835,7 +1846,7 @@
|
|
1835
1846
|
content = $li.html();
|
1836
1847
|
this.replaceWith("p", $li);
|
1837
1848
|
$paragraph = $(".is-selected");
|
1838
|
-
$paragraph.removeClass("graf--empty").html(content);
|
1849
|
+
$paragraph.removeClass("graf--empty").html(content).attr("name", utils.generateUniqueName());
|
1839
1850
|
if ($list.children().length === 0) {
|
1840
1851
|
$list.remove();
|
1841
1852
|
}
|
@@ -1930,7 +1941,7 @@
|
|
1930
1941
|
};
|
1931
1942
|
|
1932
1943
|
Uploader.prototype.uploadExistentImage = function(image_element, opts) {
|
1933
|
-
var i,
|
1944
|
+
var i, n, node, tmpl, _i, _ref, _results;
|
1934
1945
|
if (opts == null) {
|
1935
1946
|
opts = {};
|
1936
1947
|
}
|
@@ -1950,18 +1961,18 @@
|
|
1950
1961
|
}
|
1951
1962
|
} else {
|
1952
1963
|
utils.log("DOS");
|
1953
|
-
|
1954
|
-
$(img).replaceWith(tmpl);
|
1964
|
+
$(image_element).replaceWith(tmpl);
|
1955
1965
|
}
|
1956
1966
|
utils.log($("[name='" + (tmpl.attr('name')) + "']").attr("name"));
|
1957
1967
|
this.replaceImg(image_element, $("[name='" + (tmpl.attr('name')) + "']"));
|
1958
1968
|
n = $("[name='" + (tmpl.attr('name')) + "']").parentsUntil(".section-inner").length;
|
1959
1969
|
if (n !== 0) {
|
1970
|
+
_results = [];
|
1960
1971
|
for (i = _i = 0, _ref = n - 1; _i <= _ref; i = _i += 1) {
|
1961
|
-
$("[name='" + (tmpl.attr('name')) + "']").unwrap();
|
1972
|
+
_results.push($("[name='" + (tmpl.attr('name')) + "']").unwrap());
|
1962
1973
|
}
|
1974
|
+
return _results;
|
1963
1975
|
}
|
1964
|
-
return utils.log("FIG");
|
1965
1976
|
};
|
1966
1977
|
|
1967
1978
|
Uploader.prototype.replaceImg = function(image_element, figure) {
|
@@ -2163,18 +2174,27 @@
|
|
2163
2174
|
* @param {Event} e - The backspace event that is being handled
|
2164
2175
|
* @param {Node} node - The node the backspace was used in, assumed to be from te editor's getNode() function
|
2165
2176
|
*
|
2166
|
-
* @return {Boolean} true if this function
|
2177
|
+
* @return {Boolean} true if this function should scape the default behavior
|
2167
2178
|
*/
|
2168
2179
|
|
2169
2180
|
Uploader.prototype.handleBackspaceKey = function(e, node) {
|
2170
|
-
|
2181
|
+
var anchor_node;
|
2182
|
+
utils.log("handleBackspaceKey on uploader widget");
|
2183
|
+
if ($(node).hasClass("is-selected") && $(node).hasClass("graf--figure")) {
|
2184
|
+
anchor_node = this.current_editor.selection().anchorNode;
|
2185
|
+
if ((anchor_node != null) && $(anchor_node.parentNode).hasClass("imageCaption")) {
|
2186
|
+
if (this.current_editor.isFirstChar()) {
|
2187
|
+
return true;
|
2188
|
+
} else {
|
2189
|
+
return false;
|
2190
|
+
}
|
2191
|
+
}
|
2192
|
+
} else if ($(".is-selected").hasClass("is-mediaFocused")) {
|
2171
2193
|
utils.log("Replacing selected node");
|
2172
2194
|
this.current_editor.replaceWith("p", $(".is-selected"));
|
2173
|
-
e.preventDefault();
|
2174
2195
|
this.current_editor.setRangeAt($(".is-selected")[0]);
|
2175
2196
|
return true;
|
2176
2197
|
}
|
2177
|
-
return false;
|
2178
2198
|
};
|
2179
2199
|
|
2180
2200
|
return Uploader;
|
data/lib/dante-editor/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: dante-editor
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.14
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Miguel Michelson
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2015-
|
12
|
+
date: 2015-08-10 00:00:00.000000000 Z
|
13
13
|
dependencies: []
|
14
14
|
description: dante-editor yet another Medium editor clone.
|
15
15
|
email:
|
@@ -141,7 +141,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
141
141
|
version: '0'
|
142
142
|
requirements: []
|
143
143
|
rubyforge_project:
|
144
|
-
rubygems_version: 2.
|
144
|
+
rubygems_version: 2.4.8
|
145
145
|
signing_key:
|
146
146
|
specification_version: 4
|
147
147
|
summary: dante-editor yet another Medium editor clone.
|