| 1 |
Drupal.qeditInit = function() {
|
| 2 |
$('.form-autocomplete').click(function (){
|
| 3 |
this.select();
|
| 4 |
});
|
| 5 |
$('.ajax-button').each(function () {
|
| 6 |
var uri = $('.ajax-save-url').val();
|
| 7 |
var wrapper = '#message';
|
| 8 |
var qajax = new Drupal.qajax(uri, this, wrapper);
|
| 9 |
});
|
| 10 |
$('.title, .date').click(function (){
|
| 11 |
var title = $(this).text();
|
| 12 |
var loadUri= $('.ajax-load-url').val();
|
| 13 |
var id = $(this).attr('id').replace(/title-/, '').replace(/date-/, '');
|
| 14 |
Drupal.activeEdit(this);
|
| 15 |
if($(this).attr('class') == 'title'){
|
| 16 |
if(clean_url) var pattern = '?';
|
| 17 |
else pattern = '&';
|
| 18 |
Drupal.showBody(loadUri + pattern + 'nid='+id+'&width=600', $(this).attr('id'), title);
|
| 19 |
}
|
| 20 |
});
|
| 21 |
$('td .title, td .date').mouseover(function (){
|
| 22 |
var p = $(this).parent('td');
|
| 23 |
$(p).css('background-color', '#CFC');
|
| 24 |
});
|
| 25 |
$('td .title, td .date').mouseout(function (){
|
| 26 |
var p = $(this).parent('td');
|
| 27 |
$(p).css('background-color', 'transparent');
|
| 28 |
});
|
| 29 |
|
| 30 |
}
|
| 31 |
|
| 32 |
Drupal.qajax = function(uri, button, wrapper){
|
| 33 |
this.wrapper = wrapper;
|
| 34 |
Drupal.redirectFormButton(uri, button, this);
|
| 35 |
}
|
| 36 |
Drupal.qajax.prototype.onsubmit = function () {
|
| 37 |
this.progress = new Drupal.progressBar('load progress');
|
| 38 |
this.progress.setProgress(-1, 'loading...');
|
| 39 |
var el = this.progress.element;
|
| 40 |
$(el).css({
|
| 41 |
width: '28em',
|
| 42 |
paddingTop: '10px',
|
| 43 |
display: 'none'
|
| 44 |
});
|
| 45 |
$(this.wrapper).prepend(el);
|
| 46 |
$(el).show();
|
| 47 |
}
|
| 48 |
Drupal.qajax.prototype.oncomplete = function (data) {
|
| 49 |
$(this.progress.element).remove();
|
| 50 |
$('.message').each(function (){
|
| 51 |
$(this).remove();
|
| 52 |
});
|
| 53 |
var div = document.createElement('div');
|
| 54 |
$(div).addClass('message');
|
| 55 |
$(div).html(data);
|
| 56 |
$(this.wrapper).append(div);
|
| 57 |
return false;
|
| 58 |
}
|
| 59 |
Drupal.qajax.prototype.onerror = function (error) {
|
| 60 |
alert('An error occurred:\n\n'+ error);
|
| 61 |
// Remove progressbar
|
| 62 |
$(this.progress.element).remove();
|
| 63 |
this.progress = null;
|
| 64 |
}
|
| 65 |
|
| 66 |
Drupal.activeEdit = function(obj) {
|
| 67 |
$('#JT').remove();
|
| 68 |
$('.message').remove();
|
| 69 |
var id = $(obj).attr('id').replace(/title-/, '').replace(/date-/, '');
|
| 70 |
var calendarid = 'edit-date-'+id;
|
| 71 |
var type = $(obj).attr('class');
|
| 72 |
var revert = $(obj).text();
|
| 73 |
var content = $(obj).text();
|
| 74 |
var textfield = document.createElement('input');
|
| 75 |
var calendar = document.createElement('span');
|
| 76 |
var saveButton = document.createElement('input');
|
| 77 |
var cancelButton = document.createElement('input');
|
| 78 |
var br = document.createElement('br');
|
| 79 |
if(type == 'title'){
|
| 80 |
var size = 45;
|
| 81 |
}
|
| 82 |
else{
|
| 83 |
var size = 20;
|
| 84 |
}
|
| 85 |
textfield.setAttribute('value', content);
|
| 86 |
$(textfield).attr({type: 'text', name: type, size: size}).addClass('textfield');
|
| 87 |
$(textfield).attr({type: 'text', name: type, size: size, id: 'edit-date-' + id}).addClass('textfield');
|
| 88 |
$(calendar).attr({id: 'edit-date-'+id+'-button'}).addClass("jscalendar-icon").html('...');
|
| 89 |
|
| 90 |
saveButton.setAttribute('type', 'button');
|
| 91 |
cancelButton.setAttribute('type', 'button');
|
| 92 |
$(saveButton).attr({ value : 'Save'}).addClass('ajax-button').addClass('form-button');
|
| 93 |
$(cancelButton).attr({ value : 'Cancel'}).addClass('form-button');
|
| 94 |
$(obj)
|
| 95 |
.empty()
|
| 96 |
.before(textfield).before(br).before(saveButton).before(cancelButton);
|
| 97 |
// calendar
|
| 98 |
if(type == 'date'){
|
| 99 |
$(br).before(calendar);
|
| 100 |
Calendar.setup({
|
| 101 |
inputField : calendarid,
|
| 102 |
ifFormat : '%Y-%m-%d %H:%M:%S',
|
| 103 |
button : calendarid + '-button',
|
| 104 |
showsTime : true,
|
| 105 |
timeFormat : '24'
|
| 106 |
});
|
| 107 |
}
|
| 108 |
$(saveButton).click(function (){
|
| 109 |
var c = $(textfield).val();
|
| 110 |
var uri = $('.ajax-save-url').val();
|
| 111 |
var token = $('.ajax-form-token').val();
|
| 112 |
$.post(uri, {type: type, content: c, nid: id, form_token: token}, function(data){
|
| 113 |
if(data){
|
| 114 |
$(textfield).remove();
|
| 115 |
$(saveButton).remove();
|
| 116 |
$(cancelButton).remove();
|
| 117 |
$(br).remove();
|
| 118 |
if(type == 'date')
|
| 119 |
$(calendar).remove();
|
| 120 |
var message = document.createElement('span');
|
| 121 |
$(message).html('saved').addClass('message').css({color: 'red', float: 'right'});
|
| 122 |
$('#JT').remove();
|
| 123 |
$(obj).html(c).before(message);
|
| 124 |
}
|
| 125 |
else{
|
| 126 |
// error control
|
| 127 |
$(obj).empty().html(revert);
|
| 128 |
}
|
| 129 |
});
|
| 130 |
});
|
| 131 |
$(cancelButton).click(function (){
|
| 132 |
$(textfield).remove();
|
| 133 |
$(saveButton).remove();
|
| 134 |
$(cancelButton).remove();
|
| 135 |
$(br).remove();
|
| 136 |
$('#JT').remove();
|
| 137 |
if(type == 'date')
|
| 138 |
$(calendar).remove();
|
| 139 |
$(obj)
|
| 140 |
.empty()
|
| 141 |
.html(revert);
|
| 142 |
});
|
| 143 |
|
| 144 |
}
|
| 145 |
Drupal.showBody = function (url, linkId, title){
|
| 146 |
var queryString = url.replace(/^[^\?]+\??/,'');
|
| 147 |
var params = parseQuery( queryString );
|
| 148 |
if(params['link'] !== undefined){
|
| 149 |
$('#' + linkId).bind('click',function(){window.location = params['link']});
|
| 150 |
}
|
| 151 |
|
| 152 |
$('#'+linkId).after("<div id='JT' style='width:"+params['width']*1+"px'><div id='JT_arrow_right' style='left:"+((params['width']*1)+1)+"px'></div><div id='JT_close_right'>"+title+"</div><div id='JT_copy'><div class='JT_loader'><div></div></div>");//left side
|
| 153 |
$('#JT').show();
|
| 154 |
$('#JT_copy').load(url);
|
| 155 |
}
|
| 156 |
|
| 157 |
function parseQuery ( query ) {
|
| 158 |
var Params = new Object ();
|
| 159 |
if ( ! query ) return Params; // return empty object
|
| 160 |
var Pairs = query.split(/[;&]/);
|
| 161 |
for ( var i = 0; i < Pairs.length; i++ ) {
|
| 162 |
var KeyVal = Pairs[i].split('=');
|
| 163 |
if ( ! KeyVal || KeyVal.length != 2 ) continue;
|
| 164 |
var key = unescape( KeyVal[0] );
|
| 165 |
var val = unescape( KeyVal[1] );
|
| 166 |
val = val.replace(/\+/g, ' ');
|
| 167 |
Params[key] = val;
|
| 168 |
}
|
| 169 |
return Params;
|
| 170 |
}
|
| 171 |
|
| 172 |
if(Drupal.jsEnabled) {
|
| 173 |
$(document).ready(Drupal.qeditInit);
|
| 174 |
}
|
| 175 |
|