-
Notifications
You must be signed in to change notification settings - Fork 8
/
CardViewerController.js
157 lines (131 loc) · 5.6 KB
/
CardViewerController.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
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
({
initScripts: function(component, event, helper) {
// The objs parameter from the event contains objects returned in the requirejs callback
var objs = event.getParams().objs;
// Use $j rather than $ to avoid jQuery conflicts
if (typeof jQuery !== "undefined" && typeof $j === "undefined") {
$j = jQuery.noConflict(true);
}
// hack to update CSS for page background color when being used in S1
$j('.oneContent').attr("style", "background: #fff");
helper.getIdeas(component);
// Cute UI effects for top tab navigation that does the filtering
var classname = document.getElementsByClassName("tabitem");
var clickFunction = function(e) {
var a = this.getElementsByTagName("a")[0];
var span = this.getElementsByTagName("span")[0];
for(var i=0;i<classname.length;i++){
classname[i].className = classname[i].className.replace(/(?:^|\s)active(?!\S)/g, '');
}
this.className += " active";
span.className += 'active';
var left = a.getBoundingClientRect().left;
var top = a.getBoundingClientRect().top;
var consx = (e.clientX - left);
var consy = (e.clientY - top);
span.style.top = consy+"px";
span.style.left = consx+"px";
span.className = 'clicked';
span.addEventListener('webkitAnimationEnd', function(event){
this.className = '';
}, false);
};
for(var i=0;i<classname.length;i++){
classname[i].addEventListener('click', clickFunction, false);
classname[i].addEventListener('touchstart', clickFunction, false);
}
// Big hack to keep the Create Idea button in the lower right in S1, as fixed position CSS will not work
setInterval(function(){
// Height of DIV
var gridHeight = $j("#grid-gallery").outerHeight();
// Height from top of DIV
var gridGapAbs = Math.abs($j("#grid-gallery").offset().top);
var gridGapReal = $j("#grid-gallery").offset().top;
var salesforce1 = 0;
// If in Sf1
if( $j('div.pullToRefresh').length > 0 ) {
salesforce1 = -10;
}
else {
salesforce1 = -50;
}
var gridGap = '';
if (gridGapReal > 0)
{
gridGap = -108 - salesforce1;
}
else
{
gridGap = gridGapAbs - salesforce1;
}
var viewportHeight = $j(window).height();
var distanceToTop = $j(window).scrollTop();
var bottomPosition = gridGap + distanceToTop + viewportHeight - 10;
$j('#createidea').css("top", bottomPosition);
},1000);
$j('#ideadetail').on('hidden.bs.modal', function (e) {
component.set("v.newIdeaComment.CommentBody", "");
})
},
getFilterTop : function(cmp, evt) {
var iso = cmp.get("v.objIsotope");
iso.arrange({ sortBy: 'votescore', sortAscending : false });
},
getFilterVoteTotal : function(cmp, evt) {
var iso = cmp.get("v.objIsotope");
iso.arrange({ sortBy: 'votetotal', sortAscending : false });
},
getFilterOriginal : function(cmp, evt) {
var iso = cmp.get("v.objIsotope");
iso.arrange({ sortBy: 'original-order'});
},
getFilterFresh : function(cmp, evt) {
var iso = cmp.get("v.objIsotope");
iso.arrange({ sortBy: 'freshdate', sortAscending : false });
},
getFilterComments : function(cmp, evt) {
var iso = cmp.get("v.objIsotope");
iso.arrange({ sortBy: 'numcomments', sortAscending : false });
},
getFilterAll : function(cmp, evt) {
var iso = cmp.get("v.objIsotope");
iso.arrange({ filter: '*'});
},
postIdea : function(component, event, helper)
{
var newIdea = component.get("v.newIdea");
helper.createIdea(component, newIdea);
},
postIdeaComment : function(component, event, helper)
{
var newIdeaComment = component.get("v.newIdeaComment");
var selectedItem = event.currentTarget;
var selectedId = selectedItem.dataset.ideaid;
helper.createIdeaComment(component, newIdeaComment, selectedId);
// Reset the form UI
component.set("v.newIdeaComment.CommentBody", "");
},
openIdeaDetail : function(component, event, helper)
{
var idea = component.get("v.idea");
var selectedItem = event.currentTarget;
var selectedId = selectedItem.dataset.ideaid;
var evt = $A.get("e.jmb:OpenIdea");
evt.setParams({
"currentIdeaId": selectedId
});
evt.fire();
helper.getIdea(component, selectedId);
$j('#ideadetail').modal('show');
},
changeField : function(component, evt, helper){
// Thanks for the tip from https://developer.salesforce.com/forums/?id=906F0000000ArG9IAK
// Enrecco - https://developer.salesforce.com/forums/ForumsProfile?communityId=09aF00000004HMG&userId=005F0000003FkoS&showHeader=false
//gets the html element from the change event
var textarea = evt.srcElement;
//sets a "textareaValue" attribute of the general component
$A.run(function(){
component.set('v.newIdea.Body',textarea.value);
});
},
})