-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathelements.js
More file actions
124 lines (107 loc) · 3.26 KB
/
elements.js
File metadata and controls
124 lines (107 loc) · 3.26 KB
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
function getJElement(config) {
var type = config.html || 'div';
var jElement = $('<' + type + '/>');
jElement.attr('class', config.cls);
if (config.items) {
for (var i = 0; i < config.items.length; i++) {
jElement.append(config.items[i]);
}
}
if (config.attributes) {
for (var i = 0; i < config.attributes.length; i++) {
jElement.attr(config.attributes[i].name, config.attributes[i].value);
}
}
return jElement;
}
function noteGenerator(config) {
var dragMe = getJElement({
cls: [SSN.cls.dragMeLabel, SSN.cls.text].join(' '),
items: [chrome.i18n.getMessage("dragMe")]
});
var jActions = getJElement({
cls: SSN.cls.noteActions,
items: []
});
var jNoteEditableContent;
if (config.editable) {
jActions.append(dragMe);
jNoteEditableContent = getJElement({
items: [],
html: "textArea",
cls: [SSN.cls.editableContent, SSN.cls.text].join(' '),
attributes: [{name: "placeHolder", value: chrome.i18n.getMessage("typeMe")}]
});
}
var jNoteContent = getJElement({
html: "div",
cls: [SSN.clsSelectors.resizable, SSN.cls.noteContent, SSN.cls.text].join(' '),
items: [config.obj.note],
attributes: config.contentAttributes
});
var jNoteItems = [jActions];
if (config.editable) {
jNoteItems.push(jNoteEditableContent);
} else {
jNoteItems.push(jNoteContent);
}
var jNote = getJElement({
cls: [SSN.cls.note, SSN.clsSelectors.widgetContent].join(' '),
items: jNoteItems
});
jNote.css('left', Number(config.obj.x)).css('top', Number(config.obj.y))
.css("background-color", getValidColor(config.backgroundColor, "ffff00"));
if (config.editable) {
jNote.attr(SSN.specialAttributes.removeAll, SSN.consts.removeFalse);
} else {
jNote.attr(SSN.specialAttributes.removeAll, SSN.consts.removeTrue);
}
if (config.renderTo)
jNote.appendTo($(config.renderTo));
jNote.draggable({
containment: document.body,
zIndex: 10000
});
var dragStop = function(){};
var dragStart = function(){};
if (config.firstDragStart)
dragStart = config.firstDragStart;
if (config.firstDragStop)
dragStop = config.firstDragStop;
jNote.bind(SSN.events.dragStop, function(event, ui) {
if (config.editable && jNoteEditableContent) {
var val = jNoteEditableContent.val();
jNoteEditableContent.remove();
jNoteContent.append(val);
jNote.append(jNoteContent);
jNoteEditableContent = null;
}
SSN.states.zIndex++;
jNote.css("zIndex", SSN.states.zIndex);
dragStop(event, ui);
if (config.stopDraggable)
config.stopDraggable(event, ui);
dragStop = function(){};
jNote.attr(SSN.specialAttributes.removeAll, SSN.consts.removeTrue);
});
jNote.bind(SSN.events.dragStart, function(event, ui) {
dragStart(event, ui);
dragStart = function(){};
if (config.startDraggable)
config.startDraggable(event, ui);
});
return jNote;
}
function addRemoveAction(onRemove, target) {
var jRemoveAction = getJElement({
cls: [SSN.cls.noteRemoveAction, SSN.cls.managableActions].join(' ')
});
jRemoveAction.click(function(){
target.remove();
onRemove();
});
target.find("." + SSN.cls.noteActions).append(jRemoveAction);
}
function clearActions(target) {
target.find("." + SSN.cls.noteActions).empty();
}