function get_local_path(url) { var a = document.createElement('a'); a.href = url; var queryremoved=a.protocol+'//'+a.hostname+a.pathname; var local=queryremoved.replace(base_url,''); return local; } function get_url_path(url) { var a = document.createElement('a'); a.href = url; return a.pathname; } var menu = "menu_content"; function TastoDestro(e) { NascondiMenu(); if (menu != "") { var left = e.pageX || (e.clientX + document.body.scrollLeft); var top = e.pageY || (e.clientY + document.body.scrollTop); document.getElementById(menu).style.display = ""; if (left + document.getElementById(menu).offsetWidth <= document.body.offsetWidth) document.getElementById(menu).style.left = left + "px"; else document.getElementById(menu).style.left = (left - document.getElementById(menu).offsetWidth + 5) + "px"; if(top + document.getElementById(menu).offsetHeight <= document.body.offsetHeight || (top - document.getElementById(menu).offsetHeight + 5) <= 0) document.getElementById(menu).style.top = top + "px"; else document.getElementById(menu).style.top = (top - document.getElementById(menu).offsetHeight + 5) + "px"; } return false; } function NascondiMenu() { document.getElementById("menu_topmenu").style.display = 'None'; document.getElementById("menu_submenu").style.display = 'None'; document.getElementById("menu_content").style.display = 'None'; document.getElementById("menu_dock").style.display = 'None'; document.getElementById("menu_footer").style.display = 'None'; document.getElementById("menu_catalog").style.display = 'None'; } function Menu_Topmenu(e) { return true; } window.di4b = {}; /** * Load script for management of dialog */ /** * Script for management of dialog */ di4b.modal_message = (function () { var modal_id = 1; var modal_instance = false; var default_opts = { backdrop: true, header: true, footer: true, height: '', top: '', width: '', percentagewidth: '', transparent: false, loader: false, style: '' }; function apply_options(modal, opts, title, message) { var modal_width=0; if (opts['footer'] === false) { modal.find('.modal-footer').hide(); } else { modal.find('.modal-footer').show(); } if (opts['header'] === false) { modal.find('.modal-header').hide(); } else { modal.find('.modal-header').show(); } if (opts['transparent'] === true) { modal.addClass('transparent'); } else { modal.removeClass('transparent'); } if (opts['nopadding'] === true) { modal.addClass('nopadding'); } else { modal.removeClass('nopadding'); } if (opts['loader'] === true) { modal.addClass('loader'); } else { modal.removeClass('loader'); } if (opts['width']) { modal.css('width', opts['width'] + 'px'); modal_width=opts['width']; } if (opts['percentagewidth']) { var ratio=opts['percentagewidth']/100; modal_width=Math.round($(document).width()*ratio); modal.width(modal_width); } if(modal.attr('data-style')!==undefined) { modal.removeClass(modal.attr('data-style')); modal.removeAttr('data-style'); } if (opts['style']) { modal.addClass(opts['style']); modal.attr("data-style",opts['style']); } modal.height(opts['height']); modal.find('h3').html(title); modal.find('.modal-body').html(message); if(modal_width==0) modal_width=modal.outerWidth(); setTimeout(function() { var top_val; var oldscroll=$(document).scrollTop(); if(modal.height()<$(window).height()) { top_val=$(document).scrollTop()+Math.round( ($(window).height()/2) - modal.height()/2); } else top_val=$(document).scrollTop()+50; var left_val=Math.round( ($(document).width()/2) - modal_width/2); var pos={left: left_val, top: top_val}; modal.offset(pos); setTimeout(function() { $(document).scrollTop(oldscroll); },500); },250); //if(modal.height()<$(window).height()) // $("html").css("overflow","hidden"); } function change(modal, data, width) { modal.removeClass('loader'); modal.find('.modal-body').html(data); if (width) { modal.css('width', width + 'px'); modal.css('margin-left', '-' + (width / 2) + 'px'); } } function setLoader(modal) { modal.addClass('loader'); modal.find('.modal-body').html(''); } function hide(modal, at_end) { if (at_end) { modal.bind('hidden', function () { at_end(); modal.unbind('hidden'); }); } modal.modal('hide'); // if(modal.height()<$(window).height()) // $("html").css("overflow","visible"); } return { 'create': function (title, message, options) { var opts = $.extend({}, default_opts, options); modal_opts = {}; modal_opts['backdrop'] = opts['backdrop']; var modal = $('#modal-message').clone().appendTo(document).modal(modal_opts); modal.find('.close-action').click(function(e) { e.preventDefault(); modal.modal('hide'); }); modal.attr('id', 'modal-message-' + modal_id); modal_id++; apply_options(modal, opts, title, message); return modal; }, /** * Use as a singleton * Just one istance per app **/ 'show': function (title, message, options) { var opts = $.extend({}, default_opts, options); if (!modal_instance) { modal_instance = di4b.modal_message.create(title, message, opts); } apply_options(modal_instance, opts, title, message); modal_instance.modal('show'); }, 'change': function (data, width) { if (modal_instance) { change(modal_instance, data, width); } }, 'setloader': function () { if (modal_instance) { setLoader(modal_instance); } }, 'hide': function (at_end) { if (!modal_instance) { return false; } hide(modal_instance, at_end); return true; }, 'getObject': function () { return modal_instance; } }; }()); /** * Script for management for menus */ di4b.menu = (function () { function resize_items(menu_id) { var width_container = $('#'+menu_id+' .items').width(); var num_items = $('#'+menu_id+' .items').children().length; var width_items = 0; var item_right_margin = 0; $('#'+menu_id+' .items .link').each(function () { width_items += $(this).width(); }); item_right_margin = (width_container - width_items)/(num_items - 1); // Go to integer, because with decimal you can't be shure item_right_margin_int = Math.floor(item_right_margin); var delta = Math.floor((item_right_margin - item_right_margin_int) * (num_items - 1)); var unit = Math.ceil(delta / (num_items - 1)); $('#'+menu_id+' .items .link').not('.last').each( function () { var inc = item_right_margin_int; if (delta > unit) { delta -= unit; inc += unit; } $(this).css('margin-right', inc + 'px'); }); } function init() { // Precarico il font prima di fare il resize; questo dovrebbe evitare // il calcolo della dimensione con il font di base, e poi // una volta caricato il font il menù va a capo var images = []; var exts = ['ttf', 'woff', 'eot', 'svg']; for (ext in exts) { var image = new Image; image.src = base_url + 'css/fonts/carme-regular-webfont.' + exts[ext]; image.onerror = function() { resize_items(); }; images.push(image); } } return { 'init': init, 'resize_items': resize_items }; }()); di4b.admin_menu = (function () { var max_items; var current=false; function add(menu_id) { if (max_items == false || ($('#'+menu_id+' .items .link').length - 1) < max_items) { $('.menu-item-model').clone().removeClass('menu-item-model').insertBefore($('#'+menu_id+' .items #comandi')); $(".comandi .submenu").last().find('.comandi img').removeClass('remove_disabled').addClass('remove'); $(".comandi .submenu").last().closest(".link").removeClass("hidden"); $(".comandi .submenu").last().closest('.link').find('.idField').attr('value',''); initialize_popover($(".comandi .submenu").last(),menu_id); di4b.menu.resize_items(menu_id); } else { di4b.modal_message.show('Modifica menu impossibile', 'Impossibile aggiungere una voce menu; raggiunto il massimo numero di voci!'); } } function save(menu_id) { $('#'+menu_id).closest('form').submit(); } function remove(obj,menu_id) { if($(".link .comandi").length<3 && menu_id=='topmenu') { di4b.modal_message.show('Modifica menu impossibile', 'Impossibile rimuovere il menu: il menu principale deve sempre avere almeno un elemento!'); } else { $(obj).closest('.link').remove(); di4b.menu.resize_items(menu_id); } } function initialize_popover(obj,menu_id) { var menu_counter=$("#"+menu_id+" .link").length; $(obj).closest(".link").attr("rel","menu"+menu_counter); $(".comandi .submenu").each(function() { $(this).popover("hide"); }); current=false; $(obj).popover({ html: true, placement:'below', trigger:'manual' }).click(function(e) { if(current==false) { $(this).attr("popover-active","yes"); $(this).popover('show'); current=$(this); } else { $(".comandi .submenu").each(function() { $(this).attr("popover-active","no"); $(this).popover("hide"); }); if($(this).get(0)!=current.get(0)) { $(this).attr("popover-active","yes"); $(this).popover('show'); current=$(this); } else current=false; } }); } function init(menu_id) { if ($('.menu-item-model').length == 0) return; if ($('#'+menu_id+' input[name=max_items]').length > 0) { max_items = $('#'+menu_id+' input[name=max_items]').val(); } $('#'+menu_id).on('click', '.intopmenu_add', function() { add(menu_id); }); $('#'+menu_id).on('click', '.intopmenu_confirm', function() { save(menu_id); }); $('#'+menu_id).on('click', '.remove', function () { remove(this,menu_id); }); $('#'+menu_id).on('click', '.remove_disabled', function () { di4b.modal_message.show('Eliminazione del menù vietata', 'Non è possibile eliminare menu che hanno dei sottomenu: cancella prima i sottomenu'); }); if ($.fn.sortable) { $('#'+menu_id+' .items').sortable({ 'items': '.link:not(.last)', 'handle': '.drag' }); } initialize_popover("#"+menu_id+" .comandi .submenu",menu_id); } return { 'init': init }; }()); di4b.admin_mosaic = (function () { function init() { if ($('#form_homepage').length == 0) return; $('#form_homepage').on('change', '.mod_img', function () { var image = $(this).closest('.images'); var image_val = $(this).val(); image.css('background-image', 'url(' + image_val + ')'); }); } return { 'init': init }; }()); di4b.admin_gallery = (function () { var max_height = 0; function calculate_max_height() { // Set same max height to all elements $('.media-grid.gallery .item').each(function() { var height = $(this).height(); if (height > max_height) { max_height = height; } }); } function apply_max_height() { // Apply max height (if > 0) if (max_height > 0) { $('.media-grid.gallery .item').each(function() { $(this).height(max_height); }); } } function dragndrop() { // Attach sortable widget if ($.fn.sortable) { var css_class = $('.media-grid.gallery .items .item').not('.add').attr('class'); $('.media-grid.gallery').sortable({ 'items': '.item', 'handle': '.drag', 'tolerance': 'intersect', 'placeholder': css_class + ' placeholder', 'cancel': '.add', 'change': function (e, ui) { $(ui.placeholder).height(max_height); }, 'start': function (e, ui) { $(ui.placeholder).height(max_height); } }); } } function init() { if ($('.media-grid.gallery').length == 0) return; // For the catalog with dinamic new elements $('#formSalva').on('click', '.media-grid.gallery div.item.add', function (e) { e.preventDefault(); var item = $('#item-edit-template').find('.item').clone(); $('.media-grid.gallery .items .add').after(item); item.find('.filechoose').click(); calculate_max_height(); apply_max_height(); }); $('#formSalva').on('click', '.media-grid.gallery div.item .delete', function (e) { e.preventDefault(); $(this).closest('.item').remove(); calculate_max_height(); apply_max_height(); }); calculate_max_height(); apply_max_height(); dragndrop(); } return { 'init': init, 'resize_items': function() { calculate_max_height(); apply_max_height(); }, 'bind_dragndrop': dragndrop }; }()); /* load admin catalog component */ di4b.admin_catalog = (function () { var modal_detail; function truncate_text(str,maxl) { if(str.length>maxl) { str=str.substring(0,maxl)+"..."; } return str; } function dragndrop() { // Attach sortable widget if ($.fn.sortable) { $('#formSalva .media-grid').sortable({ 'handle': '.drag', 'items': '.item' }); } } function add_product() { var size = $('#formSalva .media-grid').attr('data-length'); var product_item = $('#item-catalog-product-template').html(); product_item = product_item.replace(/%%index%%/g, ++size); $('#formSalva .media-grid').attr('data-length', size); $('#formSalva .media-grid .add_product').after(product_item); // Se clicco su annulla dopo la creazione voglio levare l'elemento // $('#formSalva .media-grid').one('void', function() { // $('#formSalva .media-grid .item').first().remove(); // }); // $('#formSalva .media-grid').one('updated', function() { // $('#formSalva .media-grid').off('void'); // }); // edit_form($('#formSalva .media-grid .item').first()); } function get_form_values(product, modal_detail) { var main_index = product.data('index'); // copy the element vals modal_detail.find("[name]").each(function(index,el) { var correspondent_selector_in_page='input[name="page_prods[' + main_index + ']['+$(el).attr('name')+']"]'; var value=product.find(correspondent_selector_in_page).val(); $(el).val(value); }); // video has to be dealt separately if($('input[name="page_prods[' + main_index + '][video]"]')!="") modal_detail.find("param").val('file='+base_url+$('input[name="page_prods[' + main_index + '][video]"]').val().replace(base_url,'')+'&screencolor=B21618'); // And set the preview image modal_detail.find('.immaginepagina .preview img').attr('src', modal_detail.find('input[name="image"]').val()); } function apply_form_values(product, modal_detail) { var main_index = product.data('index'); // copy the element vals modal_detail.find("[name]").each(function(index,el) { var correspondent_selector_in_page='[name="page_prods[' + main_index + ']['+$(el).attr('name')+']"]'; product.find(correspondent_selector_in_page).val($(el).val()); }); // copy tinymce value var tinymce_id = modal_detail.find('textarea[name="description"]').attr('id'); product.find('input[name="page_prods[' + main_index + '][description]"]').val(tinyMCE.get(tinymce_id).getContent()); // And then the visible ones product.find('div.name').html(truncate_text("cod. "+product.find('input[name="page_prods[' + main_index + '][name]"]').val(),20)); //product.find('div.ecname').html(product.find('input[name="page_prods[' + main_index + '][name]"]').val()); product.find('div.description').html(truncate_text(product.find('input[name="page_prods[' + main_index + '][introduction]"]').val(),25)); product.find('div.preview img').attr('src', product.find('input[name="page_prods[' + main_index + '][image]"]').val()); tinyMCE.get(tinymce_id).destroy(); } function edit_form(product) { var html_dialog = $('#item-catalog-product-form-template').html(); modal_detail=di4b.modal_message.create('Modifica prodotto', html_dialog, { width: '640', footer: false, header: false, style: 'catalog' }); get_form_values(product, modal_detail); modal_detail.find('.save').on('click', function (e) { e.preventDefault(); apply_form_values(product, modal_detail); modal_detail.modal('hide'); $('#formSalva .media-grid').trigger('updated'); }); modal_detail.find('.void').on('click', function (e) { e.preventDefault(); modal_detail.modal('hide'); $('#formSalva .media-grid').trigger('void'); }); modal_detail.find('.delete').on('click', function (e) { e.preventDefault(); modal_detail.modal('hide'); product.remove(); }); modal_detail.find('textarea.description').addClass('editor_product'); modal_detail.find('textarea.description').attr('id', 'editor-product-' + Math.round(Math.random() * 25000)); modal_detail.modal('show'); modal_detail.on('shown', function () { tinyMCE.settings = {}; tinyMCE.execCommand('mceAddControl', false, modal_detail.find('textarea.description').attr('id')); }); } function init() { if ($('#formSalva .media-grid').length == 0) return; $('#formSalva .media-grid').on('click', '.edit', function (e) { e.preventDefault(); edit_form($(this).closest('.item')); }); $('#formSalva .media-grid').on('click', '.delete', function (e) { e.preventDefault(); $(this).closest('.item').remove(); }); $('#formSalva').on('click', '.add_product', function (e) { e.preventDefault(); add_product(); }); $('#formSalvaContenutoAjax').on('image_changed', '.immaginepagina .mod_img', function (e) { e.preventDefault(); $(this).closest('.immaginepagina').find('.preview img').attr('src', $(this).val()); }); // Prima di inviare i dati salva la posizione degli elementi $('#formSalva').on('submit', function (e) { $('.page_order').each(function (i) { $(this).val(i); }); }); dragndrop(); } return { 'init': init, 'bind_dragndrop': dragndrop }; }()); di4b.admin_containeralbum = (function () { var max_height = 0; var active_album = false; function calculate_max_height() { // Set same max height to all elements $('.containeralbum .item').each(function() { var height = $(this).height(); if (height > max_height) { max_height = height; } }); } function apply_max_height() { // Apply max height (if > 0) if (max_height > 0) { $('.containeralbum .item').each(function() { $(this).height(max_height); }); } } function dragndrop() { // Attach sortable widget if ($.fn.sortable) { var css_class = $('.containeralbum .items .item').not('.add').attr('class'); $('.containeralbum .items').sortable({ 'items': '.item', 'handle': '.drag', 'tolerance': 'intersect', 'placeholder': css_class + ' placeholder', 'cancel': '.add', 'change': function (e, ui) { $(ui.placeholder).height(max_height); }, 'start': function (e, ui) { $(ui.placeholder).height(max_height); } }); } } function init() { if ($('#formSalva .containeralbum').length == 0) return; // For the catalog with dinamic new elements $('#formSalva').on('click', '.containeralbum .items .item.add', function (e) { e.preventDefault(); var item = $('#item-containeralbum').find('.item').clone(); $('.containeralbum .items .item.add').after(item); item.find('a.edit').trigger('click'); calculate_max_height(); apply_max_height(); }); $('#formSalva').on('click', '.containeralbum .items .item .edit', function (e) { e.preventDefault(); var this_album = $(this).closest('.item'); $.get($(this).attr('href'), { 'typology': 'album', 'style': $('#stile').val(), 'is_popup': 1 }, function (data) { di4b.modal_message.show('Modifica Album', data, {fullwidth: true, footer: false, header: false, style: 'album'}); di4b.modal_message.getObject().on('shown', function () { active_album = this_album; di4b.admin_album.init(); di4b.admin.tinymce.init(); }); }); }); $('#formSalva').on('click', '.containeralbum .items .item .delete', function (e) { e.preventDefault(); $(this).closest('.item').remove(); calculate_max_height(); apply_max_height(); }); if ($('.containeralbum .items').length == 0) return; dragndrop(); calculate_max_height(); apply_max_height(); } return { 'init': init, 'resize_items': function() { calculate_max_height(); apply_max_height(); }, 'bind_dragndrop': dragndrop, 'getActiveAlbum': function () { return active_album; }, 'resetActiveAlbum': function () { active_album = false; } }; }()); di4b.admin_album = (function () { var max_height = []; var num = 0; var image_active = false; var modal_detail = false; function calculate_max_height() { // Set same max height to all elements $('.albums .media-grid').each(function(mediagrid_index) { if (!max_height[mediagrid_index]) { max_height[mediagrid_index] = 0; } $(this).find('.item').each(function() { var height = $(this).height(); if (height > max_height[mediagrid_index]) { max_height[mediagrid_index] = height; } }); }); } function apply_max_height() { $('.albums .media-grid').each(function(mediagrid_index) { $(this).find('.item').each(function() { if (max_height[mediagrid_index] > 0) { $(this).height(max_height[mediagrid_index]); } }); }); } function dragndrop() { // Attach sortable widget if ($.fn.sortable) { var css_class = $('.album .items .item').not('.add_img').attr('class'); $('.album .items').sortable({ 'items': '.item:not(.add)', 'handle': '.drag', 'tolerance': 'intersect', 'placeholder': css_class + ' placeholder', 'change': function (e, ui) { $(ui.placeholder).height(max_height); }, 'start': function (e, ui) { $(ui.placeholder).height(max_height); } }); } } function add_album () { function replace_iii_from_names(item, num) { item.find("input,textarea").each(function() { if ($(this).attr('name')) { var name = $(this).attr('name').replace('iii', num); $(this).attr('name', name); } }); } var item = $('#item-album-edit-template').find('.item').clone() .attr('id', 'album-' + num).data('id', num); $('.media-grid.album .items .add_alb').after(item); item = $('#item-album-form-template').find('> .album').clone().addClass('visible') .attr('id', 'album-form-' + num).attr('data-id', num); replace_iii_from_names(item, num); $('.albums').find('.visible').removeClass('visible'); $('.albums').append(item); if ($('.albumslist').length) { item = $('#item-album-form-name-template').find('> div').clone(); item.attr('data-id', num); replace_iii_from_names(item, num); $('.albumslist .list').append(item); } num++; } /** * Put the form in the "album mode": disable the page commands and hide * others album's commands. */ function edit_album(list_item) { var index = list_item.data('id'); di4b.admin.disable_page_form(); $(list_item).closest('.albumslist').find('.name button, .add_album').addClass('hidden'); $(list_item).closest('.name').addClass('active'); $('.albums > .album').hide(); $('#album-form-' + index).show(); } /** * Hide all albums and go in "page mode". It's the opposite of edit_album. */ function done_edit_album() { di4b.admin.enable_page_form(); $('.albumslist .name button, .albumslist .add_album').removeClass('hidden'); $('.albumslist .name.active').removeClass('active'); $('.albums > .album').hide(); } function init() { if ($.fn.sortable) { $('.albumslist .list').sortable({ update: function(event, ui) { $('.albumslist .list .name').each(function (i) { var id = $(this).data('id'); $('input[name="page_Album[' + id + '][Ordine]"]').val(i); }); }, handle: '.drag' }); } num = $('.albums > .album').length; // For album with dinamic new elements $(document).off('click', '.media-grid.album div.item.add_alb, #formSalva .add_album'); $(document).on('click', '.media-grid.album div.item.add_alb, #formSalva .add_album', function (e) { e.preventDefault(); add_album(); if ($('.albumslist').length) { $('.albums > .album').hide(); edit_album($('.albumslist .list .name[data-id=' + (num - 1) +']')); } }); $(document).off('click', '.media-grid.album div.item .delete_alb'); $(document).on('click', '.media-grid.album div.item .delete_alb', function (e) { e.preventDefault(); var item = $(this).closest('.item'); var id = item.data('id'); item.remove(); $('#album-form-' + id).remove(); }); $(document).off('click', '.media-grid.album div.item .modify_alb'); $(document).on('click', '.media-grid.album div.item .modify_alb', function (e) { e.preventDefault(); var id = $(e.target).closest('.item').data('id'); $('.albums').find('.visible').removeClass('visible'); $('#album-form-' + id).addClass('visible'); }); $(document).off('click', '.media-grid.album div.item.add_img .btn,.media-grid.album div.item.add_img'); $(document).on('click', '.media-grid.album div.item.add_img .btn,.media-grid.album div.item.add_img', function (e) { e.preventDefault(); $target = $(e.target); var item = $('#item-album-edit-image-template').find('.item').clone() .removeAttr('id'); var id = $target.closest('.album-form').data('id'); item.find("input,textarea").each(function() { var name = $(this).attr('name').replace('iii', id); $(this).attr('name', name); }); var preview_width = $target.closest('.media-grid.album').find('input[type=hidden].width').val(); var preview_height = $target.closest('.media-grid.album').find('input[type=hidden].height').val(); item.find('.preview img').attr({ 'data-width': preview_width, 'data-height': preview_height, 'width': preview_width, 'height': preview_height }); $target.closest('.items').find('.add_img').after(item); calculate_max_height(); apply_max_height(); item.find('.filechoose').click(); }); $(document).off('click', '.media-grid.album div.item a.edit'); $(document).on('click', '.media-grid.album div.item a.edit', function (e) { e.preventDefault(); if (modal_detail !== false) return; image_active = $(e.target).closest('.item'); var html_dialog = $('#item-album-image-detail-template').find('.dialog').html(); modal_detail = di4b.modal_message.create('Modifica foto', html_dialog, { header: false, footer: false, style: 'album_image' }); modal_detail.find('.title').val(image_active.find('.title').val()); modal_detail.find('.description').val(image_active.find('.description').val()); modal_detail.find('.image').val(image_active.find('.image').val()); modal_detail.find('.preview img').attr('src', image_active.find('.preview img').attr('src')); modal_detail.modal('show'); modal_detail.on('click', '.modal .save', function (e) { e.preventDefault(); image_active.find('.title').val(modal_detail.find('.title').val()); image_active.find('.description').val(modal_detail.find('.description').val()); image_active.find('.image').val(modal_detail.find('.image').val()); modal_detail.modal('hide'); }); modal_detail.on('click', '.modal .annulla', function (e) { e.preventDefault(); modal_detail.modal('hide'); }); modal_detail.on('click', '.modal .elimina', function (e) { e.preventDefault(); modal_detail.modal('hide'); }); modal_detail.on('hidden', function (e) { e.preventDefault(); modal_detail.remove(); modal_detail = false; }); }); $(document).off('change', '.media-grid.album div.item'); $(document).on('change', '.media-grid.album div.item', function (e) { e.preventDefault(); var $this = $(this); // Devo aspettare la fine dell'animazione! setTimeout(function() { if ($('input.stile').val() != 'timeline' && $('input.stile').val() != 'books' && $('input.stile').val() != 'landscapes') { $this.find('.edit').click(); } }, 500); }); $(document).off('click', '.media-grid.album div.item .delete'); $(document).on('click', '.media-grid.album div.item .delete', function (e) { e.preventDefault(); $(this).closest('.item').remove(); }); $(document).off('click', '#formSalva .remove_album'); $(document).on('click', '#formSalva .remove_album', function (e) { e.preventDefault(); $(e.target).closest('.album-form').remove(); }); $(document).off('click', '#FormSalva .saveForm.album button.save'); $(document).on('click', '#FormSalva .saveForm.album button.save', function (e) { e.preventDefault(); var form = $(e.target).closest('.saveForm.album'); var data = $('.saveForm.album').serialize(); data += '&bott_salva=save'; alert(data); $.ajax({ 'url': $('.saveForm.album').find('.url').val(), 'type': 'POST', 'data': data, 'dataType': 'json', 'complete': function (response, textStatus) { if (textStatus !== 'success') { alert("Errore: " + textStatus); } else { var active_album = di4b.admin_containeralbum.getActiveAlbum(); active_album.find('.preview img').attr('src', form.find('.immaginepagina img').attr('src')); if (form.find('textarea').length > 0) { active_album.find('.description').html(form.find('textarea').val().replace("\n", '')); } var response_json = JSON.parse(response.responseText); active_album.find('input.album_id').val(response_json['page_id']); active_album.find('.edit').attr('href', response_json['url']); di4b.admin_containeralbum.resetActiveAlbum(); di4b.modal_message.hide(); } } }); }); $(document).off('click', '#formSalvaContenuto.album a.delete_album'); $(document).on('click', '#formSalvaContenuto.album a.delete_album', function (e) { e.preventDefault(); di4b.modal_message.hide(); di4b.admin_containeralbum.getActiveAlbum().remove(); di4b.admin_containeralbum.resetActiveAlbum(); }); $(document).off('click', '#formSalvaContenuto.album button.annulla'); $(document).on('click', '#formSalvaContenuto.album button.annulla', function (e) { e.preventDefault(); di4b.modal_message.hide(); }); // The landscape mode has some custom js if ($('.albumslist').length) { // Hide all the albums onload! $('.albums > .album').hide(); // Show album on click on the album name $(document).off('click', '.albumslist .list .name .edit'); $(document).on('click', '.albumslist .list .name .edit', function (e) { e.preventDefault(); edit_album($(e.target).closest('.name')); }); // Remove album on click on delete button $(document).off('click', '.albums .album .delete'); $(document).on('click', '.albums .album .delete', function (e) { e.preventDefault(); var index = $(e.target).closest('.album-form').data('id'); $('#album-form-' + index).remove(); $('.albumslist .list .name[data-id="' + index + '"]').remove(); done_edit_album(); }); // When the user change the title I have also to update the name // in the album's list $(document).off('change keyup', '.albums .album .nomealb'); $(document).on('change keyup', '.albums .album .nomealb', function (e) { e.preventDefault(); var index = $(e.target).closest('.album-form').data('id'); $('.albumslist .list .name[data-id="' + index + '"] .albumname').text($(e.target).val()); }); // Manage the click on "save album" $(document).off('click', '.albums .album .save'); $(document).on('click', '.albums .album .save', function (e) { e.preventDefault(); done_edit_album(); }); // Manage the click on "back" $(document).off('click', '.albums .album .annulla'); $(document).on('click', '.albums .album .annulla', function (e) { e.preventDefault(); done_edit_album(); }); } calculate_max_height(); apply_max_height(); dragndrop(); } return { 'init': init, 'dragndrop': dragndrop }; }()); /* login component */ di4b.login = (function () { function init() { $('.login').click(function(e) { e.preventDefault(); $this = $(this); $.get($this.attr('href'), {}, function(data, textStatus) { if (textStatus == 'success') { di4b.modal_message.show('Accesso alla Modalità Modifica', data, { 'width': 400, 'footer': false }); } }, 'html'); }); } return { 'init': init }; }()); /* Load messenger component */ di4b.messenger = (function () { function getUrlVars(url) { var vars = [], hash; var hashes = url.slice(url.indexOf('?') + 1).split('&'); for(var i = 0; i < hashes.length; i++) { hash = hashes[i].split('='); vars.push(hash[0]); vars[hash[0]] = hash[1]; } return vars; } function loadUrlByAjax(caller,data,textStatus) { var title=caller.attr('rel'); var url=caller.attr('href'); if (textStatus == 'success') { if(data=="") { window.location.reload(); return; } var style=""; if(caller.attr('data-style')) style=caller.attr('data-style'); var hasHeader=true; if(caller.hasClass('noheader')) hasHeader=false; var width="400"; if(caller.attr('data-width')) width=caller.attr('data-width'); var height=null; if(caller.attr('data-height')) height=caller.attr('data-height'); var options={ 'width': width, 'footer': false, 'header': hasHeader, 'style': style, 'height': height }; di4b.modal_message.show(title, data, options); } } function init() { $('.messenger').not("form.messenger").click(function(e) { e.preventDefault(); $this = $(this); var caller=$(this); var url=caller.attr('href'); var variables=getUrlVars(url); $.get(url, variables, function(data, textStatus) { loadUrlByAjax(caller,data,textStatus); }, 'html'); }); // stop propagation in inner links so that they do not induce a call to the main messenger $('.messenger').not("form.messenger").find("a").click( function(e) { e.stopPropagation(); } ); $('form.messenger').submit(function(e) { e.preventDefault(); $this = $(this); var caller=$(this); var url=caller.attr('action'); var variables={}; $.each(caller.serializeArray(),function(index,value) { variables[value.name]=value.value; }); $.get(url, variables, function(data, textStatus) { loadUrlByAjax(caller,data,textStatus); }, 'html'); }); } return { 'init': init }; }()); /* Load rotatingSequence component */ function RotatingSequence(wrapper,keepCentered) { // obtain the internal wrapper this.externalWrapper=$(wrapper); this.wrapper=$(this.externalWrapper).find("div"); this.container=this.wrapper.children().first(); this.duration=250; this.resizeTimeout=false; this.setArrowVisibility(); this.keepCentered=keepCentered; this.callback(); $(window).bind("resize",$.proxy(this.callback,this)); } RotatingSequence.prototype.callback=function () { if(this.keepCentered) this.centerElements(); this.setArrowVisibility(); } RotatingSequence.prototype.lastVisible=function () { var childWidth=0; var num=0; // include margin to avoid flickering on double centering var wrapperWidth=this.wrapper.outerWidth(true); this.container.children().each( function(i) { if(childWidth1) num=num-1; return this.container.children().slice(num).first(); } RotatingSequence.prototype.minimalExcess=function () { var childWidth=0; // include margin to avoid flickering on double centering var wrapperWidth=this.wrapper.outerWidth(true); this.container.children().each( function(i) { if(childWidth$(window).width()) this.showArrows(); else this.hideArrows(); } RotatingSequence.prototype.showArrows=function () { this.externalWrapper.find(".larrow").show(); this.externalWrapper.find(".rarrow").show(); } RotatingSequence.prototype.hideArrows=function () { this.externalWrapper.find(".larrow").hide(); this.externalWrapper.find(".rarrow").hide(); } RotatingSequence.prototype.centerElements=function () { if(this.wrapper.width()>$(window).width()) { var excess=parseInt(this.minimalExcess()/2); if(excess<0) excess=0; this.wrapper.css("margin-left","-"+excess+"px"); } else { var diff=$(window).width()-this.totalWidth(); this.wrapper.css("margin-left",diff/2+"px"); } } RotatingSequence.prototype.totalWidth=function () { var childWidth=0; this.container.children().each( function(i) { childWidth+=$(this).outerWidth(true); }); return childWidth; } RotatingSequence.prototype.needsRotation=function () { return this.totalWidth()>this.wrapper.width(); } RotatingSequence.prototype.rotateLeftAnimated=function () { var childs=this.container.children(); var first=childs.first().clone(); var w=childs.first().outerWidth(true); if(childs.first().queue().length!=0) return; first.insertAfter(childs.last()); childs.first().animate({marginLeft: "-="+w},this.duration,function() { childs.first().remove(); }); }; RotatingSequence.prototype.rotateRightAnimated=function () { var childs=this.container.children(); var last=childs.last().clone(); var margin_orig=childs.css("margin-left"); var w=childs.last().outerWidth(true); if(childs.first().queue().length!=0) return; last.insertBefore(childs.first()); last.css("margin-left","-"+w+"px"); last.animate({marginLeft: "+="+w},this.duration,function() { childs.last().remove(); }); }; /** * Manage ajax preview of product */ di4b.catalog = (function () { function init() { if ($('.products_catalog').length == 0) { return false; } $('.products_catalog').find('a.product_link').click(function(e) { e.preventDefault(); $.get($(this).attr('href'), {}, function (data) { di4b.modal_message.show('Dettagli prodotto', data,{ percentagewidth: '80',header: false, footer: false, style: 'catalog-message'}); }); return false; }); return true; } return { 'init': init }; }()); /** * Manage ajax preview of gallery's images */ di4b.gallery = (function () { var loaded = {}; var root = $('#gallery.with_preview'); var max_width = 0; var force_width = 0; var force_width_image = 0; var active = false; function load_img_content(src, width, description) { if (max_width && width > max_width) { width = max_width; image_width = max_width; } if (force_width_image) { image_width = force_width_image; } if (force_width) { width = force_width; } var parent = active.parent(); var next = parent.next('.image'); var prev = parent.prev('.image'); var html_control = ''; if (prev.length > 0) { html_control += '←' } else { html_control += '' } html_control += 'CLOSE' if (next.length > 0) { html_control += '→' } else { html_control += '' } html_control += ''; var html = ''; if (description) { html += '' + description + ''; } di4b.modal_message.change(html_control + html, width); if (prev.length > 0) { di4b.modal_message.getObject().find('.control .left').click(function (e) { e.preventDefault(); di4b.modal_message.setloader(); load_img(prev.find('a')); }); } di4b.modal_message.getObject().find('.control .center').click(function (e) { e.preventDefault(); di4b.modal_message.hide(); }); if (next.length > 0) { di4b.modal_message.getObject().find('.control .right').click(function (e) { e.preventDefault(); di4b.modal_message.setloader(); load_img(next.find('a')); }); } } function load_img(obj) { active = obj; var description = obj.parent().find('.description'); if (description.length > 0) { description = description.html(); } else { description = ''; } var img_src = active.attr('href'); if (!loaded[img_src]) { // Visualizzo il box di caricamento var img = new Image(); img.onload = function() { loaded[img_src] = img.width; load_img_content(img_src, img.width, description); }; img.src = img_src; } else { load_img_content(img_src, loaded[img_src], description); } } function init() { var opts = { header: false, footer: false, backdrop: true, transparent: true, nopadding: true }; if (root.length == 0) { return false; } if (root.find('input[type=hidden].max_width').length > 0) { max_width = root.find('input[type=hidden].max_width').val(); } if (root.find('input[type=hidden].force_width').length > 0) { force_width = root.find('input[type=hidden].force_width').val(); } if (root.find('input[type=hidden].force_width_image').length > 0) { force_width_image = root.find('input[type=hidden].force_width_image').val(); } else { force_width_image = force_width; } root.find('a.preview').click(function(e) { e.preventDefault(); $this = $(this); opts['loader'] = true; if ($this.data('modal-style')) { opts['style'] = $this.data('modal-style'); } di4b.modal_message.show('', '', opts); load_img($this); }); return true; } return { 'init': init }; }()); di4b.timeline = (function () { var slideshow = false; function init() { $(document).on('click', '.flipbook-controls a.next', function (e) { e.preventDefault(); $('.flipbook').flipbook.gotoNext(); }); $(document).on('click', '.flipbook-controls a.auto', function (e) { e.preventDefault(); if (slideshow) { $('.flipbook').flipbook.pauseSlideshow(); $(e.target).parent().removeClass("stop"); slideshow = false; } else { $('.flipbook').flipbook.playSlideshow(); $(e.target).parent().addClass("stop"); slideshow = true; } }); $(document).on('click', '.flipbook-controls a.back', function (e) { e.preventDefault(); $('.flipbook').flipbook.gotoPrev(); }); return true; } return { 'init': init }; }()); di4b.admin = {}; /** * Manage async update of the fields in the admin * section. */ di4b.admin.update_form_fields = (function () { var typology = ''; function update_fields() { var action = $("#formSalva").attr('action'); // Just pass typology, style and title // ... everything else just introduces troubles var form_data = { 'typology_rewrite': $('#typology').val(), 'page_Nome': $('#page_Nome').val(), 'page_Stile': $('#stile').val(), 'bott_salva': 'update_form' }; $.post(action, form_data, function (form) { // Put the class of formSalva var new_typology = $('input[name="page_Tipo"]', form).val(); $("#formSalva").removeClass(typology).addClass(new_typology); typology = new_typology; // and place the new html $("#formSalvaContenuto").html(form); // and new typology and style $("#page_Tipo").val(new_typology); $("#stile").val($('input[name="page_Stile"]', form).val()); // Relaunch admin scripts $("#formSalva").off("click"); di4b.admin.init(); }); } function init() { typology = $("#page_Tipo").val(); $('#formSalva').on('change', '#formSalva #typology', function() { update_fields(); }); } return { 'init': init }; }()); /** * Init TinyMCE codes */ di4b.admin.tinymce = (function () { function init() { if (typeof(tiny_configs) == 'undefined' || typeof(tinyMCE) == 'undefined') return false; for (config in tiny_configs) { tinyMCE.init(tiny_configs[config]); } return true; } return { 'init': init } }()); di4b.admin.disable_page_form = function () { $('#formSalva > .actions button').attr('disabled', 'disabled'); $('#formSalva > .actions a.btn').addClass('disabled'); $('#formSalva > .actions a.btn').each(function () { $(this).attr('data-old-href', $(this).attr('href')).removeAttr('href'); }); $('#page_Nome, #page_homepage').attr('disabled', 'disabled'); }; di4b.admin.enable_page_form = function () { $('#formSalva > .actions button').removeAttr('disabled'); $('#formSalva > .actions a.btn').removeClass('disabled'); $('#formSalva > .actions a.btn').each(function () { $(this).attr('href', $(this).attr('data-old-href')).removeAttr('data-old-href'); }); $('#page_Nome, #page_homepage').removeAttr('disabled'); }; /** * Code to manage the scroller buttons. */ di4b.scrollers = (function() { var oldY = 0, oldInnerHeight = 0; function checkSize () { return window.innerHeight < document.body.clientHeight; } /* * If needed it adds the controllers to go up and down * in the page. */ function putControllers() { $("#scrolldown,#scrollup").remove(); if (checkSize()) { $('#container').append('Vai giu'); if (window.scrollY > 0) { $('#container').append('Vai su'); } } } function goUp() { window.scrollBy(0, -50); } function goDown() { window.scrollBy(0, 50); } function init() { $(document).on('click', '#scrolldown, #scrollup', function(e) { e.preventDefault(); if (this.id == 'scrolldown') { goDown(); } else { goUp(); } putControllers(); }); // Put a timeout to check the scroll. Using the scroll/resize event is // not a good idea in these days setInterval(function () { if (oldY != window.scrollY || oldInnerHeight != window.innerHeight) { putControllers(); oldY = window.scrollY; oldInnerHeight = window.innerHeight; } }, 100); } return { 'init': init } })(); /** * Code to manage the quickedit */ di4b.quickedit = (function() { function selectpage() { $selected = $('#quickedit select option:selected'); $('#quickedit .typology .value').text($selected.data('typology')); } function init() { $(document).on('click', '#quickedit .btn', function(e) { $this = $(this); $selected = $('#quickedit select option:selected'); if ($this.hasClass('delete')) { e.preventDefault(); window.location = $selected.data('url-delete'); } else if ($this.hasClass('edit')) { e.preventDefault(); window.location = $selected.data('url-edit'); } else if ($this.hasClass('view')) { e.preventDefault(); window.location = $selected.data('url-view'); } else if ($this.hasClass('new')) { // Just follow the href of the "button" } }); $(document).on('change', '#quickedit select', function(e) { selectpage(); e.preventDefault(); }); selectpage(); } return { 'init': init }; })(); /** * Init TinyMCE codes */ di4b.admin.tinymce = (function () { function init() { if (typeof(tiny_configs) == 'undefined' || typeof(tinyMCE) == 'undefined') return false; for (config in tiny_configs) { tinyMCE.init(tiny_configs[config]); } return true; } return { 'init': init }; }()); /** * Init form check */ di4b.admin.formcheck = (function () { function init() { $(document).on('submit', '#formSalva', function (e) { if ($('#page_Nome').length > 0 && $('#page_Nome').val().length == 0) { alert("Il titolo della pagina non può essere vuoto!"); e.preventDefault(); } }); } return { 'init': init }; }()); di4b.admin.init = function() { di4b.admin_gallery.init(); di4b.admin_catalog.init(); di4b.admin_mosaic.init(); di4b.admin_album.init(); di4b.admin_containeralbum.init(); di4b.admin.tinymce.init(); di4b.admin.formcheck.init(); }; di4b.admin.disable_page_form = function () { $('#formSalva > .actions button').attr('disabled', 'disabled'); $('#formSalva > .actions a.btn').addClass('disabled'); $('#formSalva > .actions a.btn').each(function () { $(this).attr('data-old-href', $(this).attr('href')).removeAttr('href'); }); $('#page_Nome, #page_homepage').attr('disabled', 'disabled'); }; di4b.admin.enable_page_form = function () { $('#formSalva > .actions button').removeAttr('disabled'); $('#formSalva > .actions a.btn').removeClass('disabled'); $('#formSalva > .actions a.btn').each(function () { $(this).attr('href', $(this).attr('data-old-href')).removeAttr('data-old-href'); }); $('#page_Nome, #page_homepage').removeAttr('disabled'); }; function ajaxSendEmail(form) { if(form.beingSubmitted==true) return false; form.beingSubmitted=true; $.ajax({ url: "sendEmail.php", type: "post", data: { mailform_email: form.mailform_email===undefined ? '' : form.mailform_email.value, mailform_body: form.mailform_body===undefined ? '' : form.mailform_body.value, mailform_telefono: form.mailform_telefono===undefined ? '' : form.mailform_telefono.value, mailform_nome: form.mailform_nome===undefined ? '' : form.mailform_nome.value, mailform_tipo: form.mailform_tipo===undefined ? '' : form.mailform_tipo.value, mailform_destinatari: form.mailform_destinatari===undefined ? '' : form.mailform_destinatari.value }, dataType: "html", beforeSend: function() { $(".page").css("cursor","wait"); }, success: function(msg) { $(".page").css("cursor","default"); di4b.modal_message.show("invio messaggio email",msg,{ 'width': 500 }); if(msg.search("Errore")==-1) { if(form.mailform_email) form.mailform_email.value=''; if(form.mailform_body) form.mailform_body.value=''; if(form.mailform_telefono) form.mailform_telefono.value=''; if(form.mailform_nome) form.mailform_nome.value=''; if(form.mailform_tipo) form.mailform_tipo.value=''; if(form.mailform_destinatari) form.mailform_destinatari.value=''; } form.beingSubmitted=false; } }); return false; } function reload_widget(obj) { if(obj.attr("data-from-url")===undefined) return; var url=obj.attr("data-from-url"); $.ajax({url: url, success: function(data,textStatus) {obj.html(data);} }); } function reload_widgets() { $("[data-from-url]").each(function() { reload_widget($(this)); }); } $(document).ready(function() { $("#topmenu").mouseover(function(){ return Menu_Topmenu($(this)); }); // deal the menu variabile $("#footer").hover(function(){ menu='menu_footer'; }, function(){ menu='menu_content'; }); $("#topmenu").hover(function(){ menu='menu_topmenu'; }, function(){ menu='menu_content'; }); $("#submenu").hover(function(){ menu='menu_submenu'; }, function(){ menu='menu_content'; }); $("#sidemenu").hover(function(){ menu='menu_catalog'; }, function(){ menu='menu_content'; }); // Popover for disabled elements if ($.fn.popover) { $("a[rel=popover],button[rel=popover]").popover({ offset: 10, placement: 'above' }).click(function(e) { e.preventDefault() }); } /* * Admin stuff */ di4b.menu.init('topmenu'); di4b.admin_menu.init('topmenu'); di4b.menu.init('submenu'); di4b.admin_menu.init('submenu'); di4b.admin_catalog.init(); di4b.admin_album.init(); di4b.admin_containeralbum.init(); di4b.admin.update_form_fields.init(); di4b.admin.tinymce.init(); // Login (available to admins and users) di4b.login.init(); // activate modal popup on tags with "messenger" class di4b.messenger.init(); // User staff di4b.catalog.init(); di4b.gallery.init(); di4b.timeline.init(); di4b.quickedit.init(); //di4b.scrollers.init(); // eliminati gli scrollers, per fortuna! var bc_width=$(".vertical-title .text img").width()+ $(".vertical-title .text a").first().width(); if($(".vertical-title .text a").length>1) bc_width+=$(".vertical-title .text a").last().width()+100; if($(".content").height()0) { $(".admin .page.link-slider .ulist").sortable({ handle: ".drag", items: "> li:not(.add)" }); } // activate sortable on link-slider items if sortable has been loaded if($(".admin .related_products").length>0) { $(".admin .related_products").sortable({ handle: ".drag", items: "> .productrelated_link:not(.add)" }); } });