Merge pull request #294 from towards-a-new-leftypol/style_select2
Style select (second attempt)
This commit is contained in:
commit
dc81de9d5c
|
@ -15,70 +15,41 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
$(document).ready(function() {
|
$(document).ready(function() {
|
||||||
var stylesDiv = $('div.styles');
|
var stylesDiv = $('div.styles');
|
||||||
var pages = $('div.pages');
|
var pages = $('div.pages');
|
||||||
var stylesSelect = $('<select></select>').css({float:"none"});
|
var stylesSelect = $('<select></select>').css({float:"none"});
|
||||||
var options = [];
|
var options = [];
|
||||||
|
|
||||||
var i = 1;
|
var i = 1;
|
||||||
stylesDiv.children().each(function() {
|
stylesDiv.children().each(function() {
|
||||||
var name = this.innerHTML.replace(/(^\[|\]$)/g, '');
|
var name = this.innerHTML.replace(/(^\[|\]$)/g, '');
|
||||||
var opt = $('<option></option>')
|
var opt = $('<option></option>')
|
||||||
.html(name)
|
.html(name)
|
||||||
.val(i);
|
.val(i);
|
||||||
if ($(this).hasClass('selected'))
|
if ($(this).hasClass('selected'))
|
||||||
opt.attr('selected', true);
|
opt.attr('selected', true);
|
||||||
options.push ([name.toUpperCase (), opt]);
|
options.push ([name.toUpperCase (), opt]);
|
||||||
$(this).attr('id', 'style-select-' + i);
|
$(this).attr('id', 'style-select-' + i);
|
||||||
i++;
|
i++;
|
||||||
});
|
});
|
||||||
|
|
||||||
options.sort ((a, b) => {
|
options.sort ((a, b) => {
|
||||||
const keya = a [0];
|
const keya = a [0];
|
||||||
const keyb = b [0];
|
const keyb = b [0];
|
||||||
if (keya < keyb) { return -1; }
|
if (keya < keyb) { return -1; }
|
||||||
if (keya > keyb) { return 1; }
|
if (keya > keyb) { return 1; }
|
||||||
return 0;
|
return 0;
|
||||||
}).forEach (([key, opt]) => {
|
}).forEach (([key, opt]) => {
|
||||||
stylesSelect.append(opt);
|
stylesSelect.append(opt);
|
||||||
});
|
});
|
||||||
|
|
||||||
stylesSelect.change(function() {
|
stylesSelect.change(function() {
|
||||||
$('#style-select-' + $(this).val()).click();
|
$('#style-select-' + $(this).val()).click();
|
||||||
});
|
});
|
||||||
|
|
||||||
stylesDiv.hide()
|
stylesDiv.hide()
|
||||||
pages.after(
|
pages.after(
|
||||||
$('<div id="style-select"></div>')
|
$('<div id="style-select"></div>')
|
||||||
.append(_('Select theme: '), stylesSelect)
|
.append(_('Select theme: '), stylesSelect)
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
stylesDiv = $('div.styles');
|
|
||||||
var pages = $('div.pages');
|
|
||||||
var stylesSelect = $('<select></select>');
|
|
||||||
|
|
||||||
var i = 1;
|
|
||||||
stylesDiv.children().each(function() {
|
|
||||||
var opt = $('<option></option>')
|
|
||||||
.html(this.innerHTML.replace(/(^\[|\]$)/g, ''))
|
|
||||||
.val(i);
|
|
||||||
if ($(this).hasClass('selected'))
|
|
||||||
opt.attr('selected', true);
|
|
||||||
stylesSelect.append(opt);
|
|
||||||
$(this).attr('id', 'style-select-' + i);
|
|
||||||
i++;
|
|
||||||
});
|
|
||||||
|
|
||||||
stylesSelect.change(function() {
|
|
||||||
$('#style-select-' + $(this).val()).click();
|
|
||||||
});
|
|
||||||
|
|
||||||
stylesDiv.hide()
|
|
||||||
pages.after(
|
|
||||||
$('<div id="style-select"></div>')
|
|
||||||
/*.text(_('Style: '))*/
|
|
||||||
.append(stylesSelect)
|
|
||||||
);
|
|
||||||
});
|
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue