1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54
| /*****************************
NORMAL TAGS FUNCTIONS
*****************************/
function insertTag(startTag, endTag, textareaId, tagType) {
var field = document.getElementById(textareaId);
var scroll = field.scrollTop;
field.focus();
/* Get selection */
if (window.ActiveXObject) {
var textRange = document.selection.createRange();
var currentSelection = textRange.text;
} else {
var startSelection = field.value.substring(0, field.selectionStart);
var currentSelection = field.value.substring(field.selectionStart, field.selectionEnd);
var endSelection = field.value.substring(field.selectionEnd);
}
/* Insert */
if (window.ActiveXObject) {
textRange.text = startTag + currentSelection + endTag;
textRange.moveStart("character", -endTag.length - currentSelection.length);
textRange.moveEnd("character", -endTag.length);
textRange.select();
} else {
field.value = startSelection + startTag + currentSelection + endTag + endSelection;
field.focus();
field.setSelectionRange(startSelection.length + startTag.length, startSelection.length + startTag.length + currentSelection.length);
}
field.scrollTop = scroll;
}
function cancel(){
window.history.back(-1);
}
/***********************
JQUERY FUNCTIONS
***********************/
$(function() {
var url = $( "#url" );
$( "#dialog" ).dialog({
autoOpen: false,
buttons: {
"Ajouter URL": function() {
var starttag = "<a href="http://\"" + url.val() + "\"" target="_blank">";
$( this ).dialog( "close" );
insertTag(starttag,'</a>','textarea');
},
Cancel: function() {
$( this ).dialog( "close" );
}
}
});
$( "#urlopener" ).click(function() {
$( "#dialog" ).dialog( "open" );
});
}); |