Skip to content
Snippets Groups Projects
Commit f4749685 authored by Guillaume ROUSSE's avatar Guillaume ROUSSE
Browse files

externalize custom javascript in dedicated file

parent 204cced2
No related branches found
No related tags found
No related merge requests found
......@@ -36,6 +36,7 @@ nobase_www_DATA = \
images/favicon_geant.ico \
images/favicon.png \
images/geant_logo_rgb_300dpi.jpg \
account-manager.js \
jquery-1.11.1.min.js \
jquery.cookie-1.4.1.min.js \
jquery.steps.1.1.0.min.js \
......
// To confirm on a link (A HREF)
function request_confirm_link(my_url, my_message) {
question = confirm(my_message);
if (question !="0") {
top.location = my_url;
}
}
function showhide(div){
var oDiv = document.getElementById(div);
if(oDiv.style.display == "none"){
oDiv.style.display = "block";
}else{
oDiv.style.display = "none";
}
}
function hide(div) {
var oDiv = document.getElementById(div);
oDiv.style.display = "none";
}
jQuery(function($){
$.widget( "custom.combobox", {
_create: function() {
this.wrapper = $( "<span>" )
.addClass( "custom-combobox" )
.insertAfter( this.element );
this.element.hide();
this._createAutocomplete();
this._createShowAllButton();
},
_createAutocomplete: function() {
var selected = this.element.children( ":selected" ),
value = selected.val() ? selected.text() : "";
this.input = $( "<input>" )
.appendTo( this.wrapper )
.val( value )
.attr( "title", "" )
.addClass( "custom-combobox-input ui-widget ui-widget-content ui-state-default ui-corner-left error required" )
.autocomplete({
delay: 0,
minLength: 0,
source: $.proxy( this, "_source" )
})
.tooltip({
tooltipClass: "ui-state-highlight"
});
this._on( this.input, {
autocompleteselect: function( event, ui ) {
ui.item.option.selected = true;
this._trigger( "select", event, {
item: ui.item.option
});
},
autocompletechange: "_removeIfInvalid"
});
},
_createShowAllButton: function() {
var input = this.input,
wasOpen = false;
$( "<a>" )
.attr( "tabIndex", -1 )
.attr( "title", "Show All Items" )
.tooltip()
.appendTo( this.wrapper )
.button({
icons: {
primary: "ui-icon-triangle-1-s"
},
text: false
})
.removeClass( "ui-corner-all" )
.addClass( "custom-combobox-toggle ui-corner-right" )
.mousedown(function() {
wasOpen = input.autocomplete( "widget" ).is( ":visible" );
})
.click(function() {
input.focus();
// Close if already visible
if ( wasOpen ) {
return;
}
// Pass empty string as value to search for, displaying all results
input.autocomplete( "search", "" );
});
},
_source: function( request, response ) {
var matcher = new RegExp( $.ui.autocomplete.escapeRegex(request.term), "i" );
response( this.element.children( "option" ).map(function() {
var text = $( this ).text();
if ( this.value && ( !request.term || matcher.test(text) ) )
return {
label: text,
value: text,
option: this
};
}) );
},
_removeIfInvalid: function( event, ui ) {
// Selected an item, nothing to do
if ( ui.item ) {
return;
}
// Search for a match (case-insensitive)
var value = this.input.val(),
valueLowerCase = value.toLowerCase(),
valid = false;
this.element.children( "option" ).each(function() {
if ( $( this ).text().toLowerCase() === valueLowerCase ) {
this.selected = valid = true;
return false;
}
});
// Found a match, nothing to do
if ( valid ) {
return;
}
// Remove invalid value
this.input
.val( "" )
.attr( "title", value + " didn't match any item" )
.tooltip( "open" );
this.element.val( "" );
this._delay(function() {
this.input.tooltip( "close" ).attr( "title", "" );
}, 2500 );
this.input.autocomplete( "instance" ).term = "";
},
_destroy: function() {
this.wrapper.remove();
this.element.show();
}
});
});
......@@ -8,11 +8,9 @@ html1/DTD/xhtml1-transitional.dtd">
<link rel="icon" type="image/png" href="images/favicon.png" />
<!-- Foundation css -->
<link rel="stylesheet" type="text/css" href="foundation/css/normalize.css">
<link rel="stylesheet" type="text/css" href="foundation/css/foundation.css">
<link href="jquery.steps.css" rel="stylesheet">
<link rel="stylesheet" type="text/css" href="jquery.steps.css">
<link rel="stylesheet" type="text/css" href="jquery-ui-1.11.1/jquery-ui.min.css" />
<link rel="stylesheet" type="text/css" href="css/style.css" />
......@@ -21,165 +19,7 @@ html1/DTD/xhtml1-transitional.dtd">
<script type="text/javascript" src="jquery.validate.1.13.0.min.js"></script>
<script type="text/javascript" src="jquery.cookie-1.4.1.min.js"></script>
<script type="text/javascript" src="jquery.steps.1.1.0.min.js"></script>
<script TYPE="text/javascript">
<!--
// To confirm on a link (A HREF)
function request_confirm_link(my_url, my_message) {
question = confirm(my_message);
if (question !="0") {
top.location = my_url;
}
}
function showhide(div){
var oDiv = document.getElementById(div);
if(oDiv.style.display == "none"){
oDiv.style.display = "block";
}else{
oDiv.style.display = "none";
}
}
function hide(div) {
var oDiv = document.getElementById(div);
oDiv.style.display = "none";
}
jQuery(function($){
$.widget( "custom.combobox", {
_create: function() {
this.wrapper = $( "<span>" )
.addClass( "custom-combobox" )
.insertAfter( this.element );
this.element.hide();
this._createAutocomplete();
this._createShowAllButton();
},
_createAutocomplete: function() {
var selected = this.element.children( ":selected" ),
value = selected.val() ? selected.text() : "";
this.input = $( "<input>" )
.appendTo( this.wrapper )
.val( value )
.attr( "title", "" )
.addClass( "custom-combobox-input ui-widget ui-widget-content ui-state-default ui-corner-left error required" )
.autocomplete({
delay: 0,
minLength: 0,
source: $.proxy( this, "_source" )
})
.tooltip({
tooltipClass: "ui-state-highlight"
});
this._on( this.input, {
autocompleteselect: function( event, ui ) {
ui.item.option.selected = true;
this._trigger( "select", event, {
item: ui.item.option
});
},
autocompletechange: "_removeIfInvalid"
});
},
_createShowAllButton: function() {
var input = this.input,
wasOpen = false;
$( "<a>" )
.attr( "tabIndex", -1 )
.attr( "title", "Show All Items" )
.tooltip()
.appendTo( this.wrapper )
.button({
icons: {
primary: "ui-icon-triangle-1-s"
},
text: false
})
.removeClass( "ui-corner-all" )
.addClass( "custom-combobox-toggle ui-corner-right" )
.mousedown(function() {
wasOpen = input.autocomplete( "widget" ).is( ":visible" );
})
.click(function() {
input.focus();
// Close if already visible
if ( wasOpen ) {
return;
}
// Pass empty string as value to search for, displaying all results
input.autocomplete( "search", "" );
});
},
_source: function( request, response ) {
var matcher = new RegExp( $.ui.autocomplete.escapeRegex(request.term), "i" );
response( this.element.children( "option" ).map(function() {
var text = $( this ).text();
if ( this.value && ( !request.term || matcher.test(text) ) )
return {
label: text,
value: text,
option: this
};
}) );
},
_removeIfInvalid: function( event, ui ) {
// Selected an item, nothing to do
if ( ui.item ) {
return;
}
// Search for a match (case-insensitive)
var value = this.input.val(),
valueLowerCase = value.toLowerCase(),
valid = false;
this.element.children( "option" ).each(function() {
if ( $( this ).text().toLowerCase() === valueLowerCase ) {
this.selected = valid = true;
return false;
}
});
// Found a match, nothing to do
if ( valid ) {
return;
}
// Remove invalid value
this.input
.val( "" )
.attr( "title", value + " didn't match any item" )
.tooltip( "open" );
this.element.val( "" );
this._delay(function() {
this.input.tooltip( "close" ).attr( "title", "" );
}, 2500 );
this.input.autocomplete( "instance" ).term = "";
},
_destroy: function() {
this.wrapper.remove();
this.element.show();
}
});
});
//-->
</script>
<script type="text/javascript" src="account-manager.js"></script>
<title>[% title %]</title>
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment