revamped client side scripts so that they are loaded using Require.js instead.
parent
b49c7b8609
commit
038e04dee6
@ -0,0 +1,81 @@
|
|||||||
|
define(function() {
|
||||||
|
var Settings = {};
|
||||||
|
|
||||||
|
Settings.config = {};
|
||||||
|
|
||||||
|
Settings.init = function() {
|
||||||
|
Settings.prepare();
|
||||||
|
};
|
||||||
|
|
||||||
|
Settings.prepare = function() {
|
||||||
|
// Come back in 500ms if the config isn't ready yet
|
||||||
|
if (Settings.config === undefined) {
|
||||||
|
setTimeout(function() {
|
||||||
|
Settings.prepare();
|
||||||
|
}, 500);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Populate the fields on the page from the config
|
||||||
|
var fields = document.querySelectorAll('#content [data-field]'),
|
||||||
|
numFields = fields.length,
|
||||||
|
saveBtn = document.getElementById('save'),
|
||||||
|
x, key, inputType;
|
||||||
|
for (x = 0; x < numFields; x++) {
|
||||||
|
key = fields[x].getAttribute('data-field');
|
||||||
|
inputType = fields[x].getAttribute('type');
|
||||||
|
if (fields[x].nodeName === 'INPUT') {
|
||||||
|
if (Settings.config[key]) {
|
||||||
|
switch (inputType) {
|
||||||
|
case 'text':
|
||||||
|
case 'textarea':
|
||||||
|
case 'number':
|
||||||
|
fields[x].value = Settings.config[key];
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 'checkbox':
|
||||||
|
fields[x].checked = Settings.config[key] === '1' ? true : false;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else if (fields[x].nodeName === 'TEXTAREA') {
|
||||||
|
if (Settings.config[key]) fields[x].value = Settings.config[key];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
saveBtn.addEventListener('click', function(e) {
|
||||||
|
var key, value;
|
||||||
|
e.preventDefault();
|
||||||
|
|
||||||
|
for (x = 0; x < numFields; x++) {
|
||||||
|
key = fields[x].getAttribute('data-field');
|
||||||
|
if (fields[x].nodeName === 'INPUT') {
|
||||||
|
inputType = fields[x].getAttribute('type');
|
||||||
|
switch (inputType) {
|
||||||
|
case 'text':
|
||||||
|
case 'number':
|
||||||
|
value = fields[x].value;
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 'checkbox':
|
||||||
|
value = fields[x].checked ? '1' : '0';
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
} else if (fields[x].nodeName === 'TEXTAREA') {
|
||||||
|
value = fields[x].value;
|
||||||
|
}
|
||||||
|
|
||||||
|
socket.emit('api:config.set', {
|
||||||
|
key: key,
|
||||||
|
value: value
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
Settings.remove = function(key) {
|
||||||
|
socket.emit('api:config.remove', key);
|
||||||
|
};
|
||||||
|
|
||||||
|
return Settings;
|
||||||
|
});
|
@ -1,7 +1,13 @@
|
|||||||
(function() {
|
define(['forum/accountheader'], function(header) {
|
||||||
$(document).ready(function() {
|
var AccountHeader = {};
|
||||||
|
|
||||||
|
AccountHeader.init = function() {
|
||||||
|
header.init();
|
||||||
|
|
||||||
$('.user-favourite-posts .topic-row').on('click', function() {
|
$('.user-favourite-posts .topic-row').on('click', function() {
|
||||||
ajaxify.go($(this).attr('topic-url'));
|
ajaxify.go($(this).attr('topic-url'));
|
||||||
});
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
return AccountHeader;
|
||||||
});
|
});
|
||||||
}());
|
|
@ -1,18 +1,20 @@
|
|||||||
(function() {
|
define(['forum/accountheader'], function(header) {
|
||||||
|
var Followers = {};
|
||||||
|
|
||||||
|
Followers.init = function() {
|
||||||
|
header.init();
|
||||||
|
|
||||||
var yourid = templates.get('yourid'),
|
var yourid = templates.get('yourid'),
|
||||||
theirid = templates.get('theirid'),
|
theirid = templates.get('theirid'),
|
||||||
followersCount = templates.get('followersCount');
|
followersCount = templates.get('followersCount');
|
||||||
|
|
||||||
$(document).ready(function() {
|
|
||||||
|
|
||||||
if (parseInt(followersCount, 10) === 0) {
|
if (parseInt(followersCount, 10) === 0) {
|
||||||
$('#no-followers-notice').removeClass('hide');
|
$('#no-followers-notice').removeClass('hide');
|
||||||
}
|
}
|
||||||
|
|
||||||
app.addCommasToNumbers();
|
app.addCommasToNumbers();
|
||||||
|
};
|
||||||
|
|
||||||
|
return Followers;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
}());
|
|
Loading…
Reference in New Issue