Allégement script javascript

This commit is contained in:
Michael RICOIS 2012-01-06 11:23:33 +00:00
parent f3908a3888
commit 5e88c47e88
3 changed files with 153 additions and 148 deletions

View File

@ -20,6 +20,7 @@ class IndexController extends Zend_Controller_Action
public function criteresAction()
{
$this->view->headScript()->appendFile('/themes/default/scripts/fields.js', 'text/javascript');
$this->view->fields = $this->fields;
}

View File

@ -0,0 +1,152 @@
$(document).ready(function(){
$( "#tabs" ).tabs({
cookie: { expires: 1 },
});
$(".tooltip").each(function(){
var title = $(this).attr('title');
var width = $(this).attr('wdth');
$(this).attr('title', '');
$(this).qtip({
solo:true,
content: title,
style: {
width: width,
classes: "ui-tooltip-dark"
},
position: {
at: $('#at').val(),
my: $('#my').val(),
viewport: $(window),
adjust: {
method: $('#adjust_method').val(),
x: parseInt($('#adjust_x').val(), 10) || 0,
y: parseInt($('#adjust_y').val(), 10) || 0
}
}
});
});
$( ".slider-range" ).slider({
range: true,
create: function(event, ui) {
var max = $("#"+$(this).attr('input')).attr('max');
var min = $("#"+$(this).attr('input')).attr('min');
$(this).slider( "option", "min", min );
$(this).slider( "option", "max", max );
},
values : [0, 100000000000000],
slide: function( event, ui ) {
var name = $(this).attr('input');
$( "#"+name ).val( ui.values[ 0 ] + " , " + ui.values[ 1 ] );
},
step: 10,
stop: function( event, ui ) {
var name = $(this).attr('input');
set(name, ui.values[ 0 ] + "," + ui.values[ 1 ]);
},
});
var dates = $( ".from, .to" ).datepicker({
defaultDate: "+1w",
changeMonth: true,
numberOfMonths: 2,
onSelect: function( selectedDate ) {
var option = this.id == "from" ? "maxDate" : "minDate",
instance = $( this ).data( "datepicker" ),
date = $.datepicker.parseDate(
instance.settings.dateFormat ||
$.datepicker._defaults.dateFormat,
selectedDate, instance.settings );
dates.not( this ).datepicker( "option", option, date );
}
});
$( ".datepicker" ).datepicker( "option", "dateFormat", "yymmdd" );
$( "#accordion" ).accordion({
autoHeight: false,
navigation: true,
icons: {
header: "ui-icon-circle-arrow-e",
headerSelected: "ui-icon-circle-arrow-s"
}
});
$( "#toggle" ).button().toggle(function() {
$( "#accordion" ).accordion( "option", "icons", false );
}, function() {
$( "#accordion" ).accordion( "option", "icons", icons );
});
$( ".column" ).sortable({
connectWith: ".column"
});
$( ".portlet" ).addClass( "ui-widget ui-widget-content ui-helper-clearfix ui-corner-all" )
.find( ".portlet-header" )
.addClass( "ui-widget-header ui-corner-all" )
.prepend( "<span class='ui-icon ui-icon-minusthick'></span>")
.end()
.find( ".portlet-content" );
$( ".portlet-header .ui-icon" ).click(function() {
$( this ).toggleClass( "ui-icon-minusthick" ).toggleClass( "ui-icon-plusthick" );
$( this ).parents( ".portlet:first" ).find( ".portlet-content" ).toggle();
});
$( ".column" ).disableSelection();
$('#tabs').delegate('select.criteres', 'change', function(e){
var valeur = $(this, ':selected').val();
e.stopPropagation();
if(valeur == 'tous') {
$('#'+$(this).attr('name')).css('background-color', '');
} else {
$('#'+$(this).attr('name')).css('background-color', '#CCF8D2'); }
set($(this).attr('name'), $(this, ':selected').val());
});
$('#tabs').delegate('input[type=checkbox].criteres', 'click', function(e){
e.stopPropagation();
set($(this).attr('name'), $(this).val());
});
$('#tabs').delegate('input[type=radio].criteres', 'click', function(e){
e.stopPropagation();
set($(this).attr('name'), $(this).val());
});
$('#tabs').delegate('input[type=text].criteres', 'blur', function(e){
e.stopPropagation();
set($(this).attr('name'), $(this).val());
});
$('#tabs').delegate('a.interval', 'click', function(e){
e.preventDefault();
var key = $(this).attr('id');
var values = $('input[name='+key+'1]').val() + ',' + $('input[name='+key+'2]').val();
set(key, values);
return false;
});
});
function set(key, value)
{
$('#comptage').css('display', 'none');
$('#attente').css('display', 'block');
$.post('/comptage', { cle:key, valeur:value}, function(data, status) {
var html = 'Nombre sélectionnées : <span class="valeur">' +
data.count + '</span> (dont <span class="valeur">'+
data.insee +'</span> unité(s) insee)';
$('#attente').css('display', 'none');
$('#comptage').html(html).css('display','block');
}, 'json')
.error(function(){ alert('error'); });
}

