Parent: [ec07b0] (diff)

Child: [a4546e] (diff)

Download this file

allura-base.js    176 lines (164 with data), 6.1 kB

  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
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
(function($) {
// Setup label help text
$('label[title]').each(function(){
var $this = $(this);
$this.append('<a href="#" class="help_icon ico"><b class="ui-icon ui-icon-help"></b></a>');
$this.tooltip({showURL: false});
});
// Setup title-pane widgets
$('.title-pane .title').click(function(e) {
e.preventDefault();
$(this).closest('.title-pane')
.find('> .content').toggle('fast', function() {
$(this)
.closest('.title-pane').toggleClass('closed').end()
.toggleClass('hidden');
});
});
if(window.location.hash) {
$(window.location.hash + '.title-pane').removeClass('closed');
}
// Setup editable widgets
$('div.editable, span.editable, h1.editable')
.find('.viewer')
.append('<a class="edit_btn btn ico"><b class="ui-icon ui-icon-pencil"></b><span>Edit</span></a>')
.end()
.click(function(e){
var editable = $(this).closest('.editable');
var editor = editable.find('.editor');
var viewer = editable.find('.viewer');
if(editor.hasClass('overlap')){
editor.width(viewer.width());
}
editable.addClass('editing')
.removeClass('viewing');
// autoresize textareas will be the wrong size the first time due to being hidden, so nudge them
editor.find('textarea').change();
e.stopPropagation();
})
.find('a').click(function(event){
if(!$(this).hasClass('edit_btn')){
event.stopPropagation();
}
})
.end()
.end()
.find('.editor')
.find('input, select, textarea').each(function(i){
var $this = $(this);
var editor = $this.closest('.editor');
$this.attr('original_val', this.value);
if(!$('a.cancel_btn', editor).length){
var save_btns = $('<div class="save_holder"><input type="submit" value="Save"/><a href="#" class="cancel_btn">Cancel</a></div>');
if(editor.hasClass('multiline')){
var save_holder = editor.find('.save_holder');
if(save_holder.length){
save_holder.append(save_btns);
}
else{
editor.append(save_btns);
}
}
else{
editor.append($('<table class="holder_table"><tr/></table>')
.append($('<td/>').append($this))
.append($('<td class="save_controls"/>').append($(save_btns)))
);
}
}
})
.end()
.find('.cancel_btn').click(function(e){
$(this).closest('.editable')
.addClass('viewing')
.removeClass('editing')
.find('input, select, textarea').each(function(){
$(this).val($(this).attr('original_val'));
});
return false;
});
})(jQuery);
$(function(){
$('.defaultText').
focus(function(){
var $this = $(this);
if ( $this.val() == $this[0].title ){
$this.removeClass('defaultTextActive').val('');
}
}).
blur(function(){
var $this = $(this);
if ( !$this.val() ){
$this.addClass('defaultTextActive').val($this[0].title);
}
}).
blur();
$('.selectText').focus(function(){this.select()});
});
function auto_close( o, timeout ){
var $o = $(o);
setTimeout(function(){
$o.fadeOut('slow');
}, timeout);
return $o;
}
function add_close_box( o ){
return $(o).prepend('<a class="btn ico close-box"><b class="ui-icon ui-icon-close"></b></a>');
}
function flash( html, kind, timeout ){
kind || (kind = 'notice');
var $message = add_close_box($('<div class="'+kind+'">').append(html).prependTo('#notifications'));
timeout && auto_close($message, timeout);
return $message;
}
function attach_form_retry( form ){
$(form).submit(function(){
$form = $(this);
var $message = $('#save-message');
$message.length || ($message = flash('<p>saving...</p>').attr('id', 'save-message'));
var $text = $message.find('p');
setTimeout(function(){
// After 7 seconds, express our concern.
$text.text('The server is taking too long to respond.<br/>Retrying in 30 seconds.');
$message.
addClass('error').
removeClass('notice').
show();
setTimeout(function(){
// After 30 seconds total, give up and try again.
$text.text('retrying...');
$message.show();
$form.submit();
}, 23000)
}, 7000);
});
}
$(function(){
// Setup notifications.
$('#flash > div').
prependTo('#notifications').
each(function(){
this.className || (this.className = 'notice');
auto_close(add_close_box(this), 45000);
});
$('#notifications a.close-box').live('click', function(){
$(this).parent().hide();
});
// Add notifications for form submission.
attach_form_retry('form.can-retry');
// Make life a little better for Chrome users by setting tab-order on inputs.
// This won't stop Chrome from tabbing over links, but should stop links from
// coming "in between" fields.
var i = 0;
$('input,textarea,select,button').each(function(){
$(this).attr('tabindex', i++);
});
// Provide prompt text for otherwise empty viewers
var ws = /^\s*$/;
$('[data-prompt]').each(function(){
var $this = $(this);
if ( ws.test($this.text()) ) {
$this.css('color', 'gray').text($this.attr('data-prompt'))
}
});
});