Rfe 9201: Make Survey textAreas yui resizable
This commit is contained in:
parent
46cca4fae1
commit
f4dab79093
2 changed files with 64 additions and 101 deletions
Binary file not shown.
|
|
@ -1,110 +1,73 @@
|
||||||
|
if (typeof Survey == "undefined") {
|
||||||
/*global Survey, YAHOO */
|
|
||||||
if (typeof Survey === "undefined") {
|
|
||||||
var Survey = {};
|
var Survey = {};
|
||||||
}
|
}
|
||||||
|
|
||||||
Survey.ObjectTemplate = (function(){
|
Survey.ObjectTemplate = new function(){
|
||||||
|
|
||||||
// Keep references to widgets here so that we can destory any instances before
|
this.loadObject = function(html,type){
|
||||||
// creating new ones (to avoid memory leaks)
|
|
||||||
var dialog;
|
|
||||||
var editor;
|
|
||||||
|
|
||||||
return {
|
document.getElementById('edit').innerHTML = html;
|
||||||
|
|
||||||
unloadObject: function(){
|
|
||||||
// First destory the editor..
|
|
||||||
if (editor) {
|
|
||||||
editor.destroy();
|
|
||||||
editor = null;
|
|
||||||
}
|
|
||||||
|
|
||||||
// And then the Dialog that contains it.
|
|
||||||
if (dialog) {
|
|
||||||
dialog.destroy();
|
|
||||||
dialog = null;
|
|
||||||
}
|
|
||||||
},
|
|
||||||
|
|
||||||
loadObject: function(html, type){
|
var myTextarea;
|
||||||
// Make sure we purge any event listeners before overwrite innerHTML..
|
|
||||||
YAHOO.util.Event.purgeElement('edit', true);
|
|
||||||
document.getElementById('edit').innerHTML = html;
|
|
||||||
|
|
||||||
var btns = [{
|
|
||||||
text: "Submit",
|
|
||||||
handler: function(){
|
|
||||||
editor.saveHTML();
|
|
||||||
this.submit();
|
|
||||||
},
|
|
||||||
isDefault: true
|
|
||||||
}, {
|
|
||||||
text: "Copy",
|
|
||||||
handler: function(){
|
|
||||||
document.getElementById('copy').value = 1;
|
|
||||||
this.submit();
|
|
||||||
}
|
|
||||||
}, {
|
|
||||||
text: "Cancel",
|
|
||||||
handler: function(){
|
|
||||||
this.cancel();
|
|
||||||
}
|
|
||||||
}, {
|
|
||||||
text: "Delete",
|
|
||||||
handler: function(){
|
|
||||||
document.getElementById('delete').value = 1;
|
|
||||||
this.submit();
|
|
||||||
}
|
|
||||||
}, {
|
|
||||||
text: "Preview",
|
|
||||||
handler: function(){
|
|
||||||
if (type === 'answer') {
|
|
||||||
alert('Sorry, preview is only supported for Sections and Questions, not Answers');
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
var msg = 'This will delete any Survey responses you have made under this ' +
|
|
||||||
'user account and redirect you to the Take Survey page starting at the selected item. ' +
|
|
||||||
"\n\nAre you sure you want to continue?";
|
|
||||||
if (confirm(msg)) {
|
|
||||||
window.location.search = 'func=jumpTo;id=' + dialog.getData().id;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}];
|
|
||||||
|
|
||||||
dialog = new YAHOO.widget.Dialog(type, {
|
|
||||||
width: "600px",
|
|
||||||
context: [document.body, 'tr', 'tr'],
|
|
||||||
visible: false,
|
|
||||||
constraintoviewport: true,
|
|
||||||
buttons: btns
|
|
||||||
});
|
|
||||||
|
|
||||||
dialog.callback = Survey.Comm.callback;
|
|
||||||
dialog.render();
|
|
||||||
|
|
||||||
var textareaId = type + 'Text';
|
|
||||||
var textarea = YAHOO.util.Dom.get(textareaId);
|
|
||||||
|
|
||||||
var height = YAHOO.util.Dom.getStyle(textarea, 'height');
|
|
||||||
if (!height) {
|
|
||||||
height = '300px';
|
|
||||||
}
|
|
||||||
|
|
||||||
// N.B. SimpleEditor has a memory leak so this eats memory on every instantiation
|
var handleSubmit = function(){
|
||||||
editor = new YAHOO.widget.SimpleEditor(textareaId, {
|
myTextarea.saveHTML();
|
||||||
height: height,
|
this.submit();
|
||||||
width: '100%',
|
}
|
||||||
dompath: false //Turns on the bar at the bottom
|
|
||||||
});
|
|
||||||
|
|
||||||
if (editor.get('toolbar')) {
|
var butts = [
|
||||||
editor.get('toolbar').titlebar = false;
|
{ text:"Submit", handler:handleSubmit, isDefault:true },
|
||||||
}
|
{ text:"Copy", handler:function(){document.getElementById('copy').value = 1; this.submit();}},
|
||||||
editor.render();
|
{ text:"Cancel", handler:function(){this.cancel();}},
|
||||||
|
{ text:"Delete", handler:function(){document.getElementById('delete').value = 1; this.submit();}}
|
||||||
|
];
|
||||||
|
|
||||||
|
var form = new YAHOO.widget.Dialog(type,
|
||||||
|
{
|
||||||
|
width : "500px",
|
||||||
|
fixedcenter : true,
|
||||||
|
visible : false,
|
||||||
|
constraintoviewport : true,
|
||||||
|
buttons : butts
|
||||||
|
} );
|
||||||
|
|
||||||
|
form.callback = Survey.Comm.callback;
|
||||||
|
form.render();
|
||||||
|
|
||||||
|
if(type == 'question'){
|
||||||
|
var resize = new YAHOO.util.Resize('resize_randomWords_formId');
|
||||||
|
resize.on('resize', function(ev) {
|
||||||
|
YAHOO.util.Dom.setStyle('randomWords_formId', 'width', (ev.width - 6) + "px");
|
||||||
|
YAHOO.util.Dom.setStyle('randomWords_formId', 'height', (ev.height - 6) + "px");
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
if(type == 'answer'){
|
||||||
|
var resize = new YAHOO.util.Resize('resize_gotoExpression_formId');
|
||||||
|
resize.on('resize', function(ev) {
|
||||||
|
YAHOO.util.Dom.setStyle('gotoExpression_formId', 'width', (ev.width - 6) + "px");
|
||||||
|
YAHOO.util.Dom.setStyle('gotoExpression_formId', 'height', (ev.height - 6) + "px");
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
var textareaId = type+'Text';
|
||||||
|
var textarea = YAHOO.util.Dom.get(textareaId);
|
||||||
|
var height = YAHOO.util.Dom.getStyle(textarea,'height');
|
||||||
|
if (height == ''){
|
||||||
|
height = '300px';
|
||||||
|
}
|
||||||
|
var width = YAHOO.util.Dom.getStyle(textarea,'width');
|
||||||
|
if (width == ''){
|
||||||
|
width = '500px';
|
||||||
|
}
|
||||||
|
myTextarea = new YAHOO.widget.SimpleEditor(textareaId, {
|
||||||
|
height: height,
|
||||||
|
width: width,
|
||||||
|
dompath: false //Turns on the bar at the bottom
|
||||||
|
});
|
||||||
|
myTextarea.render();
|
||||||
|
|
||||||
|
form.show();
|
||||||
|
}
|
||||||
|
}();
|
||||||
|
|
||||||
dialog.show();
|
|
||||||
}
|
|
||||||
};
|
|
||||||
})();
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue