-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathsummernote-list-styles.js
141 lines (132 loc) · 4.36 KB
/
summernote-list-styles.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
/* https://github.com/tylerecouture/summernote-lists */
(function(factory) {
/* global define */
if (typeof define === "function" && define.amd) {
// AMD. Register as an anonymous module.
define(["jquery"], factory);
} else if (typeof module === "object" && module.exports) {
// Node/CommonJS
module.exports = factory(require("jquery"));
} else {
// Browser globals
factory(window.jQuery);
}
})(function($) {
$.extend(true, $.summernote.lang, {
"en-US": {
listStyleTypes: {
tooltip: "List Styles",
labelsListStyleTypes: [
"Numbered",
"Lower Alpha",
"Upper Alpha",
"Lower Roman",
"Upper Roman",
"Disc",
"Circle",
"Square"
]
}
}
});
$.extend($.summernote.options, {
listStyleTypes: {
/* Must keep the same order as in lang.imageAttributes.tooltipShapeOptions */
styles: [
"decimal",
"lower-alpha",
"upper-alpha",
"lower-roman",
"upper-roman",
"disc",
"circle",
"square"
]
}
});
// Extends plugins for emoji plugin.
$.extend($.summernote.plugins, {
listStyles: function(context) {
var self = this;
var ui = $.summernote.ui;
var options = context.options;
var lang = options.langInfo;
var listStyleTypes = options.listStyleTypes.styles;
var listStyleLabels = lang.listStyleTypes.labelsListStyleTypes;
var list = "";
for (var i = 0; i < listStyleTypes.length; i++) {
list += '<li><a href="#" data-value=' + listStyleTypes[i] + ">";
list += '<i class="note-icon-menu-check pull-left"></i>';
list += '<ol><li style="list-style-type: ' + listStyleTypes[i] + ';">';
list += listStyleLabels[i] + "</li></ol></a></li>";
}
context.memo("button.listStyles", function() {
return ui
.buttonGroup([
ui.button({
className: "dropdown-toggle list-styles",
contents: ui.icon(options.icons.caret, "span"),
tooltip: lang.listStyleTypes.tooltip,
data: {
toggle: "dropdown"
},
callback: function ($dropdownBtn) {
$dropdownBtn.click(function (e) {
e.preventDefault();
self.updateListStyleMenuState($dropdownBtn);
})
}
}),
ui.dropdownCheck({
className: "dropdown-list-styles",
checkClassName: options.icons.menuCheck,
contents: list,
callback: function($dropdown) {
$dropdown.find("a").each(function() {
$(this).click(function(e) {
e.preventDefault();
self.updateStyleType( $(this).data("value") )
});
});
} // callback
}),
])
.render();
})
/* Makes sure the check marks are on the currently applied styles */
self.updateListStyleMenuState = function($dropdownButton) {
var $selectedtList = self.getParentList();
var selectedListStyleType = $selectedtList.css('list-style-type')
console.log(selectedListStyleType);
//console.log($parentList.attr('list-style-type'));
var $listItems = $dropdownButton.next().find("a");
var styleFound = false;
$listItems.each(function() {
var itemListStyleType = $(this).data("value");
if (selectedListStyleType == itemListStyleType) {
$(this).addClass("checked");
styleFound = true;
} else {
$(this).removeClass("checked");
}
if( !styleFound ) { // check the default style
$listItems.filter('[data-value=""]').addClass("checked");
}
});
}
self.updateStyleType = function(style) {
context.invoke("beforeCommand");
self.getParentList().css("list-style-type", style);
context.invoke("afterCommand");
}
self.getParentList = function () {
if (window.getSelection) {
var $focusNode = $(window.getSelection().focusNode);
var $parentList = $focusNode.closest("div.note-editable ol, div.note-editable ul");
return $parentList;
}
return null;
}
}
});
});