var time2;
// App
// Глобальный объект приложения
//
var app = {
init:function()
{
if (typeof options.my_profile != 'undefined')
{
update.init();
}
},
getAskForm:function(user_url)
{
if (options.mobiledetect === "false")
{
var url = "/"+user_url+"/ask/?action=get-form";
$.colorbox({width:"550px", maxHeight:"50%", href: url,title: szTextForm});
}
else
{
window.location.href = "/"+user_url;
}
},
getLangForm:function()
{
if (options.mobiledetect === "false")
{
var url = "/"+app_name+"/lang?action=get-form";
$.colorbox({width:"450px", href: url, title: szLangForm});
}
else
{
window.location.href = "/"+app_name+"/lang";
}
},
getGiftsForm:function(user_url)
{
if (options.mobiledetect === "false")
{
var url = "/"+user_url+"/gifts?action=get-form";
$.colorbox({width:"604px", href: url, title: szGifts});
}
else
{
window.location.href = "/"+user_url+"/gifts";
}
},
getFollowersForm:function(user_url)
{
if (options.mobiledetect === "false")
{
var url = "/"+user_url+"/followers?action=get-form";
$.colorbox({width:"604px", href: url, title: szFollowers});
}
else
{
window.location.href = "/"+user_url+"/followers";
}
},
getFollowingForm:function(user_url)
{
if (options.mobiledetect === "false")
{
var url = "/"+user_url+"/following?action=get-form";
$.colorbox({width:"604px", href: url, title: szFollowing});
}
else
{
window.location.href = "/"+user_url+"/following";
}
},
getRatingForm:function(user_url)
{
if (options.mobiledetect === "false")
{
var url = "/"+user_url+"/rating?action=get-form";
$.colorbox({width:"500px", href: url, title: szRating});
}
else
{
window.location.href = "/"+user_url+"/rating";
}
}
}
// Settings
//
//
var settings = {
getCover:function()
{
$.ajax({
type: "POST",
url: "/account/cover",
data: "action=get",
success : function(text){
$('img.upload-background').attr("src",text);
},
error : function()
{
$('img.upload-background').attr("src","/img/noface_big.png");
}
});
},
getBg:function()
{
$.ajax({
type: "POST",
url: "/account/bg",
data: "action=get",
success : function(text){
$('img.upload-bg').attr("src",text);
},
error : function()
{
$('img.upload-bg').attr("src","/img/bg.png");
}
});
},
getPhoto:function()
{
$.ajax({
type: "GET",
url: "/account/photo",
data: "action=get-photo",
success : function(text){
$('img.upload-photo').attr("src",text);
},
error : function()
{
$('img.upload-photo').attr("src","/img/no_photo_100.jpg");
}
});
}
}
// Ribbon
// Объект для управления уведомлениями в левом боковом меню
//
var ribbon = {
//
// Создает и возвращает html строку пункта меню
//
create:function(js_class,color,href,img,id,count,text)
{
return "<li class=\""+js_class+"\"><a class=\""+color+"\" href=\""+href+"\"><i class=\""+img+"\"></i><div class=\"ribbon-msg\"><span class=\"count\" id=\""+id+"\">"+count+"</span>"+text+"</div></a></li>";
},
//
// Добавляет пункт меню в боковую панель
//
insert:function(ribbon)
{
$("ul.ribbon-menu").append(ribbon);
},
//
// Обновляет в определенном пункте меню значение
//
update:function(ribbon_id,count)
{
if (this.exists(ribbon_id))
{
$("ul.ribbon-menu").children("li").children("a").children("div.ribbon-msg").children("span#"+ribbon_id).text(count);
return true;
}
else
{
return false;
}
},
//
// Удаляет определенный пункт пункт в боковом меню
//
remove:function(ribbon_id)
{
if (ribbon.exists(ribbon_id))
{
$("span#"+ribbon_id).parents("div.ribbon-msg").parents("a").parents("li").remove();
}
},
//
// Проверят на существование пункта меню
//
exists:function(ribbon_id)
{
if ($("ul.ribbon-menu").children("li").children("a").children("div.ribbon-msg").children("span#"+ribbon_id).length > 0)
{
return true;
}
else
{
return false;
}
}
}
var offers = {
old_count:0,
init:function()
{
},
run:function()
{
},
delete:function()
{
},
add:function(offer_id)
{
$.ajax({
type: "POST",
url: "/account/offer",
data: "action=add-me&offer_id="+offer_id,
timeout: 2000,
success: function(text)
{
$("form.reply-form[data-id="+offer_id+"]").children("div.loader").html(text);
},
error: function(text){
$("form.reply-form[data-id="+offer_id+"]").children("div.loader").html(str_error);
$("div.ask-data[data-id="+offer_id+"]").children("div.content").children("p.action").children("span.action-bar").fadeIn(50);
}
});
$("div.ask-data[data-id="+offer_id+"]").children("div.content").children("p.action").children("span.action-bar").fadeOut(50);
if ($("form.reply-form[data-id="+offer_id+"]").length > 0)
{
$("form.reply-form[data-id="+offer_id+"]").children("div.loader").html(str_wait);
}
else
{
$("div.ask-data[id="+offer_id+"]").append("<form data-id=\""+offer_id+"\" class=\"reply-form\" style=\"\"><div class=\"loader\" style=\"display: block; border-top: none\">"+str_wait+"</div></form>");
}
// $("form.reply-form[data-id="+ask_id+"]").children("div.img-content").fadeOut(0);
// $("form.reply-form[data-id="+ask_id+"]").children("div.loader").html("<span class=\"spinner\"></span>").css("border-top","none").fadeIn();
// $("form.reply-form[data-id="+ask_id+"]").children("div.footer").fadeOut(20);
}
}
var page = {
print:function(page_id,page_data)
{
$.ajax({
type: "POST",
url: "/account/"+page_data,
data: "page="+page_id,
success: function(html){
$('div.view-more-container').remove();
$('div.questions-content').append(html);
},
error: function(xhr){
$("a.prj-button-full").show();
$("img#view-more-spinner").addClass("hide");
}
});
$("a.prj-button-full").hide();
$("img#view-more-spinner").removeClass("hide");
}
}
var like = {
add:function(user_id,ask_id,token_auth)
{
if (typeof options.my_profile != 'undefined')
{
$.ajax({
type: "POST",
url: "/"+user_id+"/answer/"+ask_id+"/like",
data: "action=add-like&token_auth="+token_auth,
success: function(text){
switch (text){
case 'ERROR_ROBOT_DETECT':
{
if (options.mobiledetect === "false")
{
dialog.show(robot_detect);
}
$("span[data-id="+ask_id+"].liketoolbox").show();
$("span[data-id="+ask_id+"].likeloadbox").hide();
break;
}
case 'ERROR_LOGIN':
{
if (options.mobiledetect === "false")
{
dialog.show(like_promt);
}
$("span[data-id="+ask_id+"].liketoolbox").show();
$("span[data-id="+ask_id+"].likeloadbox").hide();
break;
}
case 'ERROR_TOKEN':
{
if (options.mobiledetect === "false")
{
dialog.show(like_promt);
}
$("span[data-id="+ask_id+"].liketoolbox").show();
$("span[data-id="+ask_id+"].likeloadbox").hide();
break;
}
default:
{
var myvar = text;
var arra = myvar.split('_');
// arra[0] = likecount
// arra[1] = new rating
$("a[data-id="+ask_id+"].likecount").html(arra[0]);
$("span[data-id="+ask_id+"].liketoolbox").show();
$("span[data-id="+ask_id+"].likeloadbox").hide();
break;
}
}
},
error: function(){
$("span[data-id="+ask_id+"].liketoolbox").show();
$("span[data-id="+ask_id+"].likeloadbox").hide();
}
});
$("span[data-id="+ask_id+"].liketoolbox").hide();
$("span[data-id="+ask_id+"].likeloadbox").show();
return false;
}
else
{
if (options.mobiledetect === "false")
{
dialog.show(like_promt);
return false;
}
}
}
}
var dialog = {
show:function(dlg_text)
{
modal = notify.Init();
notify.Show(dlg_text,modal)
}
}
var parser = {
init:function(text)
{
text = $.trim(text);
switch (text)
{
case 'ERROR_ROBOT':
{
return ERROR_ROBOT;
break;
}
case 'ASK_SEND_SUCCESS':
{
return ASK_SEND_SUCCESS;
break;
}
case 'MSG_SEND_SUCCESS':
{
return MSG_SEND_SUCCESS;
break;
}
case 'ERROR_SIGNUP':
{
return ERROR_SIGNUP;
}
default:
{
return ERROR_UNDEFINED;
break;
}
}
}
}
var questions = {
old_count:0,
init:function()
{
},
run:function()
{
},
remove:function(ask_id)
{
if (options.mobiledetect === "false")
{
$.ajax({
type: "POST",
url: "/"+options.my_profile+"/answer/"+ask_id+"/delete",
data: "action=remove-ask",
success: function(text){
$("div.ask-data[data-id="+ask_id+"]").remove();
update.questions_cnt = update.questions_cnt - 1;
hintbox.show(ask_remove_success);
if (update.questions_cnt > 0)
{
ribbon.update("questions-count",update.questions_cnt);
if ($("div.ask-data").length == 0)
{
page.print(0,$("a.prj-button-full").attr("data-page"));
}
}
else
{
ribbon.remove("questions-count");
if ($("div.ask-data").length == 0)
{
$("div.questions-content").append("<div class=\"info-block\">"+szOfferPrompt+"<br><a href=\"/account/offer\">"+szGo+"</a></div>")
}
}
},
error: function(){
}
});
}
else
{
window.location.href = "/"+options.my_profile+"/answer/"+ask_id+"/delete";
}
},
addNewAsk:function()
{
if (!$("a#add-ask").attr("disabled"))
{
$.ajax({
type: "POST",
url: "/account/questions",
data: "action=new",
success: function(html){
if (html > "")
{
if ($("div.questions-content").find("div.adv-data").length > 0)
{
$("div.adv-data").remove();
}
if ($("span#questions-count").length != 0)
{
update.questions_cnt = update.questions_cnt + 1;
$("span#questions-count").text(update.questions_cnt);
}
else
{
update.questions_cnt = update.questions_cnt + 1;
ribbon.insert(ribbon.create("","red","/account/questions","ribbon-notify","questions-count",update.questions_cnt,szHaveAsk));
}
if ($("div.info-block").length > 0)
{
$("div.info-block").remove();
}
$("div.questions-content").prepend(html);
$("a#add-ask").removeAttr("disabled");
questions.old_count++;
}
else
{
$("a#add-ask").remove();
}
},
error: function(){
$("a#add-ask").removeAttr("disabled");
}
});
$("a#add-ask").attr("disabled","disabled");
}
},
reportForm:function(ask_url)
{
if (options.mobiledetect === "false")
{
var url = ask_url+"?action=get-form";
$.colorbox({width: options.cbox_width, maxHeight:"50%", href: url,title: szReport});
}
else
{
window.location.href = ask_url;
}
},
report:function(ask_url,level)
{
$.ajax({
type: "POST",
url: ask_url,
data: $('form#question-report-form').serialize(),
success: function(html){
},
error: function(){
}
});
$.colorbox.close();
},
replyFormCancel:function(ask_id)
{
$("form.reply-form[data-id="+ask_id+"]").fadeOut().remove();
$("div.ask-data[data-id="+ask_id+"]").children("div.content").children("p.action").children("span.action-bar").fadeIn(50);
$("div.ask-data[data-id="+ask_id+"]").children("div.content").children("a.delete-ask").fadeIn(50);
},
replyForm:function(ask_url,ask_id)
{
questions.removeImg(ask_id);
if (options.mobiledetect === "false")
{
$("div.ask-data[data-id="+ask_id+"]").children("div.content").children("a.delete-ask").fadeOut(50);
$("div.ask-data[data-id="+ask_id+"]").children("div.content").children("p.action").children("span.action-bar").fadeOut(50);
$("div.ask-data[id="+ask_id+"]").append("<form data-id=\""+ask_id+"\" class=\"reply-form\" style=\"\"><div class=\"footer\"><textarea maxlength=\"300\" name=\"answer\" class=\"reply\"></textarea><button id=\"send-answer\" class=\"prj-button prj-button-blue btn-send\" onclick=\"questions.reply(\'" + ask_id + "\',\'" + options.auth_token + "\');return false;\">"+szActionReply+"</button><a data-id=\""+ask_id+"\" class=\"reply-cancel\">"+szActionCancel+"</a><div class=\"right \" style=\"display: inline-block;\"><span data-id=\""+ask_id+"\" style=\"color: #404040; width: 20px; height: 15px; display: block\" class=\"btn-send add-img prj-button-white\"><i></i></span></div></div><div class=\"img-content\"></div><div class=\"loader\"></div></form>");
$("form.reply-form[data-id="+ask_id+"]").children("div.footer").children("textarea[name=answer]").focus();
$("textarea").autosize();
$('span.add-img[data-id='+ask_id+']').upload({
ask_id: $(this).attr("data-id"),
name: 'userfile',
method: 'post',
enctype: 'multipart/form-data',
action: '/'+options.my_profile+'/answer/'+ask_id+"/reply",
onComplete: function(text) {
if (text == 'success')
{
$("form.reply-form[data-id="+ask_id+"]").children("div.loader").fadeOut(10);
$("form.reply-form[data-id="+ask_id+"]").children("div.img-content").html("").append("<img src=\"/temp/"+ask_id+"_small.jpg?x="+Math.random()+"\"><a onclick=\"questions.removeImg(\'"+ask_id+"\')\" >"+szActionRemove+"</a>").fadeIn(50);
}
else
{
$("form.reply-form[data-id="+ask_id+"]").children("div.loader").css("border-top","1px solid #eee").text(error_file_upload).fadeIn(50, function(){
setTimeout(function(){$("form.reply-form[data-id="+ask_id+"]").children("div.loader").fadeOut(150);}, 2000);
});
}
},
onSubmit: function(){
$("form.reply-form[data-id="+ask_id+"]").children("div.loader").html("<span class=\"spinner\"></span>").css("border-top","1px solid #eee").fadeIn();
$("form.reply-form[data-id="+ask_id+"]").children("div.img-content").fadeOut(0);
}
});
}
else
{
window.location.href = ask_url;
}
// var url = ask_url+"/?action=get-form";
// $.colorbox({width: options.cbox_width, maxHeight:"50%", href: url,title: szReplyForm});
},
removeImg:function(ask_id)
{
$.ajax({
type: "POST",
url: "/"+options.my_profile+"/answer/"+ask_id+"/reply",
data: "action=remove-img",
success: function(html){
}
});
$("form.reply-form[data-id="+ask_id+"]").children("div.img-content").html("").fadeOut(0);
},
reply:function(ask_id, token_auth)
{
var answer = $("form.reply-form[data-id="+ask_id+"]").children("div.footer").children("textarea[name=answer]").val();
var s = $.trim(answer);
if (s.length > 0)
{
$.ajax({
type: "POST",
url: "/"+options.my_profile + "/answer/" + ask_id + "/reply",
data: "action=js-send&answer=" + answer + "&token_auth=" + token_auth,
timeout: 2000,
success: function(text){
switch (text){
case "REPLY_SEND_SUCCESS": {
update.questions_cnt = update.questions_cnt - 1;
$("div#"+ask_id).children("div.content").remove();
if (options.mobiledetect === "false")
{
hintbox.show(ask_reply_success);
}
$("div.ask-data[data-id=" + ask_id + "]").fadeOut(function(){
$("div.ask-data[data-id=" + ask_id + "]").remove();
if (update.questions_cnt == 0)
{
ribbon.remove("questions-count");
if ($("div.ask-data").length == 0)
{
$("div.questions-content").append("<div class=\"info-block\">"+szOfferPrompt+"<br><a href=\"/account/offer\">"+szGo+"</a></div>")
}
}
else
{
ribbon.update("questions-count",update.questions_cnt);
if ($("div.ask-data").length == 0)
{
page.print(0,$("a.prj-button-full").attr("data-page"));
}
}
});
break;
}
case "": {
}
default:{
break;
}
}
},
error: function(text){
$("form.reply-form[data-id="+ask_id+"]").children("div.footer").fadeIn(50);
if ($("form.reply-form[data-id="+ask_id+"]").children("div.img-content").html().length > 0)
{
$("form.reply-form[data-id="+ask_id+"]").children("div.img-content").fadeIn(20);
}
$("form.reply-form[data-id="+ask_id+"]").children("div.loader").css("border-top","1px solid #eee").text("ERROR!");
}
});
$("form.reply-form[data-id="+ask_id+"]").children("div.img-content").fadeOut(0);
$("form.reply-form[data-id="+ask_id+"]").children("div.loader").html("<span class=\"spinner\"></span>").css("border-top","none").fadeIn();
$("form.reply-form[data-id="+ask_id+"]").children("div.footer").fadeOut(20);
}
else
{
answer = $("form.reply-form[data-id="+ask_id+"]").children("div.footer").children("textarea[name=answer]").focus();
}
}
}
var wall = {
time_ms: 7000,
hTimer: 0,
answers_cnt: 0,
init:function(count)
{
if (options.mobiledetect === "false")
{
if (wall.hTimer) clearTimeout(wall.hTimer);
wall.run();
}
},
more:function(user_id)
{
$.ajax({
type: "GET",
url: "/"+user_id+"/ask",
data: "action=main-form",
success: function(html){
$("div.profile-box").html(html);
},
error: function(){
$(":button.more-ask-btn").removeAttr("disabled");
$(":button.more-ask-btn").removeClass("uiButtonDisabled");
}
});
$(":button.more-ask-btn").attr("disabled","disabled");
$(":button.more-ask-btn").addClass("uiButtonDisabled");
},
reportForm:function(user_url)
{
if (options.mobiledetect === "false")
{
var url = user_url + "?action=get-form";
$.colorbox({width: options.cbox_width, maxHeight:"50%", href: url,title: szReport});
}
else
{
window.location.href = user_url;
}
},
report:function(user_url)
{
$.ajax({
type: "POST",
url: user_url,
data: $('form#user-report-form').serialize(),
success: function(html){
},
error: function(){
}
});
$.colorbox.close();
},
remove:function(ask_url,ask_id)
{
if (options.mobiledetect === "false")
{
$.ajax({
type: "POST",
url: ask_url,
data: "action=remove&ask_id="+ask_id,
success: function(html){
$("div[data-id="+ask_id+"].ask-data").remove();
hintbox.show(answer_remove_success);
},
error: function(){
$("div[data-id="+ask_id+"].ask-data").show();
}
});
$("div[data-id="+ask_id+"].ask-data").hide();
}
else
{
window.location.href = ask_url;
}
},
send:function(from_wall)
{
var ask_data = $("textarea[name=ask_data]").val();
var to_id = $("input[name=to_id]").val();
var token = $("input[name=token]").val();
var mode = $("select.ask-mode option:selected").val();
var s = $.trim(ask_data);
if (s.length > 0)
{
$.ajax({
type: "POST",
url: "/"+to_id+"/ask",
data: "action=js-send&ask_data="+ask_data+"&show="+mode+"&token="+token,
success: function(text){
if (from_wall)
{
$("div.profile-box").html("<div class=\"profile-form-prompt\"><span>"+parser.init(text)+"</span><button onclick=\"wall.more(\'"+to_id+"\'); return false;\" class=\"yet-btn prj-button prj-button-blue\">"+szActionYet+"</button></div>");
}
else
{
if (options.mobiledetect === "false")
{
dialog.show(parser.init(text));
}
$.colorbox.close();
}
},
error: function(){
if (from_wall)
{
$(":button.send-ask").removeAttr("disabled");
$(":button.send-ask").removeClass("uiButtonDisabled");
$("a#send-mode.select-box-item").removeAttr("disabled");
$("textarea[name=ask_data]").removeAttr("disabled");
}
else
{
$(":button.send-ask").removeAttr("disabled");
$(":button.send-ask").removeClass("uiButtonDisabled");
$("a#send-mode.select-box-item").removeAttr("disabled");
}
}
});
if (from_wall)
{
$(":button.send-ask").attr("disabled","disabled");
$(":button.send-ask").addClass("uiButtonDisabled");
$("textarea[name=ask_data]").attr("disabled","disabled");
}
else
{
$(":button.send-ask").attr("disabled","disabled");
$(":button.send-ask").addClass("uiButtonDisabled");
}
}
else
{
$("textarea[name=ask_data]").focus();
}
},
run:function()
{
$.ajax({
type: "POST",
url: "/"+options.profile,
data: "action=getAnswersCount",
success: function(text){
if (text === "error")
{
}
else
{
var myvar = text;
var arr = myvar.split('_');
if (parseInt(text) > wall.answers_cnt)
{
wall.update(parseInt(text));
}
}
},
complete: function()
{
// console.log(update.time_ms)
// Добавляем 7 секунд для следуещего обновления
wall.time_ms = wall.time_ms + 7000;
wall.hTimer = setTimeout(function()
{
wall.init();
},
update.time_ms);
}
});
},
update: function (count)
{
if ($("div.info-block").length != 0)
{
$("div.info-block").html('<span>'+szHaveNewAnswers+' <a href="/'+options.profile+'">'+szReloadPage+'</a></span>');
}
else
{
$("<div>")
.hide()
.addClass("info-block")
.html('<span>'+szHaveNewAnswers+' <a href="/'+options.profile+'">'+szReloadPage+'</a></span>')
.fadeIn("slow",function(){
$(this).prependTo("div#answers");
});
}
}
}
var update = {
time_ms:7000,
hTimer:0,
questions_cnt: 0,
init:function()
{
if ($("span#questions-count").length != 0)
{
update.questions_cnt = parseInt($("span#questions-count").text());
}
if (update.hTimer) clearTimeout(update.hTimer);
update.run();
},
run:function()
{
$.ajax({
url: "/account/update",
success: function(text){
if (text === "error")
{
}
else
{
var myvar = text;
var arr = myvar.split('_');
update.AskCnt(arr[0]);
update.MsgCnt(arr[1]);
update.NotifyCnt(arr[2]);
}
},
complete: function()
{
// console.log(update.time_ms);
// Добавляем 7 секунд для следуещего обновления
update.time_ms = update.time_ms + 7000;
this.hTimer = setTimeout(function()
{
update.init();
},
update.time_ms);
}
});
},
AskCnt:function(count)
{
// ribbon.insert(ribbon.create("","red","/support/","ribbon-img-msg","support-count","100","Ribbon"));
if (count > 0)
{
if (!ribbon.update("questions-count",count))
{
ribbon.insert(ribbon.create("","red","/account/questions","ribbon-ask","questions-count",count,szHaveAsk));
}
}
else
{
ribbon.remove("questions-count");
}
if (typeof options.page_id != 'undefined')
{
if (options.page_id === 'questions')
{
if (update.questions_cnt < count)
{
if ($("div.info-block").length != 0)
{
$("div.info-block").html('<span>'+szHaveNewQuestions+' <a href="/account/questions">'+szReloadPage+'</a></span>');
}
else
{
$("<div>")
.hide()
.addClass("info-block")
.html('<span>'+szHaveNewQuestions+' <a href="/account/questions">'+szReloadPage+'</a></span>')
.fadeIn("slow",function(){
$(this).prependTo("div.questions-content");
});
}
}
}
}
},
MsgCnt:function(count)
{
if (count > 0)
{
if (!ribbon.update("messages-count",count))
{
ribbon.insert(ribbon.create("","orange","/account/messages","ribbon-msg","messages-count",count,szHaveMsg));
}
}
else
{
ribbon.remove("messages-count");
}
},
NotifyCnt:function(count)
{
if (count > 0)
{
if (!ribbon.update("notify-count",count))
{
ribbon.insert(ribbon.create("","","/account/notify","ribbon-notify","notify-count",count,szHaveLike));
}
}
else
{
ribbon.remove("notify-count");
}
}
}
var fx = {
"initModal":function()
{
$("div#notify-block").remove();
if ($("#modal-dialog").length == 0)
{
modal = notify.Init();
notify.Show(str_wait,modal);
$("<div>").hide().addClass("modal-backdrop").click(function(event){
fx.closeModal(event);
}).appendTo("body");
return $("<div>")
.hide()
.addClass("modal")
.addClass("modal-dlg")
.attr("id","modal-dialog")
.appendTo("body");
}
else
{
return $("#modal-dialog");
}
},
"showModal":function(data,modal)
{
$("div#notify-block").remove();
modal.html("").append(data);
$(".modal-dlg,.modal-backdrop").fadeIn("slow");
},
"closeModal":function(event)
{
$("#modal-dialog,.modal-backdrop").fadeOut("slow", function(){
$(this).remove();
});
}
};
var share = {
vkontakte:function(url,title,img_url){
window.open('http://vk.com/share.php?url='+url+'&title='+title+'&image='+img_url,'vkontakt', 'location=1,status=1,scrollbars=1,resizable=1,width=800,height=400,top=200,left=200');
},
facebook:function(url){
window.open('http://www.facebook.com/sharer.php?u='+url,'sharer', 'width=500,height=400,top=200,left=400');
},
twitter:function(url){
window.open('http://twitter.com/home?status='+url,'twitter', 'location=1,status=1,scrollbars=1,resizable=1,width=800,height=400,top=200,left=200');
}
}
var lightbox = {
show:function(width,height,url)
{
lightbox.create(width,height);
$.ajax({
type: "GET",
url: url,
data: "action=getAnswersCount",
success: function(html){
// $("div.lightbox").children("div.content").css("background","#fff").html(html);
},
complete: function()
{
// $("div.lightbox").children("div.content").css("background","#fff").html(html);
}
});
$("div.lightbox").css("display","block");
},
create:function(width,height)
{
var box = $("<div>")
.addClass("lightbox")
.appendTo("body")
.html("");
return box.append(function(){
return $("<div>")
.addClass("content")
.css("width",width)
.css("height",height)
.css("margin-left",-width/2)
.css("margin-top",-height/2)
})
},
close:function()
{
$("div.lightbox").remove();
}
}
var comments = {
add:function(comment_url,ask_hash)
{
var comment_text = $("form.reply-form[data-id="+ask_hash+"]").children("div.footer").children("div.comment-bar").children("textarea[name=comment]").val();
var comment_hide = 1;
if ($("form.reply-form[data-id="+ask_hash+"]").children("div.footer").children("div.comment-bar").children("label").children("input[type='checkbox']").prop("checked"))
{
var comment_hide = 0;
}
var s = $.trim(comment_text);
if (s.length > 0)
{
$.ajax({
type: "POST",
url: comment_url,
data: "action=add-comment"+"&auth_token="+options.auth_token+"&comment="+comment_text+"&hide="+comment_hide,
success: function(html){
comments.getComment(comment_url, ask_hash, html);
comments.formClose(comment_url, ask_hash);
},
error: function(){
alert('error');
}
});
}
},
remove:function(comment_url,comment_id)
{
$.ajax({
type: "POST",
url: comment_url,
data: "action=remove-comment"+"&comment_id="+comment_id,
success: function(html){
$('div.comment[data-id='+comment_id+']').hide();
},
error: function(){
alert('error');
}
});
},
getComment:function(comment_url,ask_hash,comment_id)
{
$.ajax({
type: "POST",
url: comment_url,
data: "action=get-comment"+"&comment_id="+comment_id,
success: function(html){
$('div.ask-data[data-id='+ask_hash+']>div.content').append(html);
comments.getQuickForm(comment_url,ask_hash);
if (options.mobiledetect === "false")
{
hintbox.show(ask_comment_success);
}
},
error: function(){
alert('error');
}
});
},
hideComments:function(comment_url,ask_hash)
{
$.ajax({
type: "POST",
url: comment_url,
data: "action=hide-comments&have_count=0",
success: function(html){
$('div.ask-data[data-id='+ask_hash+']>div.content>div.get-comments').remove();
$('div.ask-data[data-id='+ask_hash+']>div.content>div.comment').remove();
comments.removeQuickForm(ask_hash);
$('div.ask-data[data-id='+ask_hash+']>div.content').append(html);
},
error: function(){
$('div.ask-data[data-id='+ask_hash+']>div.content>div.get-comments').html(szActionHideComments);
}
});
$('div.ask-data[data-id='+ask_hash+']>div.content>div.get-comments').text(str_wait);
},
getComments:function(comment_url,ask_hash)
{
var text = $('div.ask-data[data-id='+ask_hash+']>div.content>div.get-comments').text();
$.ajax({
type: "POST",
url: comment_url,
data: "action=get-comments&have_count=" + $('div.ask-data[data-id='+ask_hash+']>div.content>div.comment').length,
success: function(html){
$(html).insertAfter('div.ask-data[data-id='+ask_hash+']>div.content>div.get-comments');
$('div.ask-data[data-id='+ask_hash+']>div.content>div.get-comments').text(szActionHideComments);
$('div.ask-data[data-id='+ask_hash+']>div.content>div.get-comments').attr("onclick","comments.hideComments(\'" + comment_url + "\',\'" + ask_hash + "\'); return false;");
},
error: function(){
$('div.ask-data[data-id='+ask_hash+']>div.content>div.get-comments').html(text);
}
});
$('div.ask-data[data-id='+ask_hash+'] > div.content > div.get-comments').text(str_wait);
},
removeQuickForm:function(ask_hash)
{
$('div.ask-data[data-id=' + ask_hash + '] > div.content > div.quick-comment').remove();
},
getQuickForm:function(comment_url, ask_hash)
{
$('div.ask-data[data-id=' + ask_hash + '] > div.content').append("<div class=\"quick-comment\"><input onfocus=\"comments.getForm(\'" + comment_url + "\',\'" + ask_hash + "\'); return false;\" type=\"text\" placeholder=\"" + szComment + "\"></div>");
},
getForm:function(comment_url,ask_hash)
{
if (typeof options.my_profile != 'undefined')
{
$("form.reply-form").fadeOut(function(){
$("div.ask-data[data-id="+$(this).attr("data-id")+"]").children("div.content").children("p.action").children("span.liketoolbox").children("a.btn-comment").fadeIn(0);
}).remove();
$("div.ask-data[data-id="+ask_hash+"]>div.content>div.quick-comment").remove();
$("div.ask-data[data-id="+ask_hash+"]").children("div.content").children("p.action").children("span.liketoolbox").children("a.btn-comment").fadeOut(0);
$("div.ask-data[data-id="+ask_hash+"]").children("div.content").children("p.action").children("span.action-bar").fadeOut(50);
$("div.ask-data[id="+ask_hash+"]").append("<form data-id=\""+ask_hash+"\" class=\"reply-form\" style=\"\"><div class=\"footer\"><div class=\"comment-bar\"><img src=\""+options.my_photo_50+"\"><span class=\"comment-arrow\"></span><textarea maxlength=\"300\" name=\"comment\" class=\"reply\"></textarea><button class=\"prj-button prj-button-blue btn-send\" onclick=\"comments.add(\'"+comment_url+"\',\'"+ask_hash+"\');return false;\">"+szActionComment+"</button><a onclick=\"comments.FormCancel(\'" + comment_url + "\',\'" + ask_hash + "\'); return false;\" class=\"comment-cancel\">"+szActionCancel+"</a><label for=\"unknown\"><input id=\"unknown\" value=\"0\" type=\"checkbox\" data-id=\""+ask_hash+"\" name=\"hide\">"+szCommentAnonymous+"</label></div><div class=\"loader\"></div></div></form>");
$("form.reply-form[data-id="+ask_hash+"]").children("div.footer").children("textarea[name=comment]").focus();
$("textarea").autosize();
$("form.reply-form[data-id="+ask_hash+"]").children("div.footer").children("div.comment-bar").children("textarea[name=comment]").focus();
}
else
{
if ($('div.ask-data[data-id=' + ask_hash + '] > div.content > div.quick-comment').length != 0)
{
$('div.ask-data[data-id=' + ask_hash + '] > div.content > div.quick-comment').html("<span>" + comment_prompt + "</span>");
}
else
{
if (options.mobiledetect === "false")
{
hintbox.show(comment_prompt);
}
}
}
},
FormCancel:function(comment_url, ask_hash)
{
$("form.reply-form[data-id="+ask_hash+"]").fadeOut().remove();
if ($('div.ask-data[data-id=' + ask_hash + '] > div.content > div.comment').length > 0)
{
comments.getQuickForm(comment_url, ask_hash);
}
$("div.ask-data[data-id="+ask_hash+"]").children("div.content").children("p.action").children("span.liketoolbox").children("a.btn-comment").fadeIn(0);
},
formClose:function(comment_url, ask_hash)
{
$("form.reply-form[data-id="+ask_hash+"]").fadeOut().remove();
}
}
var hintbox = {
show:function(text)
{
modal = notify.Init();
notify.Show(text,modal)
}
}
var notify = {
hTimer: 0,
time_ms: 3000,
"Init":function()
{
clearTimeout(this.hTimer);
this.hTimer = setTimeout(function()
{
notify.Close(this.hTimer);
},
this.time_ms);
$("div#notify-block").remove();
return $("<div>")
.hide()
.attr("id","notify-block")
.addClass("notify-block")
.appendTo("body").html("").fadeIn("slow");
},
"Show":function(data,modal)
{
modal.html("").append(data);
},
"Close":function(hTimer)
{
clearTimeout(hTimer);
$("div#notify-block").fadeOut("slow", function(){
$("div#notify-block").remove();
});
}
};
$(document).ready(function(){
app.init();
var lang = (navigator.language ||
navigator.systemLanguage ||
navigator.userLanguage ||
'ru').substr(0, 2).toLowerCase();
$("textarea").autosize();
$("span.video-object").live("click",function(){
var video_id = $(this).attr("video-id");
var video_code = $(this).attr("video-code");
$("p.answer-img[video-id="+video_id+"][video-code="+video_code+"]").html("<iframe src=\"http://www.youtube.com/embed/"+video_code+"?autoplay=1\" width=\"547\" height=\"350\" frameborder=\"0\" allowfullscreen></iframe>");
})
//alert(lang);
if (options.mobiledetect === "false")
{
$("div.lightbox").live("click",function(event){
lightbox.close();
return false;
});
$("div.lightbox > div.content").live("click",function(event){
event.stopPropagation();
});
$("input[type='checkbox']").live("change",function(){
if ($(this).prop("checked"))
{
$("form.reply-form[data-id="+$(this).attr("data-id")+"]").children("div.footer").children("div.comment-bar").children("img").attr("src",options.unknown);
}
else
{
$("form.reply-form[data-id="+$(this).attr("data-id")+"]").children("div.footer").children("div.comment-bar").children("img").attr("src",options.my_photo_50);
}
});
$("a.likecount").live("click", function(){
var id = $(this).attr("data-id");
var user = $(this).parents("div.ask-data").attr("data-user");
var cnt = parseInt($(this).text());
if (cnt != 0)
{
LikesForm(user,id);
}
return false;
});
$("a.follow-btn").live("click", function(){
if (typeof options.my_profile != 'undefined')
{
AddToFriend($(this).attr("data-user"));
}
else
{
if (options.mobiledetect === "false")
{
dialog.show(follow_promt);
}
}
return false;
});
$("a#profile-avatar").click(function(){
var url = $("img.profile-avatar").attr("data-full");
$.colorbox({maxWidth:"80%", maxHeight:"80%", href:url,title: "",photo: true});
return false;
});
$("a.answer-photo").live("click",function(){
var ask_id = $(this).attr("data-id");
var url = $("img[data-id="+ask_id+"].answer-photo").attr("data-full");
$.colorbox({maxWidth:"80%", maxHeight:"80%", href:url, title: "",photo: true});
return false;
});
$("a.album-photo").live("click",function(){
var album_id = $(this).attr("data-id");
var url = $("img[data-id="+album_id+"].album-photo").attr("data-full");
$.colorbox({maxWidth:"80%", maxHeight:"80%", href:url, title: "",photo: true});
return false;
});
$("li.tt_main_menu").live("mouseover", function(){
$("div.tt_main_menu").css("display","block");
var el_width = $("div.tt_main_menu").width();
$("div.tt_main_menu_pointer").css("left",(el_width)-25+"px").css("margin","0px");
return false;
});
$("div.tt_main_menu,li.tt_main_menu").live("mouseout", function(){
$("div.tt_main_menu").css("display","none");
});
$("div.tt_main_menu").live("mouseover", function(){
$("div.tt_main_menu").css("display","block");
});
$(".tt").live("mouseover", function(){
tt_id = $(this).attr("tt-id");
var el_height = $(this).height();
var el_width = $(this).width();
var el_top = $(this).position().top;
var el_left = $(this).position().left;
var el_padding = $(this).css("padding-top");
// alert(parseInt(el_padding));
$("div.tt_container[tt-id="+$(this).attr("tt-id")+"]").css("left",el_left+"px").css("top",(el_top+el_height+(parseInt(el_padding)*2))+"px");
$("div.tt_container[tt-id="+tt_id+"]").css("display","block");
});
$("div.tt_container").live("mouseout", function(){
$("div.tt_container[tt-id="+$(this).attr("tt-id")+"]").css("display","none");
});
$("div.tt_container").live("mouseover", function(){
$("div.tt_container[tt-id="+$(this).attr("tt-id")+"]").css("display","block");
});
$(".tt").live("mouseout", function(){
$("div.tt_container[tt-id="+$(this).attr("tt-id")+"]").css("display","none");
});
$("a.lang").live("click",function(){
LangForm();
return false;
});
}
$('#upload-photo').upload({
name: 'userfile',
method: 'post',
enctype: 'multipart/form-data',
action: '/account/avatar',
onComplete: function(text) {
if (text == 'success')
{
$("div.questions-content").prepend(AdvSuccess(photo_upload_success));
settings.getPhoto();
}
else
{
$("div.questions-content").prepend(AdvError(error_file_upload));
settings.getPhoto();
}
},
onSubmit: function(){
$("div.questions-content").prepend(AdvWait(wait));
$('#upload-photo').attr("src","/img/loading.gif");
}
});
$('#upload-bg').upload({
name: 'userfile',
method: 'post',
enctype: 'multipart/form-data',
action: '/account/bg',
onComplete: function(text) {
if (text == 'success')
{
$("div.questions-content").prepend(AdvSuccess(bg_upload_success));
settings.getBg();
}
else
{
$("div.questions-content").prepend(AdvError(error_file_upload));
settings.getBg();
}
},
onSubmit: function(){
$("div.questions-content").prepend(AdvWait(wait));
$('#upload-bg').attr("src","/img/loading.gif");
}
});
$('#upload-background').upload({
name: 'userfile',
method: 'post',
enctype: 'multipart/form-data',
action: '/account/cover',
onComplete: function(text) {
if (text == 'success')
{
$("div.questions-content").prepend(AdvSuccess(cover_upload_success));
settings.getCover();
}
else
{
$("div.questions-content").prepend(AdvError(error_file_upload));
settings.getCover();
}
},
onSubmit: function(){
$("div.questions-content").prepend(AdvWait(wait));
$('#upload-background').attr("src","/img/loading.gif");
}
});
$("a.album-delete").live("click",function(){
var user_login = $(this).attr("data-user");
var album_id = $(this).attr("data-id");
RemoveAlbum(user_login,album_id);
return false;
});
$("a.ask-share").live("click", function(){
var Width = 600;
var Height = 300;
var windowWidth = window.innerWidth;
var windowHeight = window.innerHeight;
var Top = windowHeight/2-(Height/2);
var Left = windowWidth/2-(Width/2);
var ask_title = $(this).parents("div.content").find("p.ask-text").text();
var ask_url = "http://allsk.ru" + $(this).parents("div.content").find("a.time").next().attr("href");
var Url = "http://vkontakte.ru/share.php?url="+ask_url+"&image=http://allsk.ru/img/in_vk.png?x=1&title="+ask_title;
window.open(Url, "Share",'top='+Top+', left='+Left+', menubar=0, toolbar=0, location=0, directories=0, status=0, scrollbars=0, resizable=0, width='+Width+', height='+Height);
return false;
})
$("span.modal-close").live("click",function(event){
fx.closeModal(event);
});
$("#msg-remove").live("click", function(){
RemoveMsg(this.rel);
return false;
});
$("#msg-outbox-remove").live("click", function(){
RemoveOutBoxMsg($(this).attr("data-id"), this.rel);
return false;
});
$("#rating-btn").live("click", function(){
//AddToFriend(this.rel);
return false;
});
$("textarea[name=answer]").live("paste", function(){
// alert('s');
});
$("textarea.editor").live("keyup mouseout", function(){
var maxchar = 300;
var message = $('textarea.editor');
var warning_window = $('span#word-counter');
var message_lenght = $('textarea.editor').val().length;
warning_window.empty();
warning_window.html(maxchar - message_lenght);
warning_window.show('slow');
event.preventDefault();
});
$("textarea.question-textarea").live("keyup mouseout", function(){
var maxchar = 300;
var message = $('textarea.editor');
var warning_window = $('span#word-counter');
var message_lenght = $('textarea.question-textarea').val().length;
warning_window.empty();
warning_window.html(maxchar - message_lenght);
warning_window.show('slow');
event.preventDefault();
});
function LoginExists(login)
{
$.ajax({
type: "POST",
url: "/action/login_exists",
data: "login="+login,
success: function(text){
if (text === "ok")
{
LoginError();
$("img#user_spinner").hide();
return false;
}
else
{
$("input[name=user_login]").removeClass("not-validated");
$("img#user_spinner").hide();
return true;
}
}
});
$("img#user_spinner").show();
}
$("form.signup_form").submit(function(){
var error = false;
var user_login = $.trim($("input[name=user_page]").val());
var user_passw = $.trim($("input[name=user_password]").val());
var user_confirm = $.trim($("input[name=user_confirm]").val());
var user_captcha = $.trim($("input[name=user_captcha]").val());
if (/^[a-zA-Z0-9_]{5,16}$/.test(user_login))
{
if (/^[a-zA-Z0-9_]{6,12}$/.test(user_passw))
{
if (user_passw === user_confirm)
{
if (/^[0-9]{3,}$/.test(user_captcha))
{
error = true;
}
else
{
$("div.questions-content").prepend(AdvError(error_captcha));
}
}
else
{
$("div.questions-content").prepend(AdvError(error_passw_confirm));
}
}
else
{
$("div.questions-content").prepend(AdvError(error_passw_format));
}
}
else
{
$("div.questions-content").prepend(AdvError(error_login_format));
}
return error;
});
$("form.login_form1").submit(function(){
var user_login = $.trim($("input[name=user_login]").val());
var user_passw = $.trim($("input[name=user_passw]").val());
if (/^[a-zA-Z0-9_]{6,20}$/.test(user_login))
{
if (/^[a-zA-Z0-9_]{6,12}$/.test(user_passw))
{
return true;
}
else
{
PasswError();
return false;
}
}
else
{
LoginError();
return false;
}
});
function LoginError()
{
$("input[name=user_login]").addClass("not-validated");
}
function PasswError()
{
$("input[name=user_passw]").addClass("not-validated");
}
function ConfirmError()
{
$("input[name=user_confirm]").addClass("not-validated");
}
function CaptchaError()
{
$("input[name=user_captcha]").addClass("not-validated");
}
//
// Событие при прокрутке окна
//
$(window).scroll(function()
{
//
// Проверяем устройство пользователя
//
if (options.mobiledetect === "false")
{
if($(this).scrollTop()>350)
{
$("#back_top").fadeIn(30);
$("div.promptbar").css("top","0px");
$("div.promptbar").fadeIn(0);
}
else
{
$("div.promptbar").fadeOut(0);
$("div.topbar").css("top","0px");
$("#back_top").fadeOut(0)
}
}
});
$("#btn-ok").live("click", function(){
fx.closeModal();
});
$("#btn-ok").live("click", function(){
$.colorbox.close();
});
$("a#adv-remove").live("click",function(){
$("div.adv-data").remove();
return false;
});
$("a.reply-cancel").live("click", function(){
questions.replyFormCancel($(this).attr("data-id"));
return false;
});
$("a.more-btn").live("click",function(){
var page_id = $(this).attr("data-id");
var page = $(this).attr("data-page");
var container = $(this).attr("data-container");
MoreBtnClick(page,page_id,container);
return false;
});
$("a#more-btn").live("click",function(){
var page_id = this.rel;
var page = $("a#more-btn").attr("data-page");
PrintPage(page,page_id);
return false;
});
$("a#more-offer-btn").live("click",function(){
var page_id = this.rel;
var page = $(this).attr("data-page");
PrintOfferPage(page,page_id);
return false;
});
$("a#wall-btn").live("click",function(){
var page_id = this.rel;
var user = $("a#wall-btn").attr("data-user");
PrintWall(page_id,user);
return false;
});
$("#users-btn").live("click",function(){
PrintUsers(this.rel);
});
$("#favorites-in-more-btn").live("click",function(){
PrintFavorites(this.rel);
});
$("a#add-ask").live("click", function(){
if (!$("a#add-ask").attr("disabled"))
{
if ($("span#questions-count").length != 0)
{
update.questions_cnt = update.questions_cnt + 1
$("span#questions-count").text(update.questions_cnt);
// update.questions_cnt = parseInt($("span#questions-count").text());
}
if ($("div.info-block").length > 0)
{
$("div.info-block").remove();
}
AddNewAsk();
}
return false;
});
});