').append($(xhr.responseText));
}
if (this.loadable.opt.on.receipt instanceof Function) {
this.loadable.opt.on.receipt(data, status, xhr);
}
this.loadable.mount(data);
}
};
(function() {
var proto = AsyncLoadable.prototype = new Object;
proto.submitAsync = function() {
if (this.flying) return false;
this.flying = true;
if (this.isForm) {
if (sentForm) return false;
sentForm = this;
}
var post = this.jQ.serialize();
this.jQ.attr({
debug: '001'
});
this.block();
this.url.setParams({
xhr: true
});
var on = this.on;
// for local dev
if (window.location.hostname == 'localnode.taz.de' ) {
// this.url.protocol = 'http';
this.url.hostname = 'localnode.taz.de';
this.url.host = 'localnode.taz.de';
this.url.origin = '//localnode.taz.de';
}
//console.log(this.isForm ? 'POST' : 'GET');
console.log(this.url.toString());
$.ajax({
type: this.isForm ? 'POST' : 'GET',
url: '' + this.url,
cache: false,
data: post,
dataType: 'html', // 'xml',
xhrFields: {
withCredentials: true
},
beforeSend: function(xhr, settings) {
xhr.responseType = 'document';
},
success: function(data, status, xhr) {
on[200]($(data), status, xhr);
},
error: function(xhr, status, message) {
var data = $(xhr.response);
if (!data.length) {
var text;
try {
text = xhr.responseText;
if (text) text = text.replace(/http:/g, "");
data = $('
').html(text);
} catch (e) {
}
}
if (!data.length) {
try {
} catch (e) {
}
}
on[xhr.status && on[xhr.status] ?
xhr.status :
0
](data, status, xhr, message);
},
complete: function(xhr, status) {
}
});
};
proto.remove = function() {
var registerID = this.domEl.filOtaz_de_asynchLoadable;
this.jQ.remove();
allAsyncLoadables[registerID] = null;
};
proto.mount = function(data) {
var opt = this.opt;
var pkg = (data[0] instanceof HTMLDivElement) ? data : data.find('body');
if (!pkg.length) pkg = $(data[0].documentElement);
if (!pkg.length) alert('this should not happen ', data[0]);
var pick = pkg.find(opt.pick);
var me = this;
var replace = [{
treatee: me.jQ,
pick: pick,
ajaxify: true
}];
if (opt.replace instanceof Array) replace = replace.concat(opt.replace);
$.each(replace, function(i, r) {
var i = i,
old = $(r.treatee),
nju = $(r.pick, pkg);
//console.log('debug old nju', old, nju, pkg.prop('outerHTML') );
if (!old.length) return;
var isPrimary = i == 0;
if (!nju.length && !r.remove) {
if (isPrimary) {
me.unblock();
me.flying = false;
if (me.isForm) sentForm = false;
}
return;
}
var anchor = $('
').hide().insertBefore(old);
var id = old.attr('id');
if (id)(nju.length ? nju : anchor).not('script').attr({
id: id
});
old.slideUp(function() {
old.remove();
if (isPrimary) {
me.remove();
if (me.isForm) sentForm = false;
}
});
var last = anchor;
nju.each(function(i, e) {
var jQ = $(e);
var scripts = false;
if (jQ.is('script')) {
$('body').append(jQ);
return;
}
if (0 0) ctrls.attr('tabindex', opt.tabindex);
if (opt.focus > 0) ctrls.first().focus()
}
});
});
};
proto.demandPageReload = function() {
this.showMessage('', {
block: true,
onConfirm: function() {
location.protocol = 'https';
return false;
},
html: '
Um Formular-Inhalte gesichert übertragen zu können, muß bereits ' +
'diese Seite per HTTPS geladen werden, da Ihr Browser neuere Technologie' +
' nicht unterstützt.
' +
'
Vielleicht sollten Sie einen moderneren Browser' +
' verwenden.
',
hint: 'mit https neu laden'
});
};
proto.showMessage = function(message, opt) {
var opt = ensureObjType(opt, Object);
if (opt.block) this.block();
var form = this;
var me = $('
')
.on('submit', function() {
var blockOn = opt.onConfirm instanceof Function && opt.onConfirm() == false;
me.slideUp(function() {
form.jQ = form.jQ.not(me);
me.remove();
});
if (!blockOn) form.unblock(opt.replacement);
return false;
})
.html((opt.title ? ('
') : '') +
'
' +
(message ? ('
' + message + '
') : '') +
(opt.html || '') +
'
' +
'
'
)
.hide().insertAfter(this.jQ);
if (opt.slide) me.slideDown(function() {
me.trigger('TAZboxChange');
});
else me.show();
form.jQ = form.jQ.add(me);
};
proto.block = function() {
var form = this.jQ;
this.restore = form.clone(true);
form.submit(function() {
return false;
});
form.find('.sectbody').css({
opacity: 0.3
});
form.find('input, textarea').attr({
disabled: true
});
form.find('input:submit').fadeOut();
return this.restore;
};
proto.unblock = function(replacement) {
var replacement = replacement || this.restore;
if (!replacement) return false;
this.replaceForm(replacement);
this.restore = null;
};
proto.replaceForm = function(replace) {
var form = this.jQ;
var replace = $(replace);
replace.hide().insertAfter(form.last()).slideDown(function() {
replace.trigger('TAZboxChange');
});
form.slideUp(function() {
form.remove();
});
this.jQ = replace;
this.domEl = replace[0];
};
})();
var ensureObjType = function(obj, Type) {
var obj = obj,
Type = Type;
(typeof Type == 'undefined') && (Type = Object);
if (typeof obj == 'undefined') obj = new Type;
else if (!(obj instanceof Type)) {
alert('filOtaz_de.ajaxify:ensureObjType cries: ' +
obj + ' is not of demanded type ' + (new Type) + '.'
);
return undefined;
}
return obj;
};
})();
// debug
// todo bring together with login case above
filOtaz_de.ajaxify(formSel, {
// param removed for testing
// url: formUrl + param, // where to fetch from. overrides form's action
url: formUrl, // where to fetch from. overrides form's action
pick: 'fragment#form >*', // what to take from response | mar: this was hardcoded in old frontend. should be changed.
needSSL: false,
tabindex: 1,
focus: 0,
none: null
});
$(formSel).trigger('TAZloadAsync');
// loadForm ADDED BY MAR
}