(function () {
'use strict';
var sinClass = function (options) {
this.init(options);
};
sinClass.VERSION = '1.0.0';
sinClass.DEFAULTS = {
showDebug : false,
useIso: false,
api_filter: '',
api_searchmode: 0,
api_account: 0,
api_traegergruppe: 0,
api_traegergesellschaft: 0,
api_dachverband: 0,
sinURL : 'https://freiplatzmeldungen.de/api/',
sectionButtons: '.sin-section-button',
noticeTemplate: '\
\
\
'
};
sinClass.prototype = {
constructor: sinClass,
init: function (options) {
this.options = jQuery.extend({}, sinClass.DEFAULTS, options);
var that = this;
var charset = document.charset;
console.log(charset);
if(charset.toLowerCase() != 'utf-8') {
this.options.useIso = true;
}
},
register: function(options) {
var that = this;
that.debug("ich starte nun SIN");
jQuery("body").on("SinContentLoaded", function() {
that.debug("Es wurde ein neuer Content geladen");
});
this.initTrigger();
this.jsonData( that.options.sinURL+"start.html", {
api_filter: this.options.api_filter,
api_dachverband: this.options.api_dachverband ,
api_account: this.options.api_account,
api_searchmode: this.options.api_searchmode,
api_traegergruppe:this.options.api_traegergruppe,
api_traegergesellschaft: this.options.api_traegergesellschaft
});
this.initSectionButtons(this.options.sectionButtons);
this.initOpenClose(".button_open_close");
this.initFilterButton(".sin-filter-button");
this.initFilterSelect(".sin-filter-select");
this.initSearchButton(".sin-search-button");
this.initPagination(".sin-pagination a");
this.initEmailLink(".email-link");
this.initForm("#SinForm");
// this.post_data(this.options.sinURL+"mail.html",{ hannes: true, token: 'b071aef9c4772119d14ff2ff87a9a450' });
// hier kommen die initialfunktionen rein die wir aufrufen
},
debug: function(s) {
if(this.options.showDebug) {
console.log(s);
}
},
initTrigger: function() {
var that=this;
/* alles zum resizen */
var d = 250, t = null, e = null, h, r = false;
h = function () {
r = false;
jQuery(window).trigger('resizeend', e);
};
jQuery(window).on('resize', function (event) {
e = event || e;
clearTimeout(t);
if (!r) {
jQuery(window).trigger('resizestart', e);
r = true;
}
t = setTimeout(h, d);
});
that.initView();
jQuery(window).on('resizeend', function(event){
that.initView();
});
/* resizen ende */
},
initView: function() {
this.debug("pruefe die Breite des Bereiches");
var sinClass="sin-lg";
var size = jQuery('#freiplatzmeldungen').outerWidth();
if( size <= 969 ) sinClass="sin-md";
if( size <= 769 ) sinClass="sin-sm";
if( size <= 469 ) sinClass="sin-xs" ;
jQuery('#freiplatzmeldungen').attr("data-view",sinClass);
},
initOpenClose: function(el) {
var that = this;
jQuery("body").on("click",el, function(e) {
that.debug(this);
e.preventDefault();
e.stopPropagation();
var el = jQuery(this);
jQuery(el).blur();
if(jQuery(el).hasClass("open")) {
jQuery(el).closest(".sin-offer-box").find(".slide-content").slideUp(500,function() {
jQuery(el).removeClass("open");
});
} else {
jQuery(el).closest(".sin-offer-box").find(".slide-content").slideDown(500,function() {
jQuery(el).addClass("open");
});
}
});
},
sendFilter: function(el) {
var that = this;
var data = { section: jQuery(".sin-section-button[data-status='active']").data('section') };
data['api_account']=that.options.api_account;
data['api_dachverband']=that.options.api_dachverband;
data['api_searchmode']=that.options.api_searchmode;
data['api_traegergesellschaft']=that.options.api_traegergesellschaft;
data['api_traegergruppe']=that.options.api_traegergruppe;
data['api_filter']=that.options.api_filter;
if(jQuery(".sin-filter-button-filter .sin-filter-button").data("status")=='active') {
data['sinfilter']='active';
jQuery(".sin-filter-select").each(function() {
var sel = this;
data[jQuery(sel).attr("name")] = jQuery(sel).val();
});
if(jQuery("input.sin-stichwort").val()) {
data['stichwort'] = encodeURIComponent(jQuery("input.sin-stichwort").val());
}
}
that.jsonData(that.options.sinURL+"filter.html",data);
},
initForm: function(el) {
var that = this;
jQuery("body").on("submit",el, function(e) {
e.preventDefault();
e.stopPropagation();
var data = jQuery(el).serialize();
that.jsonData(that.options.sinURL+"mail.html",data);
return false;
});
},
initEmailLink: function(el) {
var that = this;
jQuery("body").on("click",el, function(e) {
e.preventDefault();
e.stopPropagation();
that.debug(this);
jQuery("#sin_modal").remove();
var data = {
member : jQuery(this).data("memberid"),
offer: jQuery(this).data("offerid")
};
that.jsonData(that.options.sinURL+"mail.html",data);
});
},
initFilterSelect: function(el) {
var that = this;
jQuery("body").on("change",el, function(e) {
e.preventDefault();
e.stopPropagation();
that.debug(this);
// wir müssen erst den Landkreis resetten wenn wir das Bundesland wechseln
if(jQuery(this).attr("name")=='bundesland') {
that.debug("landkreis wird resettet");
jQuery("select[name='landkreis'] option:selected").attr("selected",false);
}
that.sendFilter(el);
});
},
initPagination: function(el) {
var that = this;
jQuery("body").on("click",el, function(e) {
e.preventDefault();
e.stopPropagation();
that.debug(this);
var data = { section: Number(jQuery(".sin-section-button[data-status='active']").data('section')) };
data['api_account']=that.options.api_account;
data['api_dachverband']=that.options.api_dachverband;
data['api_searchmode']=that.options.api_searchmode;
data['api_traegergesellschaft']=that.options.api_traegergesellschaft;
data['api_traegergruppe']=that.options.api_traegergruppe;
data['api_filter']=that.options.api_filter;
data['page'] = jQuery(this).data("page");
if(jQuery(".sin-filter-button-filter .sin-filter-button").data("status")=='active') {
data['sinfilter']='active';
jQuery(".sin-filter-select").each(function() {
var sel = this;
data[jQuery(sel).attr("name")] = jQuery(sel).val();
});
if(jQuery("input.sin-stichwort").val()) {
data['stichwort'] = encodeURIComponent(jQuery("input.sin-stichwort").val());
}
}
that.debug(data);
that.jsonData(that.options.sinURL+"filter.html",data);
});
},
initSearchButton: function(el) {
var that = this;
jQuery("body").on("click",el, function(e) {
e.preventDefault();
e.stopPropagation();
that.debug(this);
that.sendFilter();
});
},
initFilterButton: function(el) {
var that = this;
jQuery("body").on("click",el, function(e) {
e.preventDefault();
e.stopPropagation();
that.debug(this);
jQuery(this).attr("data-status","active");
jQuery(this).addClass("active");
that.jsonData(that.options.sinURL+"filter.html",{
sinfilter: 'active' ,
api_dachverband: that.options.api_dachverband ,
api_traegergruppe: that.options.api_traegergruppe,
api_account: that.options.api_account,
api_searchmode: that.options.api_searchmode,
api_traegergesellschaft: that.options.api_traegergesellschaft,
api_filter: that.options.api_filter,
section: jQuery(".sin-section-button[data-status='active']").data('section')
});
});
},
initSectionButtons: function(el) {
var that = this;
jQuery("body").on("click",el, function(e) {
e.preventDefault();
e.stopPropagation();
that.debug(this);
jQuery("body " + el ).attr("data-status","inactive");
jQuery("body " + el ).removeClass("active");
jQuery(".sin-filter-button-filter").removeClass("sin-hide");
jQuery(this).attr("data-status","active");
jQuery(this).addClass("active");
if(jQuery("a.sin-filter-button").data("status")=="active") {
jQuery("select.sin-need-reset").each(function() {
jQuery(this).find("option:selected").attr("selected",false);
});
that.debug("gehe über den Filter");
that.sendFilter();
}else {
that.jsonData(that.options.sinURL+"section.html",{
api_dachverband: that.options.api_dachverband ,
api_traegergruppe: that.options.api_traegergruppe,
api_filter: that.options.api_filter,
api_account: that.options.api_account,
api_searchmode: that.options.api_searchmode,
api_traegergesellschaft: that.options.api_traegergesellschaft,
section: jQuery(this).data('section')
});
}
});
},
openModalNotice: function (el, selector, titel,content) {
jQuery("#sin_modal").remove();
jQuery("body").append(this.options.noticeTemplate);
if(selector) jQuery("#sin_modal .modal-content").addClass(selector);
jQuery("#sin_modal .modal-title").html(titel);
jQuery("#sin_modal .modal-body").html(content);
jQuery("#sin_modal").modal("show");
},
jsonData: function(url,data) {
var that = this;
if(data !== typeof "undefied"){
jQuery.extend(data, { useIso: that.options.useIso },data);
}
that.debug("hole url: " + url);
that.debug(data);
that.debug("ende");
jQuery.ajax({
url: url,
type: 'GET',
data: data,
crossDomain: true,
dataType: 'jsonp',
contentType: 'application/json; charset=utf-8',
jsonp: 'callback',
jsonpCallback: 'meincallback',
success: function(result) {
that.debug(result);
if( result.script ) {
eval(result.script);
}
jQuery("body").trigger("SinContentLoaded");
},
error: function(result,responseText,a) {
that.debug(responseText);
that.debug(a);
that.debug(result);
that.debug('Failed!');
},
});
},
_jsonData: function(url) {
jQuery.getJSON(url, function(result){
console.log("hallo");
jQuery.each(result, function(i, field){
jQuery("div").append(field + " ");
});
});
},
test: function(url) {
var that = this;
jQuery.ajax ({
type: "POST",
url: url,
dataType: 'jsonp',
jsonp: 'callback',
/*jsonpCallback: function(data,e) {
console.log(data);
console.log(e);
},*/
jsonpCallback: 'meincallback',
//json object to sent to the authentication url
data: {"u": "userid", "p": "pass"},
success: function (data) {
//successful authentication here
that.debug(data);
jQuery('body').append(data.city);
},
error: function(XHR, textStatus, errorThrown) {
that.debug("error: " + textStatus);
that.debug("error: " + errorThrown);
}
});
},
post_data: function (url, data) {
jQuery.ajax({
type: 'POST',
url: url,
data: data,
crossDomain: true,
showNoSuggestionNotice: true,
dataType: 'json',
// xhrFields: {withCredentials: true},
success: function(data,responseText,jqXHR) {
if( jqXHR.status == 204 ) {
this.debug('sorry, here is nothing to do for me. (Token problem?)')
return false;
}
if( jqXHR.status == 404 ) {
this.debug('sorry, here is nothing to show you.')
return false;
}
if( jqXHR.status == 403 ) {
this.debug('sorry, this is no place for you.')
return false;
}
//debug(data);
if( data.script ) {
eval(data.script);
}
if( data.endscript ) {
eval(data.endscript);
}
jQuery("body").trigger('contentChanged');
},
error: function() {
this.debug('something is wrong....anything buggy?');
},
complete: function() {
}
});
},
};
jQuery.cssSin = function(options) {
jQuery.sin = new sinClass(options);
jQuery.sin.register();
return jQuery.sin;
};
})(jQuery);
function myFunc(data) {
console.log(data);
}
jQuery(document).ready(function () {
jQuery.cssSin({
showDebug : true
});
});
\
\
\