/*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see .
*/
var sankoreLang = {
display: "Закрыть",
edit: "Изменить",
add: "Добавить",
enter_data: "Введите вопрос:",
enter_result: "Введите ответ:",
ok: "Ок",
cancel: "Отмена",
wgt_name: "Черный/желтый",
reload: "Обновить",
slate: "узор",
pad: "планшет",
none: "нет",
help: "Помощь",
help_content: "Пример текста помощи ...",
theme: "Тема"
};
function init(){
//variables
var toggleFlag = false; // detects toggling in toggle button
var endFlag = false; // ending of toggling in toggle button
var addToggleStart = false; // detects toggling in add button
var addToggleEnd = false; // ending of toggling in add button
var shadowOver = false;
var mode = false;
var popupFlag = false
var flagForSelect = false;
var dragElement = null; //the element that must be dragging
var lang = ""; //locale language
var resizeFlag = true;
var coords = {
left:0,
top:0
}
var resizeObj = {
y:false,
x:false,
width:0,
height:0
}
var opacityChanged = false;
$("#wgt_display").text(sankoreLang.display);
$("#wgt_edit").text(sankoreLang.edit);
$("#wgt_add").text(sankoreLang.add);
$("#wgt_name").text(sankoreLang.wgt_name);
$("#wgt_reload").text(sankoreLang.reload);
$("#wgt_help").text(sankoreLang.help);
$("#help").html(sankoreLang.help_content);
$("#style_select option[value='1']").text(sankoreLang.slate);
$("#style_select option[value='2']").text(sankoreLang.pad);
$("#style_select option[value='3']").text(sankoreLang.none);
var tmpl = $("div.inline label").html();
$("div.inline label").html(sankoreLang.theme + tmpl)
if(window.sankore){
if(sankore.preference("blackYellowData","")){
var importArray = jQuery.parseJSON(sankore.preference("blackYellowData",""));
for(var i in importArray){
var tmpReadyTask = $("
");
var exprContainer = $("
" + importArray[i].data1 + "
").appendTo(tmpReadyTask);
var resContainer = $("
"+ importArray[i].data2 + "
").appendTo(tmpReadyTask);
tmpReadyTask.width(importArray[i].width)
.height(importArray[i].height)
.css("position","absolute")
.css("top",importArray[i].top)
.css("left",importArray[i].left);
tmpReadyTask.appendTo("#data");
}
}
$(document).disableTextSelect();
}
/* ------------- BUTTONS -------------*/
if(window.sankore){
if(sankore.preference("by_style","")){
changeStyle(sankore.preference("by_style",""));
$("#style_select").val(sankore.preference("by_style",""));
} else
changeStyle("3")
} else
changeStyle("3")
$("#wgt_display, #wgt_edit").click(function(event){
if(this.id == "wgt_display"){
if(!$(this).hasClass("selected")){
$(this).addClass("selected");
$("#wgt_edit").removeClass("selected");
$("#parameters").css("display","none");
var tmpwh = $(window).height();
var tmpww = $(window).width();
resizeFlag = true;
window.resizeTo(tmpww, tmpwh - 44)
$("#data").css("padding-bottom","");
$("#leftDiv").css("border-top-left-radius","7px");
$("#rightDiv").css("border-top-right-radius","7px");
$(this).css("display", "none");
$("#wgt_edit").css("display", "block");
mode = false;
$(".leftDiv, .rightDiv").animate({
"opacity":"1"
},"fast",function(){
if(opacityChanged){
if($(".editContainer").size() != 0){
$(".editContainer").each(function(index, domElem){
var tmpReadyTask = $(domElem).find(".readyTask");
tmpReadyTask.width($(domElem).width())
.height($(domElem).height())
.css("position","absolute")
.css("top",$(domElem).position().top - 40)
.css("left",$(domElem).position().left)
.find(".taskContainer").removeAttr("contenteditable");
$(domElem).remove();
tmpReadyTask.appendTo("#data");
});
}
opacityChanged = false;
}
});
$(document).disableTextSelect();
}
} else {
if(!$(this).hasClass("selected")){
$(this).addClass("selected");
$("#wgt_display").removeClass("selected");
$("#parameters").css("display","block");
tmpwh = $(window).height();
tmpww = $(window).width();
resizeFlag = true;
window.resizeTo(tmpww, tmpwh + 44)
$("#data").css("padding-bottom","42px");
$("#leftDiv").css("border-top-left-radius","0px");
$("#rightDiv").css("border-top-right-radius","0px");
$(this).css("display", "none");
$("#wgt_display").css("display", "block");
mode = true;
$(document).enableTextSelect();
$(".leftDiv, .rightDiv").animate({
"opacity":"0.4"
},"fast",function(){
if(!opacityChanged){
if($(".readyTask").size() != 0){
var tmp_arr = [];
$(".readyTask").each(function(){
tmp_arr.push($(this));
})
orderItems(tmp_arr);
$(".readyTask").each(function(index, domElem){
var editContent = $("
").width($(domElem).width() + 10).height($(domElem) + 10).appendTo("#data");
var closeItem = $("
").appendTo(editContent);
editContent.css("top", $(domElem).position().top).css("left", $(domElem).position().left);
$(domElem).css("position","static")
.width("100%")
.height("100%")
.find(".taskContainer").attr("contenteditable", "true");
$(domElem).appendTo(editContent);
});
}
opacityChanged = true;
}
});
}
}
});
$("#wgt_help").click(function(){
var tmp = $(this);
if($(this).hasClass("open")){
$(this).removeClass("help_pad").removeClass("help_wood")
$("#help").slideUp("100", function(){
tmp.removeClass("open");
$("#data").show();
($("#wgt_edit").hasClass("selected"))?$("#parameters").show():'';
});
} else {
($("#style_select").val() == 1)?$(this).removeClass("help_pad").addClass("help_wood"):$(this).removeClass("help_wood").addClass("help_pad");
$("#data, #parameters").hide();
$("#help").slideDown("100", function(){
tmp.addClass("open");
});
}
});
$("#wgt_reload").click(function(){
reloadItems();
});
$("#wgt_add").click(function(){
if($("#wgt_help").hasClass("open")){
$("#help").slideUp("100", function(){
$("#wgt_help").removeClass("open");
$("#data").show();
});
}
shadowDiv.show();
shadowOver = true;
popupBack.show("slow");
$(document).disableTextSelect();
});
$("#style_select option[value='1']").text(sankoreLang.slate);
$("#style_select option[value='2']").text(sankoreLang.pad);
$("#style_select").change(function (event){
changeStyle($(this).find("option:selected").val());
})
/* -------------- END OF WORK WITH BUTTONS ---------------*/
//basic divs
var leftDiv = $("
").appendTo("#data");
var rightDiv = $("
").appendTo("#data");
//divs for adding a new item
var shadowDiv = $("
").appendTo("html");
var popupBack = $("