forked from aranm/scalable-javascript-architecture
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Core.DomManipulation.js
92 lines (82 loc) · 2.98 KB
/
Core.DomManipulation.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
/*globals Core, $*/
(function() {
var coreDomManipulation = function($, document) {
var elementMappings = { };
var domManipulation = {
setCssLeftOnElement: function(element, value) {
$(element).css({ left: value + 'px' });
},
setCssRightOnElement: function(element, value) {
$(element).css({ right: value + 'px' });
},
setVisible: function(element, isVisible) {
if (isVisible) {
$(element).show();
} else {
$(element).hide();
}
},
animatedHide: function(element, completedCallback) {
$(element).hide('slow', 'swing', completedCallback);
},
animatedShow: function(element, completedCallback) {
$(element).show('slow', 'swing', completedCallback);
},
animatedShowRightToLeft: function(element, completedCallback) {
$(element).show('slide', { direction: 'right' }, 500, completedCallback);
},
animatedHideLeftToRight: function(element, completedCallback) {
$(element).hide('slide', { direction: 'right' }, 500, completedCallback);
},
fadeIn: function(element, completedCallback) {
$(element).fadeIn('fast', 'swing', completedCallback);
},
fadeOut: function(element, completedCallback) {
$(element).fadeOut('fast', 'swing', completedCallback);
}
};
return {
addMapping: function(name, domElement) {
elementMappings[name] = domElement;
},
removeMapping: function(name) {
delete elementMappings[name];
},
getDom: function() {
return domManipulation;
},
openDialog: function(name, closedCallback) {
var closedFunction,
element = $(elementMappings[name]);
closedFunction = function () {
//unbind the 'hide' event
element.unbind('hidden', closedFunction);
if (closedCallback !== undefined && typeof closedCallback === "function") {
closedCallback();
}
};
//show the dialog
element.modal('show');
//attach an event to the "hide"
element.bind('hidden', closedFunction);
},
closeDialog: function(name) {
var element = $(elementMappings[name]);
element.modal('hide');
},
setDocumentTitle: function(newTitle) {
document.title = newTitle;
}
};
};
//manage require module loading scenario
if (typeof define === "function" && define.amd) {
define("Core.DomManipulation", ["Core", "jquery"], function (core, jQuery) {
core.DomManipulation = coreDomManipulation(jQuery, document);
return core.DomManipulation;
});
}
else {
Core.DomManipulation = coreDomManipulation($, document);
}
})();