View File

@ -1,139 +1,5 @@
$(document).ready(function(){
$( "#tabs" ).tabs({
cookie: { expires: 1 },
});
$(".tooltip").each(function(){
var title = $(this).attr('title');
var width = $(this).attr('wdth');
$(this).attr('title', '');
$(this).qtip({
solo:true,
content: title,
style: {
width: width,
classes: "ui-tooltip-dark"
},
position: {
at: $('#at').val(),
my: $('#my').val(),
viewport: $(window),
adjust: {
method: $('#adjust_method').val(),
x: parseInt($('#adjust_x').val(), 10) || 0,
y: parseInt($('#adjust_y').val(), 10) || 0
}
}
});
});
$( ".slider-range" ).slider({
range: true,
create: function(event, ui) {
var max = $("#"+$(this).attr('input')).attr('max');
var min = $("#"+$(this).attr('input')).attr('min');
$(this).slider( "option", "min", min );
$(this).slider( "option", "max", max );
},
values : [0, 100000000000000],
slide: function( event, ui ) {
var name = $(this).attr('input');
$( "#"+name ).val( ui.values[ 0 ] + " , " + ui.values[ 1 ] );
},
step: 10,
stop: function( event, ui ) {
var name = $(this).attr('input');
set(name, ui.values[ 0 ] + "," + ui.values[ 1 ]);
},
});
var dates = $( ".from, .to" ).datepicker({
defaultDate: "+1w",
changeMonth: true,
numberOfMonths: 2,
onSelect: function( selectedDate ) {
var option = this.id == "from" ? "maxDate" : "minDate",
instance = $( this ).data( "datepicker" ),
date = $.datepicker.parseDate(
instance.settings.dateFormat ||
$.datepicker._defaults.dateFormat,
selectedDate, instance.settings );
dates.not( this ).datepicker( "option", option, date );
}
});
$( ".datepicker" ).datepicker( "option", "dateFormat", "yymmdd" );
$( "#accordion" ).accordion({
autoHeight: false,
navigation: true,
icons: {
header: "ui-icon-circle-arrow-e",
headerSelected: "ui-icon-circle-arrow-s"
}
});
$( "#toggle" ).button().toggle(function() {
$( "#accordion" ).accordion( "option", "icons", false );
}, function() {
$( "#accordion" ).accordion( "option", "icons", icons );
});
$( ".column" ).sortable({
connectWith: ".column"
});
$( ".portlet" ).addClass( "ui-widget ui-widget-content ui-helper-clearfix ui-corner-all" )
.find( ".portlet-header" )
.addClass( "ui-widget-header ui-corner-all" )
.prepend( "<span class='ui-icon ui-icon-minusthick'></span>")
.end()
.find( ".portlet-content" );
$( ".portlet-header .ui-icon" ).click(function() {
$( this ).toggleClass( "ui-icon-minusthick" ).toggleClass( "ui-icon-plusthick" );
$( this ).parents( ".portlet:first" ).find( ".portlet-content" ).toggle();
});
$( ".column" ).disableSelection();
$('#tabs').delegate('select.criteres', 'change', function(e){
var valeur = $(this, ':selected').val();
e.stopPropagation();
if(valeur == 'tous') {
$('#'+$(this).attr('name')).css('background-color', '');
} else {
$('#'+$(this).attr('name')).css('background-color', '#CCF8D2'); }
set($(this).attr('name'), $(this, ':selected').val());
});
$('#tabs').delegate('input[type=checkbox].criteres', 'click', function(e){
e.stopPropagation();
set($(this).attr('name'), $(this).val());
});
$('#tabs').delegate('input[type=radio].criteres', 'click', function(e){
e.stopPropagation();
set($(this).attr('name'), $(this).val());
});
$('#tabs').delegate('input[type=text].criteres', 'blur', function(e){
e.stopPropagation();
set($(this).attr('name'), $(this).val());
});
$('#tabs').delegate('a.interval', 'click', function(e){
e.preventDefault();
var key = $(this).attr('id');
var values = $('input[name='+key+'1]').val() + ',' + $('input[name='+key+'2]').val();
set(key, values);
return false;
});
$('#message').hover(
function(){ $('#control').css('display', 'block'); },
function(){ $('#control').css('display', 'none'); }
@ -163,17 +29,3 @@ $(document).ready(function(){
});
function set(key, value)
{
$('#comptage').css('display', 'none');
$('#attente').css('display', 'block');
$.post('/comptage', { cle:key, valeur:value}, function(data, status) {
var html = 'Nombre sélectionnées : <span class="valeur">' +
data.count + '</span> (dont <span class="valeur">'+
data.insee +'</span> unité(s) insee)';
$('#attente').css('display', 'none');
$('#comptage').html(html).css('display','block');
}, 'json')
.error(function(){ alert('error'); });
}