dreamjob/app/webroot/js/dreamjob.js

235 lines
9.4 KiB
JavaScript
Executable File

/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
var global_load = null;
!function($) {
$(function() {
$body = $("body");
$(document).on({
ajaxStart: function() {
$body.addClass("loading");
},
ajaxStop: function() {
$body.removeClass("loading");
}
});
$(window).bind('popstate', function(evt) {
if (evt.originalEvent.state !== null) {
load(location.href, {'history': false}, false);
}
});
$("#popup").modal({'remote': false, 'show': false});
$("#popup").on('show.bs.modal', function(e) {
$.ajax({url: $(e.relatedTarget).attr("href"), success: function(data) {
$("#popup .modal-title").html($(e.relatedTarget).attr("title"));
$("#popup .modal-body").html($("#container div.box", data).html());
}, error: function(data) {
}});
});
function stopLoad(e) {
if (!e)
e = window.event;
if (e) {
if (e.preventDefault)
e.preventDefault();
if (e.stopPropagation) {
e.stopPropagation();
} else {
e.cancelBubble = true;
}
}
}
function event(where) {
$("#alert .alert").alert();
$(where + ' textarea').wysihtml5();
$(where + ' select').each(function() {
$(this).select2({allowClear: true});
});
$(where + ' .dropdown-toggle').dropdown();
$(where + " a").tooltip();
$(where + " a").not('[href*="mailto:"]').each(function(that) {
if ($(this).attr("rel") !== "external" && $(this).attr("ref") !== "eventOff" && !$(this).parents('ul').hasClass("wysihtml5-toolbar") && !$(this).hasClass(".select2-choice"))
$(this).click(function(e) {
stopLoad(e);
load($(this).attr('href'), {}, ($(this).attr('rel') == "tab"));
return false;
});
});
$(where + " form").submit(function(e) {
if ($(this).attr('enctype') != 'multipart/form-data') {
stopLoad(e);
if ($(this).hasClass('tableForm')) {
$("tbody tr.new", $(this)).remove();
i=0;
$("tbody tr", $(this)).each(function() {
$(":input[name]", this).each(function() {
str = $(this).attr("name").replace(/data\[(.*?)\]\[.*?\]\[(.+)\]/g, 'data[$1][' + i + '][$2]');
$(this).attr("name", str);
});
i++;
});
}
$(":input[ name *= '_wysihtml5_mod' ]", this).remove();
//stopLoad(e);
if ($(this).attr("back"))
back = window.location.href;
else
back = null;
load($(this).attr("action"), {data: $(this).serialize(), type: $(this).attr("method"), back: back}, ($(this).attr('rel') == "tab"));
return false;
}
});
$(where + " form[ enctype *= 'multipart/form-data' ]").each(function(evt) {
if (!$('#fileUpload').length)
$('body').append('<iframe id="fileUpload" name="fileUpload" style="display:none" />');
$(this).attr('target', 'fileUpload');
$(":input[ name *= '_wysihtml5_mod' ]", this).remove();
$(this).submit(function() {
stopLoad(evt);
frame = $('#fileUpload').load(function() {
setContent($('#fileUpload').contents().find('html').html());
$('#fileUpload').unbind('load');
setTimeout(function() {
$('#fileUpload').html('');
}, 10);
});
});
});
$(where + " form.tableForm tbody").each(function(evt) {
var that = this;
var newRow = $(".new", this).html();
$(that).on('change',function(e) {
stopLoad(e);
$("tr", that).each(function(evt) {
see = true;
$(":input:not([ type = 'hidden' ] ):not(.select2-focusser):not(.select2-input)", this).each(function() {
if (see) {
see = $(this).val() == '';
}
});
if (see && $(this).attr("data") == "set") {
$(this).attr("data", "");
$(this).remove();
}
if (!see && $(this).attr("data") != "set") {
$(this).attr("data", "set");
$("tr", that).removeClass("new");
console.log(newRow);
$(that).append("<tr class=\"new\">" + newRow + "</tr>");
$("form.tableForm tbody tr.new select").each(function() {
$(this).select2({allowClear: true});
});
evet();
}
});
});
function evet() {
$("tr:not(.new)", that).each(function() {
var that2 = this;
$(".btn-del", this).unbind("click").click(function(evt) {
$(that2).remove();
});
});
}
evet();
});
$(where + ' img').each(function() {
$(this).attr('src', $(this).attr('src') + '?' + (new Date()).getTime());
});
}
function setContent(data, back, tab, backignore) {
title = data.split('<title>')[1].split('</title>')[0];
if (title.trim().length > 0) {
document.title = title.trim();
}
alert = data.split('<!-- alert -->')[1].split('<!-- /alert -->')[0];
$('#alert').removeClass('old');
if (alert.trim().length > 0) {
$('#alert').html(alert);
} else if (!backignore) {
$('#alert').addClass('old');
}
if (back) {
load(back, {'backignore': true}, tab);
} else if (tab) {
navbar = data.split('<!-- tab -->')[1].split('<!-- /tab -->')[0];
$('#tab').html(navbar);
event("#tab");
} else {
navbar = data.split('<!-- navbar -->')[1].split('<!-- /navbar -->')[0];
$('#navbar').html(navbar);
event("#navbar");
container = data.split('<!-- container -->')[1].split('<!-- /container -->')[0];
$('#container').html(container);
event("#container");
barright = data.split('<!-- barright -->')[1].split('<!-- /barright -->')[0];
$('#barright').html(barright);
event("#barright");
barleft = data.split('<!-- barleft -->')[1].split('<!-- /barleft -->')[0];
$('#barleft').html(barleft);
event("#barleft");
}
if (!back) {
navbar = data.split('<!-- extraScript -->')[1].split('<!-- /extraScript -->')[0];
eval($(navbar).html());
}
}
function setContentError(data, back, tab) {
alert = "<div class=\"alert alert-danger\">" + data.statusText +
"<button type=\"button\" class=\"close\" data-dismiss=\"alert\">&times;</button>"
+ "</div>";
$('#alert').removeClass('old');
$('#alert').html(alert);
event("#alert");
$('#container').html(data.responseText);
event("#container");
}
function load(pageurl, conf, tab) {
data = {};
typemethode = "GET";
back = false;
backignore = false;
history = true;
if (conf['data'])
data = conf['data'];
if (conf['type'])
typemethode = conf['type'];
if (conf['back'] && conf['back'].indexOf("logout") == -1 && conf['back'].indexOf("login") == -1)
back = conf['back'];
if (conf['backignore'])
backignore = conf['backignore'];
if (conf['history'])
history = conf['history'];
$.ajax({url: pageurl, cache: false, data: data, type: typemethode, success: function(data) {
setContent(data, back, tab, backignore);
}, error: function(data) {
setContentError(data, back, tab);
}});
if (history && pageurl != window.location) {
window.history.pushState({path: pageurl}, '', pageurl);
}
}
;
event("");
global_load = load;
});
}(window.jQuery);