You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
810 lines
36 KiB
810 lines
36 KiB
13 years ago
|
var sankoreLang = {
|
||
12 years ago
|
display: "Afficher",
|
||
13 years ago
|
edit: "Modifier",
|
||
|
first_desc: "Les nombres impairs",
|
||
13 years ago
|
second_desc: "Les nombres pairs",
|
||
|
enter: "Saisir le nom de la catégorie ici ...",
|
||
13 years ago
|
add: "Nouveau bloc",
|
||
13 years ago
|
wgt_name: "Catégoriser des images",
|
||
13 years ago
|
reload: "Recharger",
|
||
13 years ago
|
slate: "ardoise",
|
||
|
pad: "tablette",
|
||
13 years ago
|
none: "aucun",
|
||
12 years ago
|
help: "Aide",
|
||
12 years ago
|
help_content: "<p><h2>Catégoriser des images</h2></p>"+
|
||
12 years ago
|
"<p><h3>Classer des images en fonction de la dénomination de la catégorie.</h3></p>"+
|
||
12 years ago
|
|
||
12 years ago
|
"<p>L’activité s’effectue par un glisser-déposer de l’image dans la catégorie correspondante. Une fois que toutes les images sont classées dans la bonne catégorie, la zone se colore en vert.</p>"+
|
||
12 years ago
|
"<p>Le bouton “Recharger” réinitialise les exercices.</p>"+
|
||
12 years ago
|
|
||
12 years ago
|
"<p>Le bouton “Modifier” vous permet :</p>"+
|
||
|
"<ul><li>de choisir le thème de l’interactivité : tablette, ardoise ou aucun (par défaut aucun) ,</li>"+
|
||
12 years ago
|
"<li>de modifier l'exercice.</li></ul>"+
|
||
12 years ago
|
|
||
12 years ago
|
"<p>En mode édition :</p>"+
|
||
|
"<ul><li>modifiez le nom de la catégorie (par exemple “fruits”, “légumes”, “mammifères”...) en cliquant dans le champ de texte,</li>"+
|
||
12 years ago
|
"<li>insérez des images dans la catégorie par glisser-déposer des images à partir de votre bibliothèque,</li>"+
|
||
12 years ago
|
"<li>ajoutez ensuite une catégorie (ou plusieurs) en cliquant sur le signe “+” situé à droite de la catégorie, complétez par son nom et ajoutez des images,</li>"+
|
||
|
"<li>supprimez une image, en cliquant sur la croix située dans son coin supérieur droit,</li>"+
|
||
|
"<li>supprimez une catégorie, en cliquant sur le signe “-” situé à droite de celle-ci,</li>"+
|
||
|
"<li>le bouton “Afficher” vous permet d’utiliser l’activité.</li></ul>",
|
||
12 years ago
|
theme: "Thème"
|
||
13 years ago
|
};
|
||
|
|
||
|
//main function
|
||
|
function start(){
|
||
|
|
||
|
$("#wgt_display").text(sankoreLang.display);
|
||
|
$("#wgt_edit").text(sankoreLang.edit);
|
||
|
$("#wgt_name").text(sankoreLang.wgt_name);
|
||
|
$("#wgt_reload").text(sankoreLang.reload);
|
||
13 years ago
|
$("#wgt_help").text(sankoreLang.help);
|
||
|
$("#help").html(sankoreLang.help_content);
|
||
12 years ago
|
$("#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)
|
||
13 years ago
|
|
||
|
if(window.sankore){
|
||
|
if(sankore.preference("categoriser_images","")){
|
||
|
var data = jQuery.parseJSON(sankore.preference("categoriser_images",""));
|
||
|
importData(data);
|
||
|
} else {
|
||
|
showExample();
|
||
|
}
|
||
|
}
|
||
|
else
|
||
|
showExample();
|
||
|
|
||
|
if (window.widget) {
|
||
|
window.widget.onleave = function(){
|
||
13 years ago
|
exportData();
|
||
13 years ago
|
}
|
||
|
}
|
||
|
|
||
13 years ago
|
$("#wgt_help").click(function(){
|
||
|
var tmp = $(this);
|
||
|
if($(this).hasClass("open")){
|
||
12 years ago
|
$(this).removeClass("help_pad").removeClass("help_wood")
|
||
13 years ago
|
$("#help").slideUp("100", function(){
|
||
|
tmp.removeClass("open");
|
||
|
$("#data").show();
|
||
|
});
|
||
12 years ago
|
} else {
|
||
|
($("#style_select").val() == 1)?$(this).removeClass("help_pad").addClass("help_wood"):$(this).removeClass("help_wood").addClass("help_pad");
|
||
13 years ago
|
$("#data").hide();
|
||
|
$("#help").slideDown("100", function(){
|
||
|
tmp.addClass("open");
|
||
|
});
|
||
|
}
|
||
|
});
|
||
|
|
||
13 years ago
|
$("#wgt_reload").click(function(){
|
||
13 years ago
|
if($("#wgt_display").hasClass("selected")){
|
||
|
$("#wgt_edit").trigger("click");
|
||
|
$("#wgt_display").trigger("click");
|
||
|
} else {
|
||
|
$("#wgt_display").trigger("click");
|
||
|
}
|
||
|
});
|
||
|
|
||
|
$("#wgt_reload, #wgt_display, #wgt_edit").mouseover(function(){
|
||
|
exportData();
|
||
13 years ago
|
});
|
||
|
|
||
12 years ago
|
$("#style_select").change(function (event){
|
||
13 years ago
|
changeStyle($(this).find("option:selected").val());
|
||
|
})
|
||
|
|
||
|
$("#wgt_display, #wgt_edit").click(function(event){
|
||
|
if(this.id == "wgt_display"){
|
||
|
if(!$(this).hasClass("selected")){
|
||
|
$(this).addClass("selected");
|
||
|
$("#wgt_edit").removeClass("selected");
|
||
12 years ago
|
$("#parameters").css("display","none");
|
||
12 years ago
|
if(window.sankore)
|
||
|
sankore.enableDropOnWidget(false);
|
||
|
// $(".add_block").remove();
|
||
13 years ago
|
$(".cont").each(function(){
|
||
|
var container = $(this);
|
||
|
var tmp_i = 0;
|
||
|
var tmp_right = "";
|
||
|
var tmp_array = [];
|
||
|
|
||
12 years ago
|
// container.find(".close_cont").remove();
|
||
13 years ago
|
container.find(".imgs_cont").each(function(){
|
||
|
$(this).find(".del_category").remove();
|
||
|
$(this).find(".add_category").remove();
|
||
|
$(this).removeAttr("ondragenter")
|
||
|
.removeAttr("ondragleave")
|
||
|
.removeAttr("ondragover")
|
||
|
.removeAttr("ondrop")
|
||
|
.find(".cat_desc").attr("disabled","disabled");
|
||
|
var tmp_count = $(this).find(".img_block").size();
|
||
|
$(this).find("input[name='count']").val(tmp_count);
|
||
|
$(this).find(".img_block").each(function(){
|
||
|
$(this).find(".close_img").remove();
|
||
|
tmp_array.push($(this));
|
||
|
$(this).remove();
|
||
|
});
|
||
|
$(this).droppable({
|
||
|
hoverClass: 'dropHere',
|
||
|
drop: function(event, ui) {
|
||
|
if($(ui.draggable).parent().parent().html() == $(this).parent().html()){
|
||
|
var tmp_ui = $(ui.draggable).parent();
|
||
12 years ago
|
$(this).append($(ui.draggable));
|
||
13 years ago
|
checkCorrectness(tmp_ui);
|
||
|
}
|
||
|
}
|
||
|
});
|
||
|
$(this).removeAttr("style");
|
||
|
});
|
||
|
|
||
|
var all_imgs = $("<div class='all_imgs'>").appendTo(container);
|
||
|
|
||
|
tmp_array = shuffle(tmp_array);
|
||
|
for(var i = 0; i<tmp_array.length;i++){
|
||
|
tmp_array[i].draggable({
|
||
|
helper:'clone',
|
||
|
zIndex:100,
|
||
|
appendTo: '#data'
|
||
|
});
|
||
|
tmp_array[i].appendTo(all_imgs);
|
||
|
}
|
||
|
|
||
|
all_imgs.droppable({
|
||
|
hoverClass: 'dropBack',
|
||
|
drop: function(event, ui) {
|
||
|
if($(ui.draggable).parent().parent().html() == $(this).parent().html()){
|
||
|
if(this != $(ui.draggable).parent()[0]){
|
||
|
var tmp_ui = $(ui.draggable).parent();
|
||
|
$(this).append($(ui.draggable));
|
||
|
checkCorrectness(tmp_ui);
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
});
|
||
|
});
|
||
|
$(this).css("display", "none");
|
||
|
$("#wgt_edit").css("display", "block");
|
||
|
}
|
||
|
} else {
|
||
|
if(!$(this).hasClass("selected")){
|
||
|
$(this).addClass("selected");
|
||
|
$("#wgt_display").removeClass("selected");
|
||
12 years ago
|
$("#parameters").css("display","block");
|
||
12 years ago
|
if(window.sankore)
|
||
|
sankore.enableDropOnWidget(true);
|
||
13 years ago
|
$(".cont").each(function(){
|
||
|
var container = $(this);
|
||
|
|
||
12 years ago
|
// $("<div class='close_cont'>").appendTo(container);
|
||
13 years ago
|
container.find(".imgs_cont").each(function(){
|
||
13 years ago
|
$("<button class='del_category'></button>").appendTo($(this));
|
||
|
$("<button class='add_category'></button>").appendTo($(this));
|
||
13 years ago
|
$(this).attr("ondragenter", "return false;")
|
||
13 years ago
|
.attr("ondragleave", "$(this).css(\"background-color\",\"#E6F6FF\"); return false;")
|
||
|
.attr("ondragover", "$(this).css(\"background-color\",\"#C3E9FF\"); return false;")
|
||
|
.attr("ondrop", "$(this).css(\"background-color\",\"#E6F6FF\"); return onDropTarget(this,event);")
|
||
13 years ago
|
.removeClass("red_cont")
|
||
|
.removeClass("green_cont")
|
||
|
.addClass("def_cont")
|
||
|
.droppable("destroy")
|
||
|
.find(".cat_desc").removeAttr("disabled");
|
||
|
var tmp_img_cont = $(this);
|
||
|
var tmp_mask = $(this).find("input[name='mask']").val();
|
||
|
container.find(".img_block").each(function(){
|
||
|
if($(this).find("input").val() == tmp_mask){
|
||
|
$("<div class='close_img'>").appendTo($(this));
|
||
|
$(this).appendTo(tmp_img_cont);
|
||
|
}
|
||
|
});
|
||
|
});
|
||
|
container.find(".all_imgs").remove();
|
||
|
});
|
||
|
|
||
|
|
||
12 years ago
|
// $("<div class='add_block'>" + sankoreLang.add + "</div>").appendTo("#data");
|
||
13 years ago
|
$(this).css("display", "none");
|
||
|
$("#wgt_display").css("display", "block");
|
||
|
}
|
||
|
}
|
||
|
});
|
||
|
|
||
|
//add new block
|
||
12 years ago
|
// $(".add_block").live("click", function(){
|
||
|
// addContainer();
|
||
|
// });
|
||
13 years ago
|
|
||
|
//adding new img
|
||
|
$(".add_img").live("click", function(){
|
||
|
addImgBlock($(this));
|
||
|
});
|
||
|
|
||
|
//deleting a block
|
||
12 years ago
|
// $(".close_cont").live("click",function(){
|
||
|
// $(this).parent().remove();
|
||
|
// refreshBlockNumbers();
|
||
|
// });
|
||
13 years ago
|
|
||
|
//deleting the img block
|
||
|
$(".close_img").live("click", function(){
|
||
|
$(this).parent().remove();
|
||
|
});
|
||
|
|
||
|
//adding new category
|
||
|
$(".add_category").live("click",function(){
|
||
|
addCategory($(this).parent());
|
||
|
});
|
||
|
|
||
|
//deleting the category
|
||
|
$(".del_category").live("click",function(){
|
||
|
if($(this).parent().parent().find(".imgs_cont").size() == 1){
|
||
|
$(this).parent().find(".img_block").remove();
|
||
|
$(this).parent().find(".cat_desc").val(sankoreLang.enter);
|
||
|
} else {
|
||
|
$(this).parent().remove();
|
||
|
}
|
||
|
});
|
||
|
}
|
||
|
|
||
|
//export
|
||
|
function exportData(){
|
||
|
var array_to_export = [];
|
||
13 years ago
|
if($("#wgt_edit").hasClass("selected")){
|
||
13 years ago
|
$(".cont").each(function(){
|
||
|
var cont_obj = new Object();
|
||
12 years ago
|
cont_obj.style = $("#style_select").find("option:selected").val();
|
||
13 years ago
|
cont_obj.mode = "edit";
|
||
|
cont_obj.conts = [];
|
||
|
$(this).find(".imgs_cont").each(function(){
|
||
|
var img_cont = new Object();
|
||
|
img_cont.mask = $(this).find("input[name='mask']").val();
|
||
|
img_cont.count = $(this).find(".img_block").size();
|
||
|
img_cont.text = $(this).find(".cat_desc").val();
|
||
|
img_cont.imgs = [];
|
||
|
$(this).find(".img_block").each(function(){
|
||
|
var img_obj = new Object();
|
||
|
img_obj.value = $(this).find("input").val();
|
||
12 years ago
|
img_obj.link = $(this).find("img").attr("src").replace("../../","");
|
||
13 years ago
|
img_obj.ht = $(this).find("img").height();
|
||
|
img_obj.wd = $(this).find("img").width();
|
||
|
img_cont.imgs.push(img_obj);
|
||
|
});
|
||
|
cont_obj.conts.push(img_cont);
|
||
|
});
|
||
|
array_to_export.push(cont_obj);
|
||
|
});
|
||
|
} else {
|
||
|
$(".cont").each(function(){
|
||
|
var cont_obj = new Object();
|
||
12 years ago
|
cont_obj.style = $("#style_select").find("option:selected").val();
|
||
13 years ago
|
cont_obj.mode = "display";
|
||
|
cont_obj.conts = [];
|
||
|
$(this).find(".imgs_cont").each(function(){
|
||
|
var img_cont = new Object();
|
||
|
img_cont.mask = $(this).find("input[name='mask']").val();
|
||
|
img_cont.count = $(this).find("input[name='count']").val();
|
||
|
img_cont.text = $(this).find(".cat_desc").val();
|
||
|
img_cont.imgs = [];
|
||
|
$(this).find(".img_block").each(function(){
|
||
|
var img_obj = new Object();
|
||
|
img_obj.value = $(this).find("input").val();
|
||
12 years ago
|
img_obj.link = $(this).find("img").attr("src").replace("../../","");
|
||
13 years ago
|
img_obj.ht = $(this).find("img").height();
|
||
|
img_obj.wd = $(this).find("img").width();
|
||
|
img_cont.imgs.push(img_obj);
|
||
|
});
|
||
|
cont_obj.conts.push(img_cont);
|
||
|
});
|
||
|
cont_obj.all_imgs = [];
|
||
|
$(this).find(".all_imgs .img_block").each(function(){
|
||
|
var img = new Object();
|
||
|
img.value = $(this).find("input").val();
|
||
12 years ago
|
img.link = $(this).find("img").attr("src").replace("../../","");
|
||
13 years ago
|
img.ht = $(this).find("img").height();
|
||
|
img.wd = $(this).find("img").width();
|
||
|
cont_obj.all_imgs.push(img);
|
||
|
});
|
||
|
array_to_export.push(cont_obj);
|
||
|
});
|
||
|
}
|
||
|
|
||
|
if($(".cont").size() == 0){
|
||
|
var cont_obj = new Object();
|
||
12 years ago
|
cont_obj.style = $("#style_select").find("option:selected").val();
|
||
13 years ago
|
cont_obj.tmp = "clear";
|
||
|
array_to_export.push(cont_obj);
|
||
|
}
|
||
12 years ago
|
if(window.sankore)
|
||
|
sankore.setPreference("categoriser_images", JSON.stringify(array_to_export));
|
||
13 years ago
|
}
|
||
|
|
||
|
//import
|
||
|
function importData(data){
|
||
12 years ago
|
|
||
13 years ago
|
for(var i in data){
|
||
|
if(data[i].tmp){
|
||
|
changeStyle(data[i].style);
|
||
12 years ago
|
$("#style_select").val(data[i].style);
|
||
13 years ago
|
} else {
|
||
|
if(i == 0){
|
||
|
changeStyle(data[i].style);
|
||
12 years ago
|
$("#style_select").val(data[i].style);
|
||
13 years ago
|
}
|
||
|
if(data[i].mode == "edit"){
|
||
|
var tmp_array = [];
|
||
|
var container = $("<div class='cont'>");
|
||
|
var sub_container = $("<div class='sub_cont'>").appendTo(container);
|
||
12 years ago
|
// $("<div class='number_cont'>"+ (++tmp) +"</div>").appendTo(sub_container);
|
||
13 years ago
|
|
||
|
for(var j in data[i].conts){
|
||
|
var imgs_container = $("<div class='imgs_cont def_cont'>").appendTo(container);
|
||
|
|
||
|
$("<input type='hidden' name='mask' value='" + data[i].conts[j].mask + "'/>").appendTo(imgs_container);
|
||
|
$("<input type='hidden' name='count' value='" + data[i].conts[j].count + "'/>").appendTo(imgs_container);
|
||
|
var tmp_div = $("<div style='width: 100%; overflow: hidden;'>").appendTo(imgs_container);
|
||
|
$("<input type='text' class='cat_desc' value='" + data[i].conts[j].text + "' disabled/>").appendTo(tmp_div);
|
||
|
for(var k in data[i].conts[j].imgs){
|
||
|
var block_img = $("<div class='img_block' style='text-align: center;'></div>");
|
||
|
$("<input type='hidden' value='" + data[i].conts[j].imgs[k].value + "'/>").appendTo(block_img);
|
||
12 years ago
|
var img = $("<img src=\"../../" + data[i].conts[j].imgs[k].link + "\" style=\"display: inline;\"/>").appendTo(block_img);
|
||
13 years ago
|
img.height(data[i].conts[j].imgs[k].ht);
|
||
|
if((120 - data[i].conts[j].imgs[k].ht) > 0)
|
||
13 years ago
|
img.css("margin",(120 - data[i].conts[j].imgs[k].ht)/2 + "px 0");
|
||
|
tmp_array.push(block_img);
|
||
|
}
|
||
|
|
||
|
imgs_container.droppable({
|
||
|
hoverClass: 'dropHere',
|
||
|
drop: function(event, ui) {
|
||
|
if($(ui.draggable).parent().parent().html() == $(this).parent().html()){
|
||
|
var tmp_ui = $(ui.draggable).parent();
|
||
12 years ago
|
$(this).append($(ui.draggable));
|
||
13 years ago
|
checkCorrectness(tmp_ui);
|
||
|
}
|
||
|
}
|
||
12 years ago
|
});
|
||
13 years ago
|
}
|
||
|
|
||
|
var all_imgs = $("<div class='all_imgs'>").appendTo(container);
|
||
|
|
||
|
tmp_array = shuffle(tmp_array);
|
||
|
for(j in tmp_array){
|
||
|
tmp_array[j].draggable({
|
||
|
helper:'clone',
|
||
|
zIndex:100,
|
||
|
appendTo: '#data'
|
||
|
});
|
||
|
tmp_array[j].appendTo(all_imgs);
|
||
|
}
|
||
|
|
||
|
all_imgs.sortable();
|
||
|
|
||
|
all_imgs.droppable({
|
||
|
hoverClass: 'dropBack',
|
||
|
drop: function(event, ui) {
|
||
|
if($(ui.draggable).parent().parent().html() == $(this).parent().html()){
|
||
|
if(this != $(ui.draggable).parent()[0]){
|
||
|
var tmp_ui = $(ui.draggable).parent();
|
||
|
$(this).append($(ui.draggable));
|
||
|
checkCorrectness(tmp_ui);
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
});
|
||
|
|
||
|
container.appendTo("#data");
|
||
|
} else {
|
||
|
container = $("<div class='cont'>");
|
||
|
sub_container = $("<div class='sub_cont'>").appendTo(container);
|
||
12 years ago
|
// $("<div class='number_cont'>" + (++tmp) + "</div>").appendTo(sub_container);
|
||
13 years ago
|
|
||
|
for(j in data[i].conts){
|
||
|
var tmp_img_array = [];
|
||
|
imgs_container = $("<div class='imgs_cont def_cont'>").appendTo(container);
|
||
|
$("<input type='hidden' name='mask' value='" + data[i].conts[j].mask + "'/>").appendTo(imgs_container);
|
||
|
$("<input type='hidden' name='count' value='" + data[i].conts[j].count + "'/>").appendTo(imgs_container);
|
||
|
tmp_div = $("<div style='width: 100%; overflow: hidden;'>").appendTo(imgs_container);
|
||
|
$("<input type='text' class='cat_desc' value='" + data[i].conts[j].text + "' disabled/>").appendTo(tmp_div);
|
||
|
for(k in data[i].conts[j].imgs){
|
||
|
block_img = $("<div class='img_block' style='text-align: center;'></div>");
|
||
|
$("<input type='hidden' value='" + data[i].conts[j].imgs[k].value + "'/>").appendTo(block_img);
|
||
|
img = $("<img src=\"../../" + data[i].conts[j].imgs[k].link + "\" style=\"display: inline;\"/>").appendTo(block_img);
|
||
13 years ago
|
img.height(data[i].conts[j].imgs[k].ht);
|
||
|
if((120 - data[i].conts[j].imgs[k].ht) > 0)
|
||
13 years ago
|
img.css("margin",(120 - data[i].conts[j].imgs[k].ht)/2 + "px 0");
|
||
|
tmp_img_array.push(block_img);
|
||
|
}
|
||
|
|
||
|
tmp_img_array = shuffle(tmp_img_array);
|
||
|
for(k in tmp_img_array){
|
||
|
tmp_img_array[k].draggable({
|
||
|
helper:'clone',
|
||
|
zIndex:100,
|
||
|
appendTo: '#data'
|
||
|
});
|
||
|
tmp_img_array[k].appendTo(imgs_container);
|
||
|
}
|
||
|
|
||
|
imgs_container.droppable({
|
||
|
hoverClass: 'dropHere',
|
||
|
drop: function(event, ui) {
|
||
|
if($(ui.draggable).parent().parent().html() == $(this).parent().html()){
|
||
|
var tmp_ui = $(ui.draggable).parent();
|
||
12 years ago
|
$(this).append($(ui.draggable));
|
||
13 years ago
|
checkCorrectness(tmp_ui);
|
||
|
}
|
||
|
}
|
||
12 years ago
|
});
|
||
13 years ago
|
}
|
||
|
|
||
|
all_imgs = $("<div class='all_imgs'>").appendTo(container);
|
||
|
var all_imgs_arr = [];
|
||
|
for(j in data[i].all_imgs){
|
||
|
block_img = $("<div class='img_block' style='text-align: center;'></div>");
|
||
|
$("<input type='hidden' value='" + data[i].all_imgs[j].value + "'/>").appendTo(block_img);
|
||
13 years ago
|
img = $("<img src=\"../../" + data[i].all_imgs[j].link + "\" style=\"display: inline;\"/>").appendTo(block_img);
|
||
|
img.height(data[i].all_imgs[j].ht);
|
||
|
if((120 - data[i].all_imgs[j].ht) > 0)
|
||
|
img.css("margin",(120 - data[i].all_imgs[j].ht)/2 + "px 0");
|
||
13 years ago
|
all_imgs_arr.push(block_img);
|
||
|
}
|
||
|
|
||
|
all_imgs_arr = shuffle(all_imgs_arr);
|
||
|
for(k in all_imgs_arr){
|
||
|
all_imgs_arr[k].draggable({
|
||
|
helper:'clone',
|
||
|
zIndex:100,
|
||
|
appendTo: '#data'
|
||
|
});
|
||
|
all_imgs_arr[k].appendTo(all_imgs);
|
||
|
}
|
||
|
|
||
|
all_imgs.sortable();
|
||
|
|
||
|
all_imgs.droppable({
|
||
|
hoverClass: 'dropBack',
|
||
|
drop: function(event, ui) {
|
||
|
if($(ui.draggable).parent().parent().html() == $(this).parent().html()){
|
||
|
if(this != $(ui.draggable).parent()[0]){
|
||
|
var tmp_ui = $(ui.draggable).parent();
|
||
|
$(this).append($(ui.draggable));
|
||
|
checkCorrectness(tmp_ui);
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
});
|
||
|
container.appendTo("#data");
|
||
12 years ago
|
checkCorrectness(all_imgs);
|
||
13 years ago
|
}
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
//example
|
||
|
function showExample(){
|
||
|
|
||
13 years ago
|
changeStyle("3");
|
||
13 years ago
|
var tmp_array = [];
|
||
|
|
||
|
var container = $("<div class='cont'>").appendTo("#data");
|
||
|
var sub_container = $("<div class='sub_cont'>").appendTo(container);
|
||
|
var imgs_container_one = $("<div class='imgs_cont def_cont'>").appendTo(container);
|
||
|
var imgs_container_two = $("<div class='imgs_cont def_cont'>").appendTo(container);
|
||
|
var all_imgs = $("<div class='all_imgs'>").appendTo(container);
|
||
|
|
||
12 years ago
|
// var number = $("<div class='number_cont'>1</div>").appendTo(sub_container);
|
||
13 years ago
|
|
||
|
$("<input type='hidden' name='mask' value='1'/>").appendTo(imgs_container_one);
|
||
|
$("<input type='hidden' name='count' value='2'/>").appendTo(imgs_container_one);
|
||
|
var tmp_div_one = $("<div style='width: 100%; overflow: hidden;'>").appendTo(imgs_container_one);
|
||
|
$("<input type='text' class='cat_desc' value='" + sankoreLang.first_desc + "' disabled/>").appendTo(tmp_div_one);
|
||
|
|
||
|
$("<input type='hidden' name='mask' value='2'/>").appendTo(imgs_container_two);
|
||
|
$("<input type='hidden' name='count' value='3'/>").appendTo(imgs_container_two);
|
||
|
var tmp_div_two = $("<div style='width: 100%; overflow: hidden;'>").appendTo(imgs_container_two);
|
||
|
$("<input type='text' class='cat_desc' value='" + sankoreLang.second_desc + "' disabled/>").appendTo(tmp_div_two);
|
||
|
|
||
|
var img1 = $("<div class='img_block' style='text-align: center;'></div>");
|
||
|
$("<input type='hidden' value='2'/>").appendTo(img1);
|
||
|
$("<img src=\"../../objects/0.gif\" style=\"display: inline;\" height=\"120\"/>").appendTo(img1);
|
||
|
var img2 = $("<div class='img_block' style='text-align: center;'></div>");
|
||
|
$("<input type='hidden' value='1'/>").appendTo(img2);
|
||
|
$("<img src=\"../../objects/1.gif\" style=\"display: inline;\" height=\"120\"/>").appendTo(img2);
|
||
|
var img3 = $("<div class='img_block' style='text-align: center;'></div>");
|
||
|
$("<input type='hidden' value='2'/>").appendTo(img3);
|
||
|
$("<img src=\"../../objects/2.gif\" style=\"display: inline;\" height=\"120\"/>").appendTo(img3);
|
||
|
var img4 = $("<div class='img_block' style='text-align: center;'></div>");
|
||
|
$("<input type='hidden' value='1'/>").appendTo(img4);
|
||
|
$("<img src=\"../../objects/3.gif\" style=\"display: inline;\" height=\"120\"/>").appendTo(img4);
|
||
|
var img5 = $("<div class='img_block' style='text-align: center;'></div>");
|
||
|
$("<input type='hidden' value='2'/>").appendTo(img5);
|
||
|
$("<img src=\"../../objects/4.gif\" style=\"display: inline;\" height=\"120\"/>").appendTo(img5);
|
||
|
|
||
|
tmp_array.push(img1, img2, img3, img4, img5);
|
||
|
tmp_array = shuffle(tmp_array);
|
||
|
for(var i = 0; i<tmp_array.length;i++){
|
||
|
tmp_array[i].draggable({
|
||
|
helper:'clone',
|
||
|
zIndex:100,
|
||
|
appendTo: '#data'
|
||
|
});
|
||
|
tmp_array[i].appendTo(all_imgs);
|
||
|
}
|
||
|
all_imgs.sortable();
|
||
|
|
||
|
imgs_container_one.droppable({
|
||
|
hoverClass: 'dropHere',
|
||
|
drop: function(event, ui) {
|
||
|
if($(ui.draggable).parent().parent().html() == $(this).parent().html()){
|
||
|
var tmp_ui = $(ui.draggable).parent();
|
||
12 years ago
|
$(this).append($(ui.draggable));
|
||
13 years ago
|
checkCorrectness(tmp_ui);
|
||
|
}
|
||
|
}
|
||
|
});
|
||
|
|
||
|
imgs_container_two.droppable({
|
||
|
hoverClass: 'dropHere',
|
||
|
drop: function(event, ui) {
|
||
|
if($(ui.draggable).parent().parent().html() == $(this).parent().html()){
|
||
|
var tmp_ui = $(ui.draggable).parent();
|
||
12 years ago
|
$(this).append($(ui.draggable));
|
||
13 years ago
|
checkCorrectness(tmp_ui);
|
||
|
}
|
||
|
}
|
||
|
});
|
||
|
|
||
|
all_imgs.droppable({
|
||
|
hoverClass: 'dropBack',
|
||
|
drop: function(event, ui) {
|
||
|
if($(ui.draggable).parent().parent().html() == $(this).parent().html()){
|
||
|
if(this != $(ui.draggable).parent()[0]){
|
||
|
var tmp_ui = $(ui.draggable).parent();
|
||
|
$(this).append($(ui.draggable));
|
||
|
checkCorrectness(tmp_ui);
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
});
|
||
|
}
|
||
|
|
||
|
//function that allows to add new category
|
||
|
function addCategory(obj){
|
||
|
var imgs_container = $("<div class='imgs_cont def_cont'>").insertAfter(obj);
|
||
|
$("<input type='hidden' name='mask' value='" + returnId() + "'/>").appendTo(imgs_container);
|
||
|
$("<input type='hidden' name='count' value=''/>").appendTo(imgs_container);
|
||
|
var tmp_div = $("<div style='width: 100%; overflow: hidden;'>").appendTo(imgs_container);
|
||
|
$("<input type='text' class='cat_desc' value='" + sankoreLang.enter + "'>").appendTo(tmp_div);
|
||
13 years ago
|
$("<button class='del_category'></button>").appendTo(imgs_container);
|
||
|
$("<button class='add_category'></button>").appendTo(imgs_container);
|
||
13 years ago
|
imgs_container.attr("ondragenter", "return false;")
|
||
12 years ago
|
.attr("ondragleave", "$(this).css(\"background-color\",\"#e6f6ff\"); return false;")
|
||
|
.attr("ondragover", "$(this).css(\"background-color\",\"#c3e9ff\"); return false;")
|
||
|
.attr("ondrop", "$(this).css(\"background-color\",\"#e6f6ff\"); return onDropTarget(this,event);");
|
||
13 years ago
|
}
|
||
|
|
||
|
//add new container
|
||
12 years ago
|
//function addContainer(){
|
||
|
// var container = $("<div class='cont'>");
|
||
|
// var sub_container = $("<div class='sub_cont'>").appendTo(container);
|
||
|
// var imgs_container = $("<div class='imgs_cont def_cont'>").appendTo(container);
|
||
|
//
|
||
|
// var close = $("<div class='close_cont'>").appendTo(container);
|
||
|
// var number = $("<div class='number_cont'>"+ ($(".cont").size() + 1) +"</div>").appendTo(sub_container);
|
||
|
//
|
||
|
// $("<input type='hidden' name='mask' value='" + returnId() + "'/>").appendTo(imgs_container);
|
||
|
// $("<input type='hidden' name='count' value=''/>").appendTo(imgs_container);
|
||
|
// var tmp_div = $("<div style='width: 100%; overflow: hidden;'>").appendTo(imgs_container);
|
||
|
// $("<input type='text' class='cat_desc' value='" + sankoreLang.enter + "'/>").appendTo(tmp_div);
|
||
|
// $("<button class='del_category'></button>").appendTo(imgs_container);
|
||
|
// $("<button class='add_category'></button>").appendTo(imgs_container);
|
||
|
// imgs_container.attr("ondragenter", "return false;")
|
||
|
// .attr("ondragleave", "$(this).css(\"background-color\",\"#e6f6ff\"); return false;")
|
||
|
// .attr("ondragover", "$(this).css(\"background-color\",\"#c3e9ff\"); return false;")
|
||
|
// .attr("ondrop", "$(this).css(\"background-color\",\"#e6f6ff\"); return onDropTarget(this,event);");
|
||
|
// container.insertBefore($(".add_block"));
|
||
|
//}
|
||
13 years ago
|
|
||
12 years ago
|
//function refreshBlockNumbers(){
|
||
|
// var i = 0;
|
||
|
// $(".cont").each(function(){
|
||
|
// $(this).find(".number_cont").text(++i);
|
||
|
// })
|
||
|
//}
|
||
13 years ago
|
|
||
|
//shuffles an array
|
||
|
function shuffle( arr )
|
||
|
{
|
||
|
var pos, tmp;
|
||
|
|
||
|
for( var i = 0; i < arr.length; i++ )
|
||
|
{
|
||
|
pos = Math.round( Math.random() * ( arr.length - 1 ) );
|
||
|
tmp = arr[pos];
|
||
|
arr[pos] = arr[i];
|
||
|
arr[i] = tmp;
|
||
|
}
|
||
|
return arr;
|
||
|
}
|
||
|
|
||
|
//changing the style
|
||
|
function changeStyle(val){
|
||
13 years ago
|
switch(val){
|
||
|
case "1":
|
||
|
$(".b_top_left").removeClass("btl_pad").removeClass("without_back");
|
||
|
$(".b_top_center").removeClass("btc_pad").removeClass("without_back");
|
||
|
$(".b_top_right").removeClass("btr_pad").removeClass("without_back");
|
||
|
$(".b_center_left").removeClass("bcl_pad").removeClass("without_back");
|
||
|
$(".b_center_right").removeClass("bcr_pad").removeClass("without_back");
|
||
|
$(".b_bottom_right").removeClass("bbr_pad").removeClass("without_back");
|
||
|
$(".b_bottom_left").removeClass("bbl_pad").removeClass("without_back");
|
||
|
$(".b_bottom_center").removeClass("bbc_pad").removeClass("without_back");
|
||
|
$("#wgt_reload").removeClass("pad_color").removeClass("pad_reload");
|
||
13 years ago
|
$("#wgt_help").removeClass("pad_color").removeClass("pad_help");
|
||
13 years ago
|
$("#wgt_edit").removeClass("pad_color").removeClass("pad_edit");
|
||
|
$("#wgt_name").removeClass("pad_color");
|
||
12 years ago
|
$("#wgt_display").addClass("display_wood");
|
||
|
$("#style_select").val(val);
|
||
|
$("body, html").removeClass("without_radius").addClass("radius_ft");
|
||
13 years ago
|
break;
|
||
|
case "2":
|
||
|
$(".b_top_left").addClass("btl_pad").removeClass("without_back");
|
||
|
$(".b_top_center").addClass("btc_pad").removeClass("without_back");
|
||
|
$(".b_top_right").addClass("btr_pad").removeClass("without_back");
|
||
|
$(".b_center_left").addClass("bcl_pad").removeClass("without_back");
|
||
|
$(".b_center_right").addClass("bcr_pad").removeClass("without_back");
|
||
|
$(".b_bottom_right").addClass("bbr_pad").removeClass("without_back");
|
||
|
$(".b_bottom_left").addClass("bbl_pad").removeClass("without_back");
|
||
|
$(".b_bottom_center").addClass("bbc_pad").removeClass("without_back");
|
||
|
$("#wgt_reload").addClass("pad_color").addClass("pad_reload");
|
||
13 years ago
|
$("#wgt_help").addClass("pad_color").addClass("pad_help");
|
||
13 years ago
|
$("#wgt_edit").addClass("pad_color").addClass("pad_edit");
|
||
|
$("#wgt_name").addClass("pad_color");
|
||
12 years ago
|
$("#wgt_display").removeClass("display_wood");
|
||
|
$("#style_select").val(val);
|
||
|
$("body, html").removeClass("without_radius").removeClass("radius_ft");
|
||
13 years ago
|
break;
|
||
|
case "3":
|
||
|
$(".b_top_left").addClass("without_back").removeClass("btl_pad");
|
||
|
$(".b_top_center").addClass("without_back").removeClass("btc_pad");
|
||
|
$(".b_top_right").addClass("without_back").removeClass("btr_pad");
|
||
|
$(".b_center_left").addClass("without_back").removeClass("bcl_pad");
|
||
|
$(".b_center_right").addClass("without_back").removeClass("bcr_pad");
|
||
|
$(".b_bottom_right").addClass("without_back").removeClass("bbr_pad");
|
||
|
$(".b_bottom_left").addClass("without_back").removeClass("bbl_pad");
|
||
|
$(".b_bottom_center").addClass("without_back").removeClass("bbc_pad");
|
||
13 years ago
|
$("#wgt_help").addClass("pad_color").addClass("pad_help");
|
||
13 years ago
|
$("#wgt_reload").addClass("pad_color").addClass("pad_reload");
|
||
|
$("#wgt_edit").addClass("pad_color").addClass("pad_edit");
|
||
|
$("#wgt_name").addClass("pad_color");
|
||
12 years ago
|
$("#wgt_display").removeClass("display_wood");
|
||
|
$("#style_select").val(val);
|
||
|
$("body, html").addClass("without_radius").removeClass("radius_ft");
|
||
13 years ago
|
break;
|
||
13 years ago
|
}
|
||
|
}
|
||
|
|
||
12 years ago
|
function stringToXML(text){
|
||
|
if (window.ActiveXObject){
|
||
|
var doc=new ActiveXObject('Microsoft.XMLDOM');
|
||
|
doc.async='false';
|
||
|
doc.loadXML(text);
|
||
|
} else {
|
||
|
var parser=new DOMParser();
|
||
|
doc=parser.parseFromString(text,'text/xml');
|
||
|
}
|
||
|
return doc;
|
||
|
}
|
||
|
|
||
13 years ago
|
//return id
|
||
|
function returnId(){
|
||
|
var tmp = Math.random().toString();
|
||
|
return tmp.substr(2);
|
||
|
}
|
||
|
|
||
|
//a func for checking when smth will drop
|
||
12 years ago
|
function checkOnDrop(dest){
|
||
13 years ago
|
var tmp_count = dest.find("input[name='count']").val();
|
||
|
var tmp_mask = dest.find("input[name='mask']").val();
|
||
|
if(dest.find(".img_block").size() == tmp_count){
|
||
|
var tmp_right = true;
|
||
|
dest.find(".img_block").each(function(){
|
||
|
if($(this).find("input").val() != tmp_mask)
|
||
|
tmp_right = false;
|
||
|
});
|
||
|
if(tmp_right)
|
||
12 years ago
|
dest.removeClass("def_cont").removeClass("red_cont").addClass("green_cont");
|
||
13 years ago
|
else
|
||
12 years ago
|
dest.removeClass("def_cont").removeClass("green_cont").addClass("red_cont");
|
||
13 years ago
|
} else
|
||
12 years ago
|
dest.removeClass("def_cont").removeClass("green_cont").addClass("red_cont");
|
||
13 years ago
|
}
|
||
|
|
||
|
//checking source on correctness
|
||
|
function checkCorrectness(source){
|
||
|
if(!source.hasClass("all_imgs")){
|
||
12 years ago
|
if(source.parent().find(".all_imgs").find(".img_block").size() == 0){
|
||
|
source.parent().find(".imgs_cont").each(function(){
|
||
|
checkOnDrop($(this))
|
||
|
})
|
||
|
} else {
|
||
|
source.parent().find(".imgs_cont").each(function(){
|
||
|
$(this).addClass("def_cont").removeClass("green_cont").removeClass("red_cont");
|
||
|
})
|
||
|
}
|
||
|
} else {
|
||
|
if(source.find(".img_block").size() > 0){
|
||
|
source.parent().find(".imgs_cont").each(function(){
|
||
|
$(this).addClass("def_cont").removeClass("green_cont").removeClass("red_cont");
|
||
|
})
|
||
|
} else {
|
||
|
source.parent().find(".imgs_cont").each(function(){
|
||
|
checkOnDrop($(this))
|
||
|
})
|
||
|
}
|
||
13 years ago
|
}
|
||
|
}
|
||
|
|
||
|
function onDropTarget(obj, event) {
|
||
|
if (event.dataTransfer) {
|
||
|
var format = "text/plain";
|
||
|
var textData = event.dataTransfer.getData(format);
|
||
|
if (!textData) {
|
||
|
alert(":(");
|
||
|
}
|
||
|
textData = stringToXML(textData);
|
||
|
if(textData.getElementsByTagName("ready")[0].firstChild.textContent == "true"){
|
||
|
var tmp = textData.getElementsByTagName("path")[0].firstChild.textContent;
|
||
|
var img_block = $("<div class='img_block' style='text-align: center;'>");
|
||
|
$("<div class='close_img'>").appendTo(img_block);
|
||
|
$("<input type='hidden' value='" + $(obj).find("input[name='mask']").val() + "'/>").appendTo(img_block);
|
||
|
var tmp_img = $("<img style='display: inline;'/>").attr("src", "../../" + tmp).appendTo(img_block);
|
||
|
img_block.draggable({
|
||
|
helper:'clone',
|
||
|
zIndex:100,
|
||
|
appendTo: '#data'
|
||
|
});
|
||
|
$(obj).append(img_block);
|
||
|
|
||
|
if(tmp_img.height() == 0){
|
||
|
var tmp_id = setInterval(function(){
|
||
|
if(tmp_img.height() != 0){
|
||
|
if(tmp_img.height() >= tmp_img.width())
|
||
|
tmp_img.attr("height", "120");
|
||
|
else{
|
||
|
tmp_img.attr("width","120");
|
||
13 years ago
|
var h = tmp_img.height();
|
||
|
tmp_img.attr("height",h);
|
||
13 years ago
|
tmp_img.css("margin",(120 - tmp_img.height())/2 + "px 0");
|
||
|
}
|
||
|
clearInterval(tmp_id);
|
||
|
}
|
||
|
}, 10);
|
||
|
} else {
|
||
|
if(tmp_img.height() >= tmp_img.width())
|
||
|
tmp_img.attr("height", "120");
|
||
|
else{
|
||
|
tmp_img.attr("width","120");
|
||
13 years ago
|
var h = tmp_img.height();
|
||
|
tmp_img.attr("height",h);
|
||
13 years ago
|
tmp_img.css("margin",(120 - tmp_img.height())/2 + "px 0");
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
else {
|
||
|
alert ("Your browser does not support the dataTransfer object.");
|
||
|
}
|
||
|
|
||
|
if (event.stopPropagation) {
|
||
|
event.stopPropagation ();
|
||
|
}
|
||
|
else {
|
||
|
event.cancelBubble = true;
|
||
|
}
|
||
|
return false;
|
||
13 years ago
|
}
|