/**
* @author Kirill Burkhanov
*/
var originalSerializeArray = $.fn.serializeArray;
$.fn.extend({
serializeArray: function () {
var brokenSerialization = originalSerializeArray.apply(this);
var checkboxValues = $(this).find('input[type=checkbox]').map(function () {
return { 'name': this.name, 'value': (this.checked) ? this.value : 0 };
}).get();
var checkboxKeys = $.map(checkboxValues, function (element) { return element.name; });
var withoutCheckboxes = $.grep(brokenSerialization, function (element) {
return $.inArray(element.name, checkboxKeys) == -1;
});
return $.merge(withoutCheckboxes, checkboxValues);
}
});
define = function(data, func) {
var controller = data[0].split('/');
if(typeof window[controller[0]] == 'undefined') {
window[controller[0]] = new Object();
}
if(typeof controller[1] != 'undefined') {
window[controller[0]][controller[1]] = func;
if(typeof data[1] != 'undefined') {
$(document).on(data[2], data[1], function(event) {
try {
self = {}
self.e = $(this);
self.data = [data[1], data[2]];
self.controller = controller;
self.event = event;
self.get = function(type) {
switch(type[0]) {
case ":":
var result = window['Data'][type.substring(1)]();
returnBack = {
0: result,
query: function() {
return Data.query(result);
},
callback: function() {
contr = result['callback'].split('/');
window[contr[0]][contr[1]]();
}
}
break;
}
return returnBack;
};
if(typeof window[self.controller[0]]['index'] != 'undefined') {
allow = window[self.controller[0]]['index']();
if(allow) {
window[self.controller[0]][self.controller[1]]();
}
} else {
window[self.controller[0]][self.controller[1]]();
}
event.preventDefault();
return self;
} catch(e) {
console.log(e);
alert('Ошибка! Пожалуйста обратитесь в Тех Поддержку \n Линия:' + e.line + ' Ошибка: ' + e.message);
return false;
}
});
}
}
}
define(['Data/url'], function() {
var query_string = {};
var query = window.location.search.substring(1);
var vars = query.split("&");
for (i = 0; i < vars.length; i++) {
var pair = vars[i].split("=");
if (typeof query_string[pair[0]] === "undefined") {
query_string[pair[0]] = decodeURIComponent(pair[1]);
} else if (typeof query_string[pair[0]] === "string") {
var arr = [ query_string[pair[0]], pair[1] ];
query_string[pair[0]] = arr;
} else {
query_string[pair[0]].push(decodeURIComponent(pair[1]));
}
}
return query_string;
});
// Data-[....] + inputs
define(['Data/any'], function() {
e = self.e;
a = Data.form();
b = Data.attr();
$.extend(a, b);
return a;
});
// inputs
define(['Data/form'], function() {
e = self.e;
var attrs = new Object();
url = self.e.serialize().split('&') || [];
$.each(url, function(i, v) {
v = v.split('=');
attrs[v[0]] = v[1];
});
console.log(attrs);
return attrs;
});
// data-[..]
define(['Data/attr'], function(element) {
if(typeof element == 'undefined') element = self.e[0];
attributes = element.attributes;
var attrs = new Object();
for (var i = 0; i < attributes.length; i++) {
name = attributes[i].name.toLowerCase();
val = attributes[i].value;
if(name.substring(0, 4) == 'data') {
name = name.substring(5);
attrs[name] = val;
}
};
return attrs;
});
// to query
define(['Data/query'], function(obj) {
var data = '',
i = 0;
for(var index in obj) {
if(index != 'callback') {
if(i == 0) {
data += index+'='+encodeURIComponent(obj[index]);
} else {
data += '&'+index+'='+encodeURIComponent(obj[index]);
}
i++;
}
}
return data;
});
var requreQueue = [];
define(['Data/setRequire'], function(file, path) {
if(typeof path == 'undefined') {
path = 'require';
}
if(path == 'editor') {
href = window.location.href.split('/')[3]
if(href != 'content') {
return false;
}
}
requreQueue.push('/view/javascript/'+path+'/'+file+'.js');
});
define(['Data/require'], function(i) {
$.getScript(requreQueue[i], function() {
name = requreQueue[i].split('/')[4].replace(/\.js/g, '');
// if(typeof window['Onload'][name] != 'undefined') {
// window['Onload'][name]();
// }
if(typeof requreQueue[i+1] != 'undefined') {
Data.require(i+1);
}
});
});
// STATIC GO GO GO ----->>>
var YandexID
if(typeof yaCounter22792237 == 'undefined') {
YandexID = {
reachGoal: function() {
return true;
}
}
} else {
YandexID = yaCounter22792237;
}
define(['Spinner/set'], function(name, element) {
var opts = {
lines: 11, // The number of lines to draw
length: 0, // The length of each line
width: 16, // The line thickness
radius: 60, // The radius of the inner circle
corners: 1, // Corner roundness (0..1)
rotate: 14, // The rotation offset
direction: 1, // 1: clockwise, -1: counterclockwise
color: '#999', // #rgb or #rrggbb or array of colors
speed: 1.2, // Rounds per second
trail: 88, // Afterglow percentage
shadow: false, // Whether to render a shadow
hwaccel: false, // Whether to use hardware acceleration
className: 'spinner', // The CSS class to assign to the spinner
zIndex: 2e9, // The z-index (defaults to 2000000000)
top: 'auto', // Top position relative to parent in px
left: 'auto' // Left position relative to parent in px
};
spinner = new Spinner(opts).spin(element[0]);
return true;
});
define(['Spinner/remove'], function(name, element) {
});
/**
* Pre-submit check
* @return {boolean} is validate
*/
var formTimeOut;
define(['Form/index'], function() {
var result = true;
var issues = [];
self.e.find(':input').not('input[type=submit]').each(function(i) {
data = Data.attr(this);
value = $(this).val().trim();
type = data.type;
len = data.len;
name = data.name;
inpType = $(this).attr('type');
if(inpType == 'checkbox') {
if(!$(this).is(':checked')) value = ''; else value = 'on';
}
if(data.required == 'true') {
if(value == '') {
issues.push([this, name, 'required']);
result = false;
}
}
if(value.length < len) {
issues.push([this, name, 'length', len]);
result = false;
}
if(typeof data.type != 'undefined' && value != '') {
if(type == 'check') value = this;
if(Validation[type](value) == false) {
issues.push([this, name, 'validation', type]);
result = false;
}
}
if(typeof data.equal != 'undefined') {
equal = data.equal;
equalElement = self.e.find(':input[name='+equal+']');
if(value != equalElement.val().trim()) {
issues.push([this, name, 'equal', type]);
result = false;
}
}
});
self.e.find('._message').find('ul').html('');
self.e.find('.input').removeClass('error');
if(issues.length > 0) self.e.find('._message, .message').show();
$.each(issues, function(i, v) {
text = v[1];
switch(v[2]) {
case 'required': text += ' - Обязательно поле'; break;
case 'length': text += ' - Не менее '+v[3]+' символов'; break;
case 'equal': text = 'Пароли не совпадают'; break;
case 'validation':
switch(v[3]) {
case 'pass': text += ' - должен сдержать не менее одной цифры'; break;
case 'email': text += ' - введена некорректно'; break;
default:
text += ' - введен некорректно';
}
break;
}
// console.log($(v[0]));
// $(v[0]).parent().addClass('error');
// self.e.find('._message ul').append('
'+text+'');
Form.showMessage(text, 'error');
});
if(result) {
self.e.css('position', 'relative').prepend('').find('.dimmer').hide();
formTimeOut = setTimeout(function() {
self.e.find('.dimmer').fadeIn(200);
Spinner.set('formSpinner', self.e.find('.dimmer .spinner'));
}, 500);
}
return result;
});
define(['Form/clean'], function(e) {
e.find(':input').not('input[type=submit]').val('');
});
define(['Form/showMessage'], function(text, type) {
clearTimeout(formTimeOut);
self.e.find('.dimmer').fadeOut(200, function() {
$(this).remove();
});
self.e.find('._message').show().find('.message')
.removeClass('error')
.removeClass('success')
.removeClass('warning')
.addClass(type).find('ul').html(''+text+'');
if(type == 'success') {
self.e.find('._message .header, ._message .name').html('Запрос успешно совершен');
console.log(self.get(':any')[0])
if(self.get(':any')[0]['clean'] != "false") {
Form.clean(self.e);
}
} else {
self.e.find('._message .header, ._message .name').html('Ошибочка вышла');
}
});
define(['Form/hideMessage'], function(text, type) {
self.e.find('._message').hide().find('ul').html('');
if(type == 'success') Form.clean(self.e);
});
/**
* Validation for Form/index
* @return {[type]} [description]
*/
define(['Validation/digits'], function(text) {
var re = /^[0-9]{1,32}$/;
return re.test(text);
});
define(['Validation/phone'], function(text) {
var re = /^[0-9\+]{12}$/;
return re.test(text);
});
define(['Validation/email'], function(text) {
var re = /@/;
return re.test(text);
});
define(['Validation/check'], function(e) {
return $(e).is(':checked');
});
define(['Validation/pass'], function(text) {
var re = /^(?=.*[0-9])[a-zA-Z0-9!@#$%^&*]{1,16}$/;
return re.test(text);
});
define(['Validation/domain'], function(text) {
// var re = /^(.*){1,32}$/;
return true; //re.test(text);
});
define(['Validation/input'], function(text) {
return true;
});
define(['Validation/textarea'], function(text) {
return true;
});
/**
* Login callback
*/
define(['Form/login', '._login', 'submit'], function() {
var get = self.get(':any')[0];
$.ajax({
type: 'POST',
url: '/scr/login',
data: get,
dataType: 'json',
success: function(data) {
console.log(data)
if (data.type == 'fail') {
Form.showMessage(data.text, 'error');
} else if(data.type == 'success') {
Form.hideMessage();
YandexID.reachGoal('login');
ga('send', 'event', 'button', 'click', 'enter');
window.location.reload();
}
}
});
});
define(['Form/registration', '._registration', 'submit'], function() {
var get = self.get(':any')[0];
$.ajax({
url: '/scr/registration',
type: 'post',
data: get,
success: function (data) {
console.log(data)
data = eval('(' + data + ')');
if(data.type == 'success') {
Form.showMessage('Вы успешно зарегестрированы', 'success');
YandexID.reachGoal('reg');
ga('send', 'event', 'button', 'click', 'reg');
window.location.pathname = '/dashboard/';
} else {
Form.showMessage(data.text, 'error');
}
}
});
event.preventDefault();
});
define(['Form/sendQuestion', '._sendQuestion', 'submit'], function() {
var get = self.get(':any')[0];
Form.showMessage(data.text, 'success');
$.ajax({
url: '/scr/sendQuestion',
type: 'post',
data: get,
success: function (data) {
}
});
});
define(['Form/recovery', '._recovery', 'submit'], function() {
var get = self.get(':any');
if(get[0].action == 'instructions') {
query = get.query() + '&type=instructions';
} else {
query = get.query() + '&type=change';
setInterval(function() {
val = parseInt($('#alert-timer').html());
$('#alert-timer').html(val-1);
if(val == 1) {
window.location.pathname = '/dashboard/';
}
}, 1000);
}
$.ajax({
url: '/scr/recovery',
type: 'post',
data: query,
success: function (data) {
data = eval('(' + data + ')');
if(data.type == 'success') {
YandexID.reachGoal('recovery');
Form.showMessage(data.text, 'success');
} else {
Form.showMessage(data.text, 'error');
}
}
});
});
define(['Form/post', '._post', 'submit'], function() {
var get = self.get(':any');
delete get[0]['clean'];
$.ajax({
url: '/scr/post',
type: 'post',
data: get.query(),
success: function (data) {
Form.showMessage('Данные успешно отправлены', 'success');
if(typeof get[0]['callback'] != 'undefined') {
if(get[0]['callback'] == 'refresh') {
window.location.reload();
} else {
window[get[0]['callback']]();
}
}
}
});
});
/**
* Modals
*/
define(['Modal/hideEditor', '._modal-hide-editor', 'click'], function() {
Editor.cancelPlugin();
Modal.hide();
});
define(['Modal/hideOnClick', '._modal-hide', 'click'], function() {
Modal.hide();
});
define(['Modal/hide'], function() {
$('.drop-element.hover').removeClass('hover');
$('.modal').addClass('end');
$("#modal .dimmer").animate({
opacity: 0,
}, 250, function() {
$('#modal').remove();
});
$('body').css('overflow', 'auto');
});
define(['Modal/show'], function(data) {
if(typeof data.size == 'undefined') {
data.size = 'normal';
}
if(typeof data.position == 'undefined') {
data.position = '';
}
if(typeof data.color == 'undefined') {
data.color = '';
}
data.imageColor = '';
if(data.color == 'grey') {
data.imageColor = '.opacity';
}
$.ajax({
url: '/modal/'+data.scr,
type: 'post',
data: data,
success: function (html) {
switch(data.size) {
case "normal": w = 600; break;
case "big": w = 900; break;
}
html = '';
$('body').prepend(html).css('overflow', 'hidden');
if(data.position == '') {
winWidth= $(window).width();
winMargin = (winWidth - w) / 2;
if(winWidth < 800) {
w = winWidth - 150;
winMargin = 60;
}
$('.modal').css({
'left': winMargin+'px',
'width': w
})
}
$('#modal').show();
$("#modal .dimmer").animate({
opacity: 1,
}, 250);
$('.modal').addClass('scale');
if(typeof data.callback != 'undefined') {
data.callback();
}
}
});
});
define(['Modal/showOnClick', '._modal', 'click'], function() {
data = self.get(':any')[0];
Modal.show(data);
});
define(['Dimmer/show'], function(data) {
html = '';
$('body').prepend(html);
});
define(['Form/createPage', '._createPage', 'submit'], function() {
var get = self.get(':any');
$.ajax({
type: 'POST',
url: '/scr/createPage',
data: get.query(),
dataType: 'json',
success: function(data) {
if(data.type == 'success') {
window.location.href = '/content/' + data.site;
} else {
Form.showMessage(data.text, 'error');
}
}
});
self.event.preventDefault();
});
function decodeURIComponentX( str ) {
if(str == null) {
return '';
}
var out = '', arr, i = 0, l, x;
arr = str.split(/(%(?:D0|D1)%.{2})/);
for ( l = arr.length; i < l; i++ ) {
try {
x = decodeURIComponent( arr[i] );
} catch (e) {
x = arr[i];
}
out += x;
}
return out
}
// require
Data.setRequire('onload');
Data.setRequire('text');
Data.setRequire('witgets', 'editor');
Data.setRequire('templates', 'editor');
Data.setRequire('move', 'editor');
Data.setRequire('editor', 'editor');
Data.setRequire('dashboard');
Data.setRequire('help');
Data.setRequire('account');
Data.setRequire('commerce');
Data.setRequire('settings');
// Data.setRequire('referals');
// Data.setRequire('landing');
Data.require(0);