summaryrefslogtreecommitdiff
path: root/plugins/Customizer/Assets/js/customizer.js
blob: ae7c4f13007215325030e616fd7cebe01d0b1e62 (plain)
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
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
//Functionality for a slider value feedback

var header_logo_output = $('header_logo_output')[0];

$(document).on('input', 'input[name="headerlogo_size"]', function(e) {
  header_logo_output.innerHTML = e.currentTarget.value;
  document.getElementById("hl1").style.height = e.currentTarget.value + "px";
});

var login_logo_output = $('login_logo_output')[0];

$(document).on('input', 'input[name="loginlogo_size"]', function(e) {
  login_logo_output.innerHTML = e.currentTarget.value;
  document.getElementById("ll1").style.height = e.currentTarget.value + "px";
});

var av_icon_output = $('av_icon_output')[0];

$(document).on('input', 'input[name="av_size"]', function(e) {
  var siz = e.currentTarget.value;
  av_icon_output.innerHTML = siz;
  if (document.querySelector(".avatar-preview .avatar-letter") !== null) {
  document.querySelector(".avatar-preview .avatar-letter").style.lineHeight = siz + "px";
  document.querySelector(".avatar-preview .avatar-letter").style.width = siz + "px";
  document.querySelector(".avatar-preview .avatar-letter").style.fontSize = (siz / 2) + "px";
  } else {
  var link = document.querySelector(".avatar-preview img").src;
  var changedLink = link.substring(0, link.length-2);
  document.querySelector(".avatar-preview img").src = changedLink + siz;
  }
});

var av_radius_output = $('av_radius_output')[0];

$(document).on('input', 'input[name="av_radius"]', function(e) {
  var rad = e.currentTarget.value;
  av_radius_output.innerHTML = rad;
  if (document.querySelector(".avatar-preview .avatar-letter") !== null) {
  document.querySelector(".avatar-preview .avatar-letter").style.borderRadius = rad + "%";
  } else {
  document.querySelector(".avatar-preview img").style.borderRadius = rad + "%";
  }
});

var b_av_icon_output = $('b_av_icon_output')[0];

$(document).on('input', 'input[name="b_av_size"]', function(e) {
  var siz = e.currentTarget.value;
  b_av_icon_output.innerHTML = siz;
  if (document.querySelector(".b-avatar-preview .avatar-letter") !== null) {
  document.querySelector(".b-avatar-preview .avatar-letter").style.lineHeight = siz + "px";
  document.querySelector(".b-avatar-preview .avatar-letter").style.width = siz + "px";
  document.querySelector(".b-avatar-preview .avatar-letter").style.fontSize = (siz / 2) + "px";
  } else {
  var link = document.querySelector(".b-avatar-preview img").src;
  var changedLink = link.substring(0, link.length-2);
  document.querySelector(".b-avatar-preview img").src = changedLink + siz;
  }
});

var b_av_radius_output = $('b_av_radius_output')[0];

$(document).on('input', 'input[name="b_av_radius"]', function(e) {
  var rad = e.currentTarget.value;
  b_av_radius_output.innerHTML = rad;
  if (document.querySelector(".b-avatar-preview .avatar-letter") !== null) {
  document.querySelector(".b-avatar-preview .avatar-letter").style.borderRadius = rad + "%";
  } else {
  document.querySelector(".b-avatar-preview img").style.borderRadius = rad + "%";
  }
});


//Accordion for settings page

document.addEventListener("DOMContentLoaded", function(event) { 


    var acc = document.getElementsByClassName("login-accordion");
    var panel = document.getElementsByClassName('login-accordian-panel');
    
    for (var i = 0; i < acc.length; i++) {
        acc[i].onclick = function() {
            var setClasses = !this.classList.contains('current');
            setClass(acc, 'current', 'remove');
            setClass(panel, 'show', 'remove');
    
            if (setClasses) {
                this.classList.toggle("current");
                this.nextElementSibling.classList.toggle("show");
            }
        }
    }
    
    function setClass(els, className, fnName) {
        for (var i = 0; i < els.length; i++) {
            els[i].classList[fnName](className);
        }
    }
});

// Valid for the form id="settings" checkboxes, when the "change" event occurs, the module is sent.

$(document).ready(function(){
    $("#settings").on("change", "input:checkbox", function(){
        $("#settings").submit();
    });
});

// auto submit on change for user theme
if (document.getElementById('userthemeSelection')) {
    document.getElementById('userthemeSelection').onchange = function() {
        document.getElementById('ts').submit();
    }
}

//Live Preview

if (document.getElementById('loginpanel_color')) {
  document.getElementById('loginpanel_color').oninput = function() {
    document.getElementById('preview-form-login').style.backgroundColor = document.getElementById('loginpanel_color').value;
    document.getElementById('preview-form-note').style.backgroundColor = document.getElementById('loginpanel_color').value;
  }

  document.getElementById('loginbackground_color').oninput = function() {
    document.getElementById('preview').style.backgroundColor = document.getElementById('loginbackground_color').value;
  }
  
  document.getElementById('form-login_note').oninput = function() {
    document.getElementById('preview-form-note').innerHTML = document.getElementById('form-login_note').value;
  }

  document.getElementById('login_shadow_color').oninput = function() {
    var slider = document.getElementById("login_shadow").value;
    var color = document.getElementById('login_shadow_color').value;
    document.getElementById('preview-form-login').style.boxShadow = '0px 0px ' + slider + 'px ' + slider * 0.1 + 'px ' + color;
    document.getElementById('preview-form-note').style.boxShadow = '0px 0px ' + slider + 'px ' + slider * 0.1 + 'px ' + color;
  }
  
  document.getElementById('login_border_color').oninput = function() {
    document.getElementById('preview-form-login').style.borderColor = document.getElementById('login_border_color').value;
    document.getElementById('preview-form-note').style.borderColor = document.getElementById('login_border_color').value;
  }

  document.getElementById('login_btn_color').oninput = function() {
    document.getElementById('preview-login-btn').style.backgroundColor = document.getElementById('login_btn_color').value;
  }

  document.getElementById('login_btn_shadow_color').oninput = function() {
    var slider = document.getElementById("login_btn_shadow").value;
    var color = document.getElementById('login_btn_shadow_color').value;
    document.getElementById('preview-login-btn').style.boxShadow = '0px 0px ' + slider + 'px ' + slider * 0.1 + 'px ' + color;
  }

  document.getElementById('login_btn_font_color').oninput = function() {
    document.getElementById('preview-login-btn').style.color = document.getElementById('login_btn_font_color').value;
  }

  document.getElementById('login_btn_shade_color').oninput = function() {
    var color = document.getElementById('login_btn_shade_color').value;
    document.getElementById('preview-login-btn').style.backgroundImage = 'linear-gradient(-180deg, transparent 0%, ' + color + ' 90%';
  }

  document.getElementById('login_btn_shadow').oninput = function() {
    var slider = document.getElementById("login_btn_shadow").value;
    var color = document.getElementById('login_btn_shadow_color').value;
    document.getElementById('preview-login-btn').style.boxShadow = '0px 0px ' + slider + 'px ' + slider * 0.1 + 'px ' + color;
  }

  document.getElementById('login_btn_border').oninput = function() {
    var slider = document.getElementById("login_btn_border").value;
    var color = document.getElementById('login_btn_border_color').value;
    document.getElementById('preview-login-btn').style.border = slider + 'px solid ' + color;
  }

  document.getElementById('login_border').oninput = function() {
    var slider = document.getElementById("login_border").value;
    var color = document.getElementById('login_border_color').value;
    document.getElementById('preview-form-login').style.border = slider + 'px solid ' + color;
    document.getElementById('preview-form-note').style.border = slider + 'px solid ' + color;
  }

  document.getElementById('login_shadow').oninput = function() {
    var slider = document.getElementById("login_shadow").value;
    var color = document.getElementById('login_shadow_color').value;
    document.getElementById('preview-form-login').style.boxShadow = '0px 0px ' + slider + 'px ' + slider * 0.1 + 'px ' + color;
    document.getElementById('preview-form-note').style.boxShadow = '0px 0px ' + slider + 'px ' + slider * 0.1 + 'px ' + color;
  }
  
  document.getElementById('login_btn_width').oninput = function() {
    var slider = document.getElementById("login_btn_width").value;
    document.getElementById('preview-login-btn').style.width = slider + 'px';
  }

  document.getElementById('preview-login-btn').onmouseover = function() {
    document.getElementById('preview-login-btn').style.color = document.getElementById('login_btn_color').value;
    document.getElementById('preview-login-btn').style.backgroundColor = document.getElementById('login_btn_font_color').value;
  }

  document.getElementById('preview-login-btn').onmouseout = function() {
    document.getElementById('preview-login-btn').style.backgroundColor = document.getElementById('login_btn_color').value;
    document.getElementById('preview-login-btn').style.color = document.getElementById('login_btn_font_color').value;
  }

  document.getElementById('form-background_url').oninput = function() {
    var val = document.getElementById("form-background_url").value;
    document.getElementById('preview').style.background = 'url("' + val +'") no-repeat center center';
    document.getElementById('preview').style.backgroundSize = 'cover';
  }
}

function OnColorChanged(selectedColor, inputId) {
              if (inputId == "login_shadow_color") {
                var slider = document.getElementById("login_shadow").value;
                document.getElementById("preview-form-login").style.color = selectedColor;
                document.getElementById("preview-form-note").style.boxShadow = '0px 0px ' + slider + 'px ' + slider * 0.1 + 'px ' + selectedColor;
              }
              if (inputId == "loginbackground_color") {
                var rgbaBox = document.getElementById("preview");
                rgbaBox.style.backgroundColor = selectedColor;
              }
              if (inputId == "loginpanel_color") {
                document.getElementById("preview-form-login").style.backgroundColor = selectedColor;
                document.getElementById("preview-form-note").style.backgroundColor = selectedColor;
              }
              if (inputId == "login_border_color") {
                document.getElementById("preview-form-login").style.borderColor = selectedColor;
                document.getElementById("preview-form-note").style.borderColor = selectedColor;
              }
              if (inputId == "login_btn_color") {
                var rgbaBox = document.getElementById("preview-login-btn");
                rgbaBox.style.backgroundColor = selectedColor;
              }
              if (inputId == "login_btn_shadow_color") {
                var rgbaBox = document.getElementById("preview-login-btn");
                var slider = document.getElementById("login_btn_shadow").value;
                rgbaBox.style.boxShadow = '0px 0px ' + slider + 'px ' + slider * 0.1 + 'px ' + selectedColor;
              }
              if (inputId == "login_btn_font_color") {
                var rgbaBox = document.getElementById("preview-login-btn");
                rgbaBox.style.color = selectedColor;
              }
              if (inputId == "login_btn_shade_color") {
                var rgbaBox = document.getElementById("preview-login-btn");
                rgbaBox.style.backgroundImage = 'linear-gradient(-180deg, transparent 0%, ' + selectedColor + ' 90%';
              }
}