Reindent dialog JS and trim trailing spaces

This commit is contained in:
Joshua Peek
2011-09-27 16:50:24 -05:00
parent 41c4801aed
commit 903ea7c49a
@@ -7,190 +7,190 @@
(function($) { (function($) {
var Dialog = { var Dialog = {
debugOn: false, debugOn: false,
markupCreated: false, markupCreated: false,
attachEvents: function( evtOK ) { attachEvents: function( evtOK ) {
$('#gollum-dialog-action-ok').click(function( e ) { $('#gollum-dialog-action-ok').click(function( e ) {
Dialog.eventOK( e, evtOK ); Dialog.eventOK( e, evtOK );
}); });
$('#gollum-dialog-action-cancel').click( Dialog.eventCancel ); $('#gollum-dialog-action-cancel').click( Dialog.eventCancel );
}, },
createFieldMarkup: function( fieldArray ) { createFieldMarkup: function( fieldArray ) {
var fieldMarkup = '<fieldset>'; var fieldMarkup = '<fieldset>';
for ( var i=0; i < fieldArray.length; i++ ) { for ( var i=0; i < fieldArray.length; i++ ) {
if ( typeof fieldArray[i] == 'object' ) { if ( typeof fieldArray[i] == 'object' ) {
fieldMarkup += '<div class="field">'; fieldMarkup += '<div class="field">';
switch ( fieldArray[i].type ) { switch ( fieldArray[i].type ) {
// only text is supported for now // only text is supported for now
case 'text': case 'text':
fieldMarkup += Dialog.createFieldText( fieldArray[i] ); fieldMarkup += Dialog.createFieldText( fieldArray[i] );
break; break;
default: default:
break; break;
} }
fieldMarkup += '</div>'; fieldMarkup += '</div>';
} }
} }
fieldMarkup += '</fieldset>'; fieldMarkup += '</fieldset>';
return fieldMarkup; return fieldMarkup;
}, },
createFieldText: function( fieldAttributes ) { createFieldText: function( fieldAttributes ) {
var html = ''; var html = '';
if ( fieldAttributes.name ) { if ( fieldAttributes.name ) {
html += '<label'; html += '<label';
if ( fieldAttributes.id ) { if ( fieldAttributes.id ) {
html += ' for="' + fieldAttributes.name + '"'; html += ' for="' + fieldAttributes.name + '"';
} }
html += '>' + fieldAttributes.name + '</label>'; html += '>' + fieldAttributes.name + '</label>';
} }
html += '<input type="text"'; html += '<input type="text"';
if ( fieldAttributes.id ) { if ( fieldAttributes.id ) {
html += ' name="' + fieldAttributes.id + '"' html += ' name="' + fieldAttributes.id + '"'
if ( fieldAttributes.type == 'code' ) { if ( fieldAttributes.type == 'code' ) {
html+= ' class="code"'; html+= ' class="code"';
} }
html += ' id="gollum-dialog-dialog-generated-field-' + html += ' id="gollum-dialog-dialog-generated-field-' +
fieldAttributes.id + '">'; fieldAttributes.id + '">';
} }
return html; return html;
}, },
createMarkup: function( title, body ) { createMarkup: function( title, body ) {
Dialog.markupCreated = true; Dialog.markupCreated = true;
return '<div id="gollum-dialog-dialog">' + return '<div id="gollum-dialog-dialog">' +
'<div id="gollum-dialog-dialog-inner">' + '<div id="gollum-dialog-dialog-inner">' +
'<div id="gollum-dialog-dialog-bg">' + '<div id="gollum-dialog-dialog-bg">' +
'<div id="gollum-dialog-dialog-title"><h4>' + '<div id="gollum-dialog-dialog-title"><h4>' +
title +'</h4></div>' + title +'</h4></div>' +
'<div id="gollum-dialog-dialog-body">' + body + '</div>' + '<div id="gollum-dialog-dialog-body">' + body + '</div>' +
'<div id="gollum-dialog-dialog-buttons">' + '<div id="gollum-dialog-dialog-buttons">' +
'<a href="#" title="Cancel" id="gollum-dialog-action-cancel" ' + '<a href="#" title="Cancel" id="gollum-dialog-action-cancel" ' +
'class="minibutton">Cancel</a>' + 'class="minibutton">Cancel</a>' +
'<a href="#" title="OK" id="gollum-dialog-action-ok" '+ '<a href="#" title="OK" id="gollum-dialog-action-ok" '+
'class="minibutton">OK</a>' + 'class="minibutton">OK</a>' +
'</div>' + '</div>' +
'</div>' + '</div>' +
'</div>' + '</div>' +
'</div>'; '</div>';
}, },
eventCancel: function( e ) { eventCancel: function( e ) {
e.preventDefault(); e.preventDefault();
debug('Cancelled dialog.'); debug('Cancelled dialog.');
Dialog.hide(); Dialog.hide();
}, },
eventOK: function( e, evtOK ) { eventOK: function( e, evtOK ) {
e.preventDefault(); e.preventDefault();
var results = []; var results = [];
// get the results from each field and build them into the object // get the results from each field and build them into the object
$('#gollum-dialog-dialog-body input').each(function() { $('#gollum-dialog-dialog-body input').each(function() {
results[$(this).attr('name')] = $(this).val(); results[$(this).attr('name')] = $(this).val();
}); });
// pass them to evtOK if it exists (which it should) // pass them to evtOK if it exists (which it should)
if ( evtOK && if ( evtOK &&
typeof evtOK == 'function' ) { typeof evtOK == 'function' ) {
evtOK( results ); evtOK( results );
} }
Dialog.hide(); Dialog.hide();
}, },
hide: function() { hide: function() {
if ( $.browser.msie ) { if ( $.browser.msie ) {
$('#gollum-dialog-dialog').hide().removeClass('active'); $('#gollum-dialog-dialog').hide().removeClass('active');
$('select').css('visibility', 'visible'); $('select').css('visibility', 'visible');
} else { } else {
$('#gollum-dialog-dialog').animate({ opacity: 0 }, { $('#gollum-dialog-dialog').animate({ opacity: 0 }, {
duration: 200, duration: 200,
complete: function() {
$('#gollum-dialog-dialog').removeClass('active');
}
});
}
},
init: function( argObject ) {
var title = '';
var body = '';
// bail out if necessary
if ( !argObject ||
typeof argObject != 'object' ) {
debug('Editor Dialog: Cannot init; invalid init object');
return;
}
if ( argObject.body && typeof argObject.body == 'string' ) {
body = '<p>' + argObject.body + '</p>';
}
// alright, build out fields
if ( argObject.fields && typeof argObject.fields == 'object' ) {
body += Dialog.createFieldMarkup( argObject.fields );
}
if ( argObject.title && typeof argObject.title == 'string' ) {
title = argObject.title;
}
if ( Dialog.markupCreated ) {
$('#gollum-dialog-dialog').remove();
}
var $dialog = $( Dialog.createMarkup( title, body ) );
$('body').append( $dialog );
if ( argObject.OK &&
typeof argObject.OK == 'function' ) {
Dialog.attachEvents( argObject.OK );
}
Dialog.show();
},
show: function() {
if ( !Dialog.markupCreated ) {
debug('Dialog: No markup to show. Please use init first.');
} else {
debug('Showing dialog');
if ( $.browser.msie ) {
$('#gollum-dialog.dialog').addClass('active');
Dialog.position();
$('select').css('visibility', 'hidden');
} else {
$('#gollum-dialog.dialog').css('display', 'none');
$('#gollum-dialog-dialog').animate({ opacity: 0 }, {
duration: 0,
complete: function() { complete: function() {
$('#gollum-dialog-dialog').removeClass('active'); $('#gollum-dialog-dialog').css('display', 'block');
Dialog.position(); // position this thing
$('#gollum-dialog-dialog').animate({ opacity: 1 }, {
duration: 500
});
} }
}); });
} }
}, }
},
init: function( argObject ) { position: function() {
var title = ''; var dialogHeight = $('#gollum-dialog-dialog-inner').height();
var body = ''; $('#gollum-dialog-dialog-inner')
.css('height', dialogHeight + 'px')
// bail out if necessary .css('margin-top', -1 * parseInt( dialogHeight / 2 ));
if ( !argObject || }
typeof argObject != 'object' ) {
debug('Editor Dialog: Cannot init; invalid init object');
return;
}
if ( argObject.body && typeof argObject.body == 'string' ) {
body = '<p>' + argObject.body + '</p>';
}
// alright, build out fields
if ( argObject.fields && typeof argObject.fields == 'object' ) {
body += Dialog.createFieldMarkup( argObject.fields );
}
if ( argObject.title && typeof argObject.title == 'string' ) {
title = argObject.title;
}
if ( Dialog.markupCreated ) {
$('#gollum-dialog-dialog').remove();
}
var $dialog = $( Dialog.createMarkup( title, body ) );
$('body').append( $dialog );
if ( argObject.OK &&
typeof argObject.OK == 'function' ) {
Dialog.attachEvents( argObject.OK );
}
Dialog.show();
},
show: function() {
if ( !Dialog.markupCreated ) {
debug('Dialog: No markup to show. Please use init first.');
} else {
debug('Showing dialog');
if ( $.browser.msie ) {
$('#gollum-dialog.dialog').addClass('active');
Dialog.position();
$('select').css('visibility', 'hidden');
} else {
$('#gollum-dialog.dialog').css('display', 'none');
$('#gollum-dialog-dialog').animate({ opacity: 0 }, {
duration: 0,
complete: function() {
$('#gollum-dialog-dialog').css('display', 'block');
Dialog.position(); // position this thing
$('#gollum-dialog-dialog').animate({ opacity: 1 }, {
duration: 500
});
}
});
}
}
},
position: function() {
var dialogHeight = $('#gollum-dialog-dialog-inner').height();
$('#gollum-dialog-dialog-inner')
.css('height', dialogHeight + 'px')
.css('margin-top', -1 * parseInt( dialogHeight / 2 ));
}
}; };