//= FRIENDS AJAX CORE HELPER FUNCTIONS
//= Loader Anzeigen
//
//== Ajax Load Message:
// Anzeige einer Box mit Loader und Message
ajaxLoadMessage = function(target, message){
message = message || '<%= HTML_LOAD_DEFAULT.to_s %>'
message_target = $("#"+target);
loader_id = "loader-"+randomString()
html_string = "
" + message +"
";
message_target.children().fadeTo(500, 0.3)
message_target.append(html_string);
loader = $("#"+loader_id)
// Abemessung berechnen
loader_width = loader.width()
loader_height = loader.height()
message_target.css({position: "relative", "min-height": loader_height+"px"})
target_width = message_target.width()
target_height = message_target.height()
if(message_target.height() > window.innerHeight){
loader.css({left: ((target_width/2)-(loader_width/2))+"px", top: (loader_height)+"px", position: "absolute"})
}else{
loader.css({left: ((target_width/2)-(loader_width/2))+"px", top: ((target_height/2)-(loader_height/2))+"px", position: "absolute"})
}
loader.show();
}
//== TinyLoadMessage
// Anzeige Loader mit Message ohne Box
tinyAjaxLoadMessage = function(target, message){
message = message || '<%= HTML_TINY_LOAD_DEFAULT.to_s %>'
message_target = $("#"+target);
message_target.children().hide();
message_target.append(" " + message);
}
progressAjaxLoadMessage = function(target, message){
message = message || '<%= HTML_TINY_LOAD_DEFAULT.to_s %>'
message_target = $("#"+target);
message_target.children().hide();
message_target.append("" + message +"
");
}
//== Cursor Loader
// Blendet den Mauszeiger aus und
// ... coming soon
// Auslesen der Optionen für den Link (Ziel, Loadmessage etc.) aus der CSS-Klasse
linkOptionsFromClassName = function(item){
link_options = new Hash();
link_options.set('target_div', '<%= AJAX_OVERLAY_CONTAINER_NAME %>');
link_options.set('load_message', false);
link_options.set('hide_load_message', false);
link_options.set('tiny_loader', false);
link_options.set('submit_data', ($(item).attr('<%= AJAX_SUBMIT_DATA_TRIGGER %>') || ''))
link_options.set('callback', '')
link_options.set('append', false)
link_options.set('push_progress_trigger', false)
a = $(item.className.split(" "));
a.each(function(i){
if(a[i].match("<%= AJAX_HIDE_LOAD_MESSAGE_SELECTOR %>")){
link_options.set('hide_load_message', true);
}else{
if(a[i].match("<%= AJAX_UPDATE_DIV_SELECTOR %>")){
link_options.set('target_div', a[i].split("<%= AJAX_UPDATE_DIV_SELECTOR %>")[1]);
}
else if(a[i].match("<%= AJAX_LOAD_MESSAGE_TRIGGER %>")){
link_options.set('load_message', true);
}
else if(a[i].match("<%= AJAX_TINY_LOAD_TRIGGER %>")){
link_options.set('tiny_loader', true);
link_options.set('load_message', false);
}
}
if(a[i].match("<%= AJAX_PUSH_PROGRESS_TRIGGER %>")){
link_options.set('push_progress_trigger', true)
}
})
if(link_options['load_message'] == true){
link_options.set('load_message_text', $(item).attr('<%= HTML_DATA_LOADING %>'));
}
if($(item).attr('<%= HTML_DATA_CALLBACK %>')){
link_options.set('callback', $(item).attr('<%= HTML_DATA_CALLBACK %>'))
}
if($(item).attr('<%= HTML_DATA_APPEND %>')){
link_options.set('append', true)
}
return link_options
}
// Element ausblenden - verwendung als Callback nach löschen etc...
hideItem = function(id){
$("#"+id).fadeOut(300);
}
// Element löschen - verwendung als Callback nach löschen etc...
removeItem = function(id){
$("#"+id).remove();
}
// Flash Notify Tools
flashNoticeDisplay = function(text,mode){
mode = mode || 'ok' ;
text = text.replace(/\'/g, "\"")
html_notice = "" + text + "
";
$('#<%= FLASH_AREA_DIV %>').html(html_notice);
$('#<%= FLASH_AREA_DIV %>').children().slideDown(500);
window.setTimeout('flashFadeOut()', 5000);
}
flashFadeOut = function(){
$('#<%= FLASH_AREA_DIV %>').children().fadeOut(500);
}
loadAjaxFlashNotice = function(){
$.getJSON('/ajax/json_flash_data', function(data){
$(data).each(function(i) {
flashNoticeDisplay($(this)[1], $(this)[0]);
});
});
}
//// Adds full host name etc. to URL
//jsFullUrl = function(url){
// proto = '<%#= request.protocol %>'
// host = '<%#= request.host %>'
// port = '<%#= request.port %>'
//
// target_url = proto + host
// if(port != ''){
// target_url = target_url + ":"+port
// }
// return target_url + url
//}
// JavaScript Makeover of Rails 2.3 'remote_function' helper
remote_function = function(path_url, div, load_message, submit, load_text){
if(typeof submit != 'undefined' && submit != '') {
submit = ("#"+submit + " *").replace("##", "#")
request_data = $(submit).serialize();
console.log(request_data);
request_type = "post"
}else{
request_data = 'authenticity_token=' + AUTH_TOKEN
request_type = "get"
}
div = div || '<%= AJAX_OVERLAY_CONTAINER_NAME %>'
$.ajax({
success:function(request){
$('#'+div).html(request);
hideLoading();
initAllAjaxTools();
loadAjaxFlashNotice();
},
beforeSend: function(data){
if(load_message != false){
if(load_message == true){
ajaxLoadMessage(div);
}else if(load_message == 'tiny'){
tinyAjaxLoadMessage(div, load_text);
}else if(load_message == 'progress'){
progressAjaxLoadMessage(div, load_text);
}
else{
showLoading();
}
}else{
}
},
url: path_url,
data: request_data,
type: request_type
});
}
parseJsonDate = function(jsonDate) {
date_parts = /(\d{4})-(\d{2})-(\d{2}).(\d{2}):(\d{2})/.exec(jsonDate)
realDate = new Date(parseInt(date_parts[1]), parseInt(date_parts[2], 10)-1, parseInt(date_parts[3], 10), parseInt(date_parts[4], 10), parseInt(date_parts[5], 10));
return realDate;
};