/*
* 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: "Display",
edit: "Edit",
add: "Add",
enter_data: "Enter data:",
enter_result: "Enter result:",
ok: "Ok",
cancel: "Cancel",
wgt_name: "Contrast",
reload: "Reload",
slate: "Wood",
pad: "Pad",
none: "None",
help: "Help",
help_content: "This is an example of help content ..."
};
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 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);
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(sankore.preference("by_style","")){
changeStyle(sankore.preference("by_style",""));
$(".style_select").val(sankore.preference("by_style",""));
} 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");
$(".style_select").css("display","none");
$(this).css("display", "none");
$("#wgt_add").css("display", "none");
$("#wgt_edit").css("display", "block");
mode = false;
$(".leftDiv, .rightDiv").animate({
"opacity":"1"
},"slow",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)
.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");
$(".style_select").css("display","block");
$(this).css("display", "none");
$("#wgt_add").css("display", "block");
$("#wgt_display").css("display", "block");
mode = true;
$(document).enableTextSelect();
$(".leftDiv, .rightDiv").animate({
"opacity":"0.4"
},"slow",function(){
if(!opacityChanged){
if($(".readyTask").size() != 0){
$(".readyTask").each(function(index, domElem){
var editContent = $("
").width($(domElem).width() + 10).height($(domElem) + 10).appendTo("#data");
var closeItem = $("
").appendTo(editContent);
var rightResize = $("
").appendTo(editContent);
var bottomResize = $("
").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")){
$("#help").slideUp("100", function(){
tmp.removeClass("open");
$("#data").show();
});
} else {
$("#data").hide();
$("#help").slideDown("100", function(){
tmp.addClass("open");
});
}
});
$("#wgt_reload").click(function(){
window.location.reload();
});
$("#wgt_add").click(function(){
shadowDiv.show("fast", function(){
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("#data");
var popupBack = $("