/
non-react.js
80 lines (65 loc) · 1.94 KB
/
non-react.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
var SG = SG || {};
SG.users_index = function(){
init();
//EVENTS
$('.m-user-column--edit-button').on('click', function(e){ clickEditButton($(this)); });
$('.m-user-column--cancel-button').on('click', function(e){ clickCancelButton($(this)); });
$('.m-user-column--delete-btn').on('click', function(e){ clickDeleteButton($(this)); });
//METHODS
function clickDeleteButton($this){
var
$el = $this.parent('.m-user-column--deal-alert'),
id = $el.data('deal-id'),
$loader = $('<div>', {class:'m-user-column--loader'});
$('#email-alerts').append($loader);
//remove that id via api call
$.ajax({
url: '/api/3.0.0/alerts/' + id + '.json',
type: 'DELETE',
success: function(){
$el.remove();
$loader.remove();
notify();
},
error: function(){
$loader.remove();
notify({type: 'error', msg: 'Sorry, try again later'});
}
});
}
function clickCancelButton($this){
var
section = $this.data('section'),
$section = $('#' + section);
$section.removeClass('editable');
}
function clickEditButton($this){
var
section = $this.data('section'),
$section = $('#' + section),
done_text = $this.data('donetext'),
edit_text = $this.data('edittext');
if($section.hasClass('editable')){
$this.html(edit_text);
$section.removeClass('editable');
}
else{
$this.html(done_text);
$section.addClass('editable');
}
}
function init(){
//make the edit buttons appear at same height on desktop
if(Modernizr.mq('only screen and (min-width: 768px)')){
$('.m-user-column--top-row').equalHeights();
}
//use masonry to flow my reviews into 2 columns
$(window).load(function(){
$('#review-wrap').masonry({
columnWidth: '.grid-sizer',
gutter: '.l-user--my-review-gutter',
itemSelector: '.l-user--my-review-wrap'
});
});
}
}