File: D:/HostingSpaces/SBogers10/fietsparkeer.komma-mediadesign.nl/wwwroot/kms/public/js/main.js
/**
* Created with JetBrains PhpStorm.
* User: mike
* Date: 3/28/13
* Time: 6:13 PM
*/
$(document).ready(function()
{
initSortableProductImages();
/*
* Resize body / aside when necessary;
*/
resizeBody();
$(window).resize(resizeBody);
$("#background img").one('load', function() {
$("#background").css({display: 'block' });
/*
* Calculate background size
*/
calculateBackgroundSize();
}).each(function() {
if(this.complete) $(this).load();
});
$(window).resize(calculateBackgroundSize);
/*
* Links have colored animation
*/
$('a','#nav_aside ul').hover(function(){ if( ! $(this).parent().hasClass('active')) $(this).stop().animate({color:'#3c3c3b'},200); },function(){ if( ! $(this).parent().hasClass('active')) $(this).stop().animate({color:'#b2b2b1'},200); })
/*
* Date picker
*/
$( ".datepicker" ).datepicker();
/*
* Reset values forms
*/
var reset = '.reset_value';
$(reset).each(function(){
var label = $(this).attr('data-label');
if($(this).val()!=label)
{
$(this).css({color:'#777777'});
}
});
$(reset).focus(
function(){
var label = $(this).attr('data-label');
$(this).css({color:'#777777'});
if($(this).val()==label)
{
$(this).val('');
}
}
);
$(reset).blur(
function()
{
if($(this).val()=="")
{
$(this).css({color:'#BBBBBB'});
var label = $(this).attr('data-label');
$(this).val(label);
}
}
);
/*
* Rating stars
*/
$('li','.rating_stars').click(function(){
var rating = $(this).index()+1;
$('#rating').val(rating);
updateRating(rating)
});
$('.rating_stars').hover(function(){
$('li','.rating_stars').hover(function(){
var rating = $(this).index()+1;
updateRating(rating)
});
},function(){
var rating = $('#rating').val();
updateRating(rating)
});
function updateRating(rating)
{
for(var i=0;i<5;i++)
{
var star = $('li','.rating_stars').eq(i);
if(i<rating)
{
$(star).addClass('active');
}
else
{
$(star).removeClass('active');
}
}
}
/*
* Btn Hover
*/
$('.btn').hover(function(){
$(this).children('.over').stop().animate({ opacity: 1 },60);
},
function(){
$(this).children('.over').stop().animate({ opacity: 0 },100);
});
/*
* Sortable list
*/
// grab important elements
var sortInput = $('#sort_order');
var list = $('#sortable-list');
// store values
list.children('li').each(function()
{
var li = $(this);
li.data('id',li.attr('title')).attr('title','');
});
// sortable
list.sortable(
{
opacity: 0.7,
update: function()
{
var sortOrder = [];
list.children('li').each(function()
{
sortOrder.push($(this).data('id'));
});
sortOrder.reverse();
sortInput.val(sortOrder.join(','));
}
});
list.disableSelection();
/*
* Select all checkboxes
*/
$('#check_all').click(function(){
var target = $('input[type="checkbox"]','ul');
if($(this).is(':checked'))
{
$(target).prop('checked', true);
}
else
{
$(target).prop('checked', false);
}
});
/*
* Submit form after file upload
*/
$('#upload_file').click(function()
{
document.getElementById('my_file').click();
});
$('body').on("change", "#my_file", function()
{
$('#item_form').submit();
$('#loader').css({ display: 'block' });
});
/*
Alerts
*/
$('.alert').each(function()
{
var h = $(this).height();
$(this).css({ top: (h * -1)+'px', display: 'block' });
$(this).stop().animate({ top: 60 });
});
$('.alert .close').click(function()
{
var h = $(this).parent().height();
$(this).parent().stop().animate({ top: (h * -1)+'px' },200, function(){ $(this).css({ display: 'none' }); });
});
$('.delete_image').click(function(){
var url = $(this).attr('data-url');
var form = $('#item_form');
$(form).append('<input type="hidden" name="delete_image_url" value="' + url + '"/>');
$(form).submit();
});
$('.delete_video').click(function(){
var url = $(this).attr('data-url');
var form = $('#item_form');
$(form).append('<input type="hidden" name="delete_image_url" value="' + url + '"/>');
$(form).submit();
});
initProductThumbs();
});
/*
* Resize full screen background image
*/
function calculateBackgroundSize()
{
// variables
var image = $('img','#background');
var iw = $(image).width();
var ih = $(image).height();
var iRatio = iw/ih;
var ww = $(window).width();
var wh = $(window).height();
var wRatio = ww/wh;
var ml, mt;
// If image is wider than window
if(iRatio > wRatio)
{
var newImageW = wh * iRatio;
ml = newImageW / -2;
mt = wh / -2;
$(image).css({ width: newImageW+'px', height: wh+'px', marginTop: mt+'px', marginLeft: ml+'px' });
}
else
{
var newImageH = ww / iRatio;
ml = ww / -2;
mt = newImageH / -2;
$(image).css({ width: ww+'px', height: newImageH+'px', marginTop: mt+'px', marginLeft: ml+'px' });
}
}
/*
* Resize body / aside when necessary;
*/
function resizeBody()
{
var body = 'body';
var aside = '#nav_aside';
var wh = $(window).height();
var bh = $(body).height();
var hh = $('#header').height();
var wrh = $('#wrapper').height();
var fh = $('#footer').height();
var checkSize = hh + fh + wrh + parseInt($('#wrapper').css('marginTop')) + parseInt($('#wrapper').css('marginBottom'));
if(checkSize < wh)
{
//console.log(wrh + ' ' + wh);
$(body).height(wh);
bh = wh;
}
$(aside).height(bh - hh - fh);
}
var activeKey = 0;
function initProductThumbs()
{
$('.item_images').children('li').click(function()
{
var newKey = $(this).index();
$('.isThumb').removeClass('isThumb');
$(this).addClass('isThumb');
activeKey = newKey;
$('#thumbkey').attr('value',activeKey);
});
}
function initSortableProductImages()
{
$('body').append('<div id="js_load"></div>');
/* grab important elements */
var sortInput = $('#sort_order');
var thumbKey = $('#thumbkey').val();
var sessionName = $('#session_name').val();
var list = $('#sortable_images');
/* worker function */
var fnSubmit = function() {
var sortOrder = [];
list.children('li').each(function(){
sortOrder.push($(this).attr('data-order'));
});
//sortOrder.reverse();
sortInput.val(sortOrder.join(','));
// Update order in session
$('#js_load').load('/kms/app/controllers/js_update_images_order.php?action=update-order&order='+sortInput.val()+'&sessionName='+sessionName+'&thumbKey='+thumbKey,function()
{
window.location.reload();
});
};
/* store values */
list.children('li').each(function() {
var li = $(this);
li.data('id',li.attr('title')).attr('title','');
});
/* sortable */
list.sortable({
helper : 'clone',
opacity: 0.7,
update: function() {
fnSubmit();
}
});
list.disableSelection();
}