Gazelle/static/functions/cssgallery.js

55 lines
2.2 KiB
JavaScript
Raw Normal View History

2013-04-18 08:00:54 +00:00
(function($) {
2013-06-06 08:01:03 +00:00
2013-04-18 08:00:54 +00:00
$(document).ready(function () {
// If the custom stylesheet field is empty, select the current style from the previews
2013-04-26 08:00:25 +00:00
if(!$('input#styleurl').val()){
var radiobutton = $('input[name="stylesheet_gallery"][value="'+$('select#stylesheet').val()+'"]');
radiobutton.click();
$('.preview_wrapper').removeClass('selected');
radiobutton.parent().parent().addClass('selected');
2013-04-18 08:00:54 +00:00
}
2013-04-26 08:00:25 +00:00
// If an overlay is clicked, select the right item in the dropdown and clear the custom css field
$('div.preview_image').click(function() {
$('.preview_wrapper').removeClass('selected');
var parent = $(this).parent();
parent.addClass('selected');
var radiobutton = parent.find('input');
2013-04-18 08:00:54 +00:00
radiobutton.prop('checked', true);
$('select#stylesheet').val(radiobutton.attr('value'));
$('input#styleurl').val('');
})
// If the input is clicked, redirect it to the overlay click event
$('input[name="stylesheet_gallery"]').change(function() {
2013-04-26 08:00:25 +00:00
$(this).parent().parent().find('div.preview_image').click();
2013-04-18 08:00:54 +00:00
})
// If the dropdown is changed, select the appropriate item in gallery, clear the custom CSS field
$('select#stylesheet').change(function() {
2013-04-26 08:00:25 +00:00
var radiobutton = $('input[name="stylesheet_gallery"][value="'+$(this).val()+'"]');
radiobutton.prop('checked', true);
$('.preview_wrapper').removeClass('selected');
radiobutton.parent().parent().addClass('selected');
2013-04-18 08:00:54 +00:00
$('input#styleurl').val('');
})
// If the custom CSS field is changed, clear radio buttons
$('input#styleurl').keydown(function() {
$('input[name="stylesheet_gallery"]').each(function() {
$(this).prop('checked', false);
})
2013-04-26 08:00:25 +00:00
$('.preview_wrapper').removeClass('selected');
2013-04-18 08:00:54 +00:00
})
// If the input is empty, select appropriate gallery item again by the dropdown
$('input#styleurl').keyup(function() {
if (!$(this).val()){
$('select#stylesheet').change();
}
})
// Allow the CSS gallery to be expanded/contracted
$('#toggle_css_gallery').click(function (e) {
e.preventDefault();
$('#css_gallery').slideToggle(function () {
$('#toggle_css_gallery').text($(this).is(':visible') ? 'Hide gallery' : 'Show gallery');
});
});
});
})(jQuery);