From 66caf1c22b1251a6a155a47aa05155b8d926ce88 Mon Sep 17 00:00:00 2001 From: unknown Date: Mon, 25 Jun 2012 16:43:46 +0200 Subject: [PATCH 1/4] fixed cat text widget --- .../interactivities/Cat text.wgt/js/script.js | 271 +++++++++++------- .../Cat text.wgt/locales/fr/js/script.js | 255 ++++++++++------ .../Cat text.wgt/locales/ru/js/script.js | 251 ++++++++++------ 3 files changed, 484 insertions(+), 293 deletions(-) diff --git a/resources/library/interactivities/Cat text.wgt/js/script.js b/resources/library/interactivities/Cat text.wgt/js/script.js index 1ea3bc2b..7f8ca614 100644 --- a/resources/library/interactivities/Cat text.wgt/js/script.js +++ b/resources/library/interactivities/Cat text.wgt/js/script.js @@ -1,17 +1,11 @@ var sankoreLang = { display: "Display", edit: "Edit", - first_desc: "Fruits", - second_desc: "Vegetables", - potatoes: "Potato", - carrot: "Carrot", - onion: "Onion", - apple: "Apple", - pear: "Pear", + first_desc: "Odd numbers", + second_desc: "Even numbers", enter: "Enter your category name here ...", add: "Add new block", - text: "Some text", - wgt_name: "Categorize text", + wgt_name: "Order images", reload: "Reload", slate: "Wood", pad: "Pad" @@ -28,8 +22,8 @@ function start(){ $(".style_select option[value='2']").text(sankoreLang.pad); if(window.sankore){ - if(sankore.preference("categoriser_text","")){ - var data = jQuery.parseJSON(sankore.preference("categoriser_text","")); + if(sankore.preference("categoriser_images","")){ + var data = jQuery.parseJSON(sankore.preference("categoriser_images","")); importData(data); } else { showExample(); @@ -40,12 +34,21 @@ function start(){ if (window.widget) { window.widget.onleave = function(){ - //exportData(); + exportData(); } } $("#wgt_reload").click(function(){ - window.location.reload(); + 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(); }); $(".style_select").change(function (event){ @@ -58,6 +61,7 @@ function start(){ $(this).addClass("selected"); $("#wgt_edit").removeClass("selected"); $(".style_select").css("display","none"); + sankore.enableDropOnWidget(false); $(".add_block").remove(); $(".cont").each(function(){ var container = $(this); @@ -68,7 +72,6 @@ function start(){ container.find(".close_cont").remove(); container.find(".imgs_cont").each(function(){ $(this).find(".del_category").remove(); - $(this).find(".add_img").remove(); $(this).find(".add_category").remove(); $(this).removeAttr("ondragenter") .removeAttr("ondragleave") @@ -79,9 +82,6 @@ function start(){ $(this).find("input[name='count']").val(tmp_count); $(this).find(".img_block").each(function(){ $(this).find(".close_img").remove(); - var tmp_text = $(this).find(".text_cont"); - tmp_text.removeAttr("contenteditable") - .css("margin", ($(this).height() - tmp_text.height())/2 + "px 0px"); tmp_array.push($(this)); $(this).remove(); }); @@ -131,14 +131,19 @@ function start(){ $(this).addClass("selected"); $("#wgt_display").removeClass("selected"); $(".style_select").css("display","block"); + sankore.enableDropOnWidget(true); $(".cont").each(function(){ var container = $(this); $("
").appendTo(container); container.find(".imgs_cont").each(function(){ - $("").appendTo($(this)); - $("").appendTo($(this)); - $(this).removeClass("red_cont") + $("").appendTo($(this)); + $("").appendTo($(this)); + $(this).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);") + .removeClass("red_cont") .removeClass("green_cont") .addClass("def_cont") .droppable("destroy") @@ -146,15 +151,11 @@ function start(){ var tmp_img_cont = $(this); var tmp_mask = $(this).find("input[name='mask']").val(); container.find(".img_block").each(function(){ - $(this).draggable("destroy") - .find(".text_cont").attr("contenteditable","true") - .removeAttr("style"); if($(this).find("input").val() == tmp_mask){ $("
").appendTo($(this)); $(this).appendTo(tmp_img_cont); } }); - $("
").appendTo($(this)); }); container.find(".all_imgs").remove(); }); @@ -174,7 +175,7 @@ function start(){ //adding new img $(".add_img").live("click", function(){ - addText($(this).parent(), $(this)); + addImgBlock($(this)); }); //deleting a block @@ -202,26 +203,19 @@ function start(){ $(this).parent().remove(); } }); - - $(".text_cont").live("blur", function(){ - exportData(); - }).live("keyup", function(e){ - if (e.keyCode == 13) - exportData(); - }); } //export function exportData(){ var array_to_export = []; - if($("#wgt_edit").hasClass("selected")){ + if($("#edit").hasClass("selected")){ $(".cont").each(function(){ var cont_obj = new Object(); + cont_obj.style = $(".style_select").find("option:selected").val(); cont_obj.mode = "edit"; cont_obj.conts = []; $(this).find(".imgs_cont").each(function(){ var img_cont = new Object(); - cont_obj.style = $(".style_select").find("option:selected").val(); 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(); @@ -229,7 +223,9 @@ function exportData(){ $(this).find(".img_block").each(function(){ var img_obj = new Object(); img_obj.value = $(this).find("input").val(); - img_obj.text = $(this).find(".text_cont").text(); + img_obj.link = $(this).find("img").attr("src"); + 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); @@ -239,11 +235,11 @@ function exportData(){ } else { $(".cont").each(function(){ var cont_obj = new Object(); + cont_obj.style = $(".style_select").find("option:selected").val(); cont_obj.mode = "display"; cont_obj.conts = []; $(this).find(".imgs_cont").each(function(){ var img_cont = new Object(); - cont_obj.style = $(".style_select").find("option:selected").val(); 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(); @@ -251,7 +247,9 @@ function exportData(){ $(this).find(".img_block").each(function(){ var img_obj = new Object(); img_obj.value = $(this).find("input").val(); - img_obj.text = $(this).find(".text_cont").text(); + img_obj.link = $(this).find("img").attr("src"); + 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); @@ -260,7 +258,9 @@ function exportData(){ $(this).find(".all_imgs .img_block").each(function(){ var img = new Object(); img.value = $(this).find("input").val(); - img.text = $(this).find(".text_cont").text(); + img.link = $(this).find("img").attr("src"); + img.ht = $(this).find("img").height(); + img.wd = $(this).find("img").width(); cont_obj.all_imgs.push(img); }); array_to_export.push(cont_obj); @@ -274,7 +274,7 @@ function exportData(){ array_to_export.push(cont_obj); } - sankore.setPreference("categoriser_text", JSON.stringify(array_to_export)); + sankore.setPreference("categoriser_images", JSON.stringify(array_to_export)); } //import @@ -285,15 +285,14 @@ function importData(data){ if(data[i].tmp){ changeStyle(data[i].style); $(".style_select").val(data[i].style); - } - else { + } else { if(i == 0){ changeStyle(data[i].style); $(".style_select").val(data[i].style); } if(data[i].mode == "edit"){ var tmp_array = []; - var container = $("
").appendTo("#data"); + var container = $("
"); var sub_container = $("
").appendTo(container); $("
"+ (++tmp) +"
").appendTo(sub_container); @@ -306,8 +305,14 @@ function importData(data){ $("").appendTo(tmp_div); for(var k in data[i].conts[j].imgs){ var block_img = $("
"); - $("").appendTo(block_img); - $("
" + data[i].conts[j].imgs[k].text + "
").appendTo(block_img); + $("").appendTo(block_img); + var img = $("").appendTo(block_img); + if(data[i].conts[j].imgs[k].ht >= data[i].conts[j].imgs[k].wd) + img.attr("height", "120"); + else{ + img.attr("width","120"); + img.css("margin",(120 - data[i].conts[j].imgs[k].ht)/2 + "px 0"); + } tmp_array.push(block_img); } @@ -333,8 +338,6 @@ function importData(data){ appendTo: '#data' }); tmp_array[j].appendTo(all_imgs); - var tmp_text = tmp_array[j].find(".text_cont"); - tmp_text.css("margin", (tmp_array[j].height() - tmp_text.height())/2 + "px 0px"); } all_imgs.sortable(); @@ -351,8 +354,10 @@ function importData(data){ } } }); + + container.appendTo("#data"); } else { - container = $("
").appendTo("#data"); + container = $("
"); sub_container = $("
").appendTo(container); $("
" + (++tmp) + "
").appendTo(sub_container); @@ -365,8 +370,14 @@ function importData(data){ $("").appendTo(tmp_div); for(k in data[i].conts[j].imgs){ block_img = $("
"); - $("").appendTo(block_img); - $("
" + data[i].conts[j].imgs[k].text + "
").appendTo(block_img); + $("").appendTo(block_img); + img = $("").appendTo(block_img); + if(data[i].conts[j].imgs[k].ht >= data[i].conts[j].imgs[k].wd) + img.attr("height", "120"); + else{ + img.attr("width","120"); + img.css("margin",(120 - data[i].conts[j].imgs[k].ht)/2 + "px 0"); + } tmp_img_array.push(block_img); } @@ -378,8 +389,6 @@ function importData(data){ appendTo: '#data' }); tmp_img_array[k].appendTo(imgs_container); - tmp_text = tmp_img_array[k].find(".text_cont"); - tmp_text.css("margin", (tmp_img_array[k].height() - tmp_text.height())/2 + "px 0px"); } imgs_container.droppable({ @@ -399,8 +408,8 @@ function importData(data){ var all_imgs_arr = []; for(j in data[i].all_imgs){ block_img = $("
"); - $("").appendTo(block_img); - $("
" + data[i].all_imgs[j].text + "
").appendTo(block_img); + $("").appendTo(block_img); + $("").appendTo(block_img); all_imgs_arr.push(block_img); } @@ -412,8 +421,6 @@ function importData(data){ appendTo: '#data' }); all_imgs_arr[k].appendTo(all_imgs); - tmp_text = all_imgs_arr[k].find(".text_cont"); - tmp_text.css("margin", (all_imgs_arr[k].height() - tmp_text.height())/2 + "px 0px"); } all_imgs.sortable(); @@ -430,6 +437,7 @@ function importData(data){ } } }); + container.appendTo("#data"); } } } @@ -459,23 +467,23 @@ function showExample(){ var tmp_div_two = $("
").appendTo(imgs_container_two); $("").appendTo(tmp_div_two); - var text1 = $("
"); - $("").appendTo(text1); - $("
" + sankoreLang.potatoes + "
").appendTo(text1); - var text2 = $("
"); - $("").appendTo(text2); - $("
" + sankoreLang.apple + "
").appendTo(text2); - var text3 = $("
"); - $("").appendTo(text3); - $("
" + sankoreLang.carrot + "
").appendTo(text3); - var text4 = $("
"); - $("").appendTo(text4); - $("
" + sankoreLang.pear + "
").appendTo(text4); - var text5 = $("
"); - $("").appendTo(text5); - $("
" + sankoreLang.onion + "
").appendTo(text5); + var img1 = $("
"); + $("").appendTo(img1); + $("").appendTo(img1); + var img2 = $("
"); + $("").appendTo(img2); + $("").appendTo(img2); + var img3 = $("
"); + $("").appendTo(img3); + $("").appendTo(img3); + var img4 = $("
"); + $("").appendTo(img4); + $("").appendTo(img4); + var img5 = $("
"); + $("").appendTo(img5); + $("").appendTo(img5); - tmp_array.push(text1, text2, text3, text4, text5); + tmp_array.push(img1, img2, img3, img4, img5); tmp_array = shuffle(tmp_array); for(var i = 0; i").insertBefore(source); - $("
").appendTo(text_block); - $("").appendTo(text_block); - $("
" + sankoreLang.text + "
").appendTo(text_block); -} - //function that allows to add new category function addCategory(obj){ var imgs_container = $("
").insertAfter(obj); @@ -540,9 +538,12 @@ function addCategory(obj){ $("").appendTo(imgs_container); var tmp_div = $("
").appendTo(imgs_container); $("").appendTo(tmp_div); - $("").appendTo(imgs_container); - $("").appendTo(imgs_container); - $("
").appendTo(imgs_container); + $("").appendTo(imgs_container); + $("").appendTo(imgs_container); + imgs_container.attr("ondragenter", "return false;") + .attr("ondragleave", "$(this).css(\"background-color\",\"\"); return false;") + .attr("ondragover", "$(this).css(\"background-color\",\"\"); return false;") + .attr("ondrop", "$(this).css(\"background-color\",\"\"); return onDropTarget(this,event);"); } //add new container @@ -558,9 +559,12 @@ function addContainer(){ $("").appendTo(imgs_container); var tmp_div = $("
").appendTo(imgs_container); $("").appendTo(tmp_div); - $("").appendTo(imgs_container); - $("").appendTo(imgs_container); - $("
").appendTo(imgs_container); + $("").appendTo(imgs_container); + $("").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")); } @@ -586,24 +590,6 @@ function shuffle( arr ) return arr; } -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; -} - -//return id -function returnId(){ - var tmp = Math.random().toString(); - return tmp.substr(2); -} - //changing the style function changeStyle(val){ if(val == 1){ @@ -637,6 +623,24 @@ function changeStyle(val){ } } +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; +} + +//return id +function returnId(){ + var tmp = Math.random().toString(); + return tmp.substr(2); +} + //a func for checking when smth will drop function checkOnDrop(dest, source){ dest.append(source); @@ -692,3 +696,60 @@ function checkCorrectness(source){ .addClass("red_cont"); } } + +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 = $("
"); + $("
").appendTo(img_block); + $("").appendTo(img_block); + var tmp_img = $("").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"); + 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"); + tmp_img.css("margin",(120 - tmp_img.height())/2 + "px 0"); + } + } + } + exportData(); + } + else { + alert ("Your browser does not support the dataTransfer object."); + } + + if (event.stopPropagation) { + event.stopPropagation (); + } + else { + event.cancelBubble = true; + } + return false; +} diff --git a/resources/library/interactivities/Cat text.wgt/locales/fr/js/script.js b/resources/library/interactivities/Cat text.wgt/locales/fr/js/script.js index 2f2a9c6c..8cf62916 100644 --- a/resources/library/interactivities/Cat text.wgt/locales/fr/js/script.js +++ b/resources/library/interactivities/Cat text.wgt/locales/fr/js/script.js @@ -1,17 +1,11 @@ var sankoreLang = { display: "Afficher", - edit: "Modifier", - first_desc: "Fruits", - second_desc: "Légumes", - potatoes: "Pomme de terre", - carrot: "Carotte", - onion: "Oignon", - apple: "Pomme", - pear: "Poire", + edit: "Modifier", + first_desc: "Les nombres impairs", + second_desc: "Les nombres pairs", enter: "Saisir le nom de la catégorie ici ...", add: "Nouveau bloc", - text: "Texte", - wgt_name: "Catégoriser des textes", + wgt_name: "Catégoriser des images", reload: "Recharger", slate: "Ardoise", pad: "Tablette" @@ -28,8 +22,8 @@ function start(){ $(".style_select option[value='2']").text(sankoreLang.pad); if(window.sankore){ - if(sankore.preference("categoriser_text","")){ - var data = jQuery.parseJSON(sankore.preference("categoriser_text","")); + if(sankore.preference("categoriser_images","")){ + var data = jQuery.parseJSON(sankore.preference("categoriser_images","")); importData(data); } else { showExample(); @@ -40,12 +34,21 @@ function start(){ if (window.widget) { window.widget.onleave = function(){ - //exportData(); + exportData(); } } $("#wgt_reload").click(function(){ - window.location.reload(); + 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(); }); $(".style_select").change(function (event){ @@ -58,6 +61,7 @@ function start(){ $(this).addClass("selected"); $("#wgt_edit").removeClass("selected"); $(".style_select").css("display","none"); + sankore.enableDropOnWidget(false); $(".add_block").remove(); $(".cont").each(function(){ var container = $(this); @@ -68,7 +72,6 @@ function start(){ container.find(".close_cont").remove(); container.find(".imgs_cont").each(function(){ $(this).find(".del_category").remove(); - $(this).find(".add_img").remove(); $(this).find(".add_category").remove(); $(this).removeAttr("ondragenter") .removeAttr("ondragleave") @@ -79,9 +82,6 @@ function start(){ $(this).find("input[name='count']").val(tmp_count); $(this).find(".img_block").each(function(){ $(this).find(".close_img").remove(); - var tmp_text = $(this).find(".text_cont"); - tmp_text.removeAttr("contenteditable") - .css("margin", ($(this).height() - tmp_text.height())/2 + "px 0px"); tmp_array.push($(this)); $(this).remove(); }); @@ -131,14 +131,19 @@ function start(){ $(this).addClass("selected"); $("#wgt_display").removeClass("selected"); $(".style_select").css("display","block"); + sankore.enableDropOnWidget(true); $(".cont").each(function(){ var container = $(this); $("
").appendTo(container); container.find(".imgs_cont").each(function(){ - $("").appendTo($(this)); - $("").appendTo($(this)); - $(this).removeClass("red_cont") + $("").appendTo($(this)); + $("").appendTo($(this)); + $(this).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);") + .removeClass("red_cont") .removeClass("green_cont") .addClass("def_cont") .droppable("destroy") @@ -146,15 +151,11 @@ function start(){ var tmp_img_cont = $(this); var tmp_mask = $(this).find("input[name='mask']").val(); container.find(".img_block").each(function(){ - $(this).draggable("destroy") - .find(".text_cont").attr("contenteditable","true") - .removeAttr("style"); if($(this).find("input").val() == tmp_mask){ $("
").appendTo($(this)); $(this).appendTo(tmp_img_cont); } }); - $("
").appendTo($(this)); }); container.find(".all_imgs").remove(); }); @@ -174,7 +175,7 @@ function start(){ //adding new img $(".add_img").live("click", function(){ - addText($(this).parent(), $(this)); + addImgBlock($(this)); }); //deleting a block @@ -202,26 +203,19 @@ function start(){ $(this).parent().remove(); } }); - - $(".text_cont").live("blur", function(){ - exportData(); - }).live("keyup", function(e){ - if (e.keyCode == 13) - exportData(); - }); } //export function exportData(){ var array_to_export = []; - if($("#wgt_edit").hasClass("selected")){ + if($("#edit").hasClass("selected")){ $(".cont").each(function(){ var cont_obj = new Object(); + cont_obj.style = $(".style_select").find("option:selected").val(); cont_obj.mode = "edit"; cont_obj.conts = []; $(this).find(".imgs_cont").each(function(){ var img_cont = new Object(); - cont_obj.style = $(".style_select").find("option:selected").val(); 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(); @@ -229,7 +223,10 @@ function exportData(){ $(this).find(".img_block").each(function(){ var img_obj = new Object(); img_obj.value = $(this).find("input").val(); - img_obj.text = $(this).find(".text_cont").text(); + img_obj.link = $(this).find("img").attr("src").replace("../../",""); + ; + 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); @@ -239,11 +236,11 @@ function exportData(){ } else { $(".cont").each(function(){ var cont_obj = new Object(); + cont_obj.style = $(".style_select").find("option:selected").val(); cont_obj.mode = "display"; cont_obj.conts = []; $(this).find(".imgs_cont").each(function(){ var img_cont = new Object(); - cont_obj.style = $(".style_select").find("option:selected").val(); 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(); @@ -251,7 +248,10 @@ function exportData(){ $(this).find(".img_block").each(function(){ var img_obj = new Object(); img_obj.value = $(this).find("input").val(); - img_obj.text = $(this).find(".text_cont").text(); + img_obj.link = $(this).find("img").attr("src").replace("../../",""); + ; + 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); @@ -260,7 +260,10 @@ function exportData(){ $(this).find(".all_imgs .img_block").each(function(){ var img = new Object(); img.value = $(this).find("input").val(); - img.text = $(this).find(".text_cont").text(); + img.link = $(this).find("img").attr("src").replace("../../",""); + ; + img.ht = $(this).find("img").height(); + img.wd = $(this).find("img").width(); cont_obj.all_imgs.push(img); }); array_to_export.push(cont_obj); @@ -274,7 +277,7 @@ function exportData(){ array_to_export.push(cont_obj); } - sankore.setPreference("categoriser_text", JSON.stringify(array_to_export)); + sankore.setPreference("categoriser_images", JSON.stringify(array_to_export)); } //import @@ -285,15 +288,14 @@ function importData(data){ if(data[i].tmp){ changeStyle(data[i].style); $(".style_select").val(data[i].style); - } - else { + } else { if(i == 0){ changeStyle(data[i].style); $(".style_select").val(data[i].style); } if(data[i].mode == "edit"){ var tmp_array = []; - var container = $("
").appendTo("#data"); + var container = $("
"); var sub_container = $("
").appendTo(container); $("
"+ (++tmp) +"
").appendTo(sub_container); @@ -306,8 +308,14 @@ function importData(data){ $("").appendTo(tmp_div); for(var k in data[i].conts[j].imgs){ var block_img = $("
"); - $("").appendTo(block_img); - $("
" + data[i].conts[j].imgs[k].text + "
").appendTo(block_img); + $("").appendTo(block_img); + var img = $("").appendTo(block_img); + if(data[i].conts[j].imgs[k].ht >= data[i].conts[j].imgs[k].wd) + img.attr("height", "120"); + else{ + img.attr("width","120"); + img.css("margin",(120 - data[i].conts[j].imgs[k].ht)/2 + "px 0"); + } tmp_array.push(block_img); } @@ -320,7 +328,7 @@ function importData(data){ checkCorrectness(tmp_ui); } } - }); + }); } var all_imgs = $("
").appendTo(container); @@ -333,8 +341,6 @@ function importData(data){ appendTo: '#data' }); tmp_array[j].appendTo(all_imgs); - var tmp_text = tmp_array[j].find(".text_cont"); - tmp_text.css("margin", (tmp_array[j].height() - tmp_text.height())/2 + "px 0px"); } all_imgs.sortable(); @@ -351,8 +357,10 @@ function importData(data){ } } }); + + container.appendTo("#data"); } else { - container = $("
").appendTo("#data"); + container = $("
"); sub_container = $("
").appendTo(container); $("
" + (++tmp) + "
").appendTo(sub_container); @@ -365,8 +373,14 @@ function importData(data){ $("").appendTo(tmp_div); for(k in data[i].conts[j].imgs){ block_img = $("
"); - $("").appendTo(block_img); - $("
" + data[i].conts[j].imgs[k].text + "
").appendTo(block_img); + $("").appendTo(block_img); + img = $("").appendTo(block_img); + if(data[i].conts[j].imgs[k].ht >= data[i].conts[j].imgs[k].wd) + img.attr("height", "120"); + else{ + img.attr("width","120"); + img.css("margin",(120 - data[i].conts[j].imgs[k].ht)/2 + "px 0"); + } tmp_img_array.push(block_img); } @@ -378,8 +392,6 @@ function importData(data){ appendTo: '#data' }); tmp_img_array[k].appendTo(imgs_container); - tmp_text = tmp_img_array[k].find(".text_cont"); - tmp_text.css("margin", (tmp_img_array[k].height() - tmp_text.height())/2 + "px 0px"); } imgs_container.droppable({ @@ -391,7 +403,7 @@ function importData(data){ checkCorrectness(tmp_ui); } } - }); + }); checkCorrectness(imgs_container); } @@ -399,8 +411,8 @@ function importData(data){ var all_imgs_arr = []; for(j in data[i].all_imgs){ block_img = $("
"); - $("").appendTo(block_img); - $("
" + data[i].all_imgs[j].text + "
").appendTo(block_img); + $("").appendTo(block_img); + $("").appendTo(block_img); all_imgs_arr.push(block_img); } @@ -412,8 +424,6 @@ function importData(data){ appendTo: '#data' }); all_imgs_arr[k].appendTo(all_imgs); - tmp_text = all_imgs_arr[k].find(".text_cont"); - tmp_text.css("margin", (all_imgs_arr[k].height() - tmp_text.height())/2 + "px 0px"); } all_imgs.sortable(); @@ -430,6 +440,7 @@ function importData(data){ } } }); + container.appendTo("#data"); } } } @@ -459,23 +470,23 @@ function showExample(){ var tmp_div_two = $("
").appendTo(imgs_container_two); $("").appendTo(tmp_div_two); - var text1 = $("
"); - $("").appendTo(text1); - $("
" + sankoreLang.potatoes + "
").appendTo(text1); - var text2 = $("
"); - $("").appendTo(text2); - $("
" + sankoreLang.apple + "
").appendTo(text2); - var text3 = $("
"); - $("").appendTo(text3); - $("
" + sankoreLang.carrot + "
").appendTo(text3); - var text4 = $("
"); - $("").appendTo(text4); - $("
" + sankoreLang.pear + "
").appendTo(text4); - var text5 = $("
"); - $("").appendTo(text5); - $("
" + sankoreLang.onion + "
").appendTo(text5); + var img1 = $("
"); + $("").appendTo(img1); + $("").appendTo(img1); + var img2 = $("
"); + $("").appendTo(img2); + $("").appendTo(img2); + var img3 = $("
"); + $("").appendTo(img3); + $("").appendTo(img3); + var img4 = $("
"); + $("").appendTo(img4); + $("").appendTo(img4); + var img5 = $("
"); + $("").appendTo(img5); + $("").appendTo(img5); - tmp_array.push(text1, text2, text3, text4, text5); + tmp_array.push(img1, img2, img3, img4, img5); tmp_array = shuffle(tmp_array); for(var i = 0; i").insertBefore(source); - $("
").appendTo(text_block); - $("").appendTo(text_block); - $("
" + sankoreLang.text + "
").appendTo(text_block); -} - //function that allows to add new category function addCategory(obj){ var imgs_container = $("
").insertAfter(obj); @@ -540,9 +541,12 @@ function addCategory(obj){ $("").appendTo(imgs_container); var tmp_div = $("
").appendTo(imgs_container); $("").appendTo(tmp_div); - $("").appendTo(imgs_container); - $("").appendTo(imgs_container); - $("
").appendTo(imgs_container); + $("").appendTo(imgs_container); + $("").appendTo(imgs_container); + imgs_container.attr("ondragenter", "return false;") + .attr("ondragleave", "$(this).css(\"background-color\",\"\"); return false;") + .attr("ondragover", "$(this).css(\"background-color\",\"\"); return false;") + .attr("ondrop", "$(this).css(\"background-color\",\"\"); return onDropTarget(this,event);"); } //add new container @@ -558,9 +562,12 @@ function addContainer(){ $("").appendTo(imgs_container); var tmp_div = $("
").appendTo(imgs_container); $("").appendTo(tmp_div); - $("").appendTo(imgs_container); - $("").appendTo(imgs_container); - $("
").appendTo(imgs_container); + $("").appendTo(imgs_container); + $("").appendTo(imgs_container); + imgs_container.attr("ondragenter", "return false;") + .attr("ondragleave", "$(this).css(\"background-color\",\"\"); return false;") + .attr("ondragover", "$(this).css(\"background-color\",\"\"); return false;") + .attr("ondrop", "$(this).css(\"background-color\",\"\"); return onDropTarget(this,event);"); container.insertBefore($(".add_block")); } @@ -598,11 +605,6 @@ function stringToXML(text){ return doc; } -//return id -function returnId(){ - var tmp = Math.random().toString(); - return tmp.substr(2); -} //changing the style function changeStyle(val){ @@ -637,6 +639,12 @@ function changeStyle(val){ } } +//return id +function returnId(){ + var tmp = Math.random().toString(); + return tmp.substr(2); +} + //a func for checking when smth will drop function checkOnDrop(dest, source){ dest.append(source); @@ -692,3 +700,60 @@ function checkCorrectness(source){ .addClass("red_cont"); } } + +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 = $("
"); + $("
").appendTo(img_block); + $("").appendTo(img_block); + var tmp_img = $("").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"); + 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"); + tmp_img.css("margin",(120 - tmp_img.height())/2 + "px 0"); + } + } + } + exportData(); + } + else { + alert ("Your browser does not support the dataTransfer object."); + } + + if (event.stopPropagation) { + event.stopPropagation (); + } + else { + event.cancelBubble = true; + } + return false; +} diff --git a/resources/library/interactivities/Cat text.wgt/locales/ru/js/script.js b/resources/library/interactivities/Cat text.wgt/locales/ru/js/script.js index 7c66426b..778a3ad5 100644 --- a/resources/library/interactivities/Cat text.wgt/locales/ru/js/script.js +++ b/resources/library/interactivities/Cat text.wgt/locales/ru/js/script.js @@ -1,16 +1,10 @@ var sankoreLang = { display: "Показать", edit: "Изменить", - first_desc: "Фрукты", - second_desc: "Овощи", - potatoes: "Картофель", - carrot: "Морковь", - onion: "Лук", - apple: "Яблоко", - pear: "Груша", + first_desc: "Нечетные числа", + second_desc: "Четные числа", enter: "Введите название категории ...", add: "Новый блок", - text: "Какой-то текст", wgt_name: "Категории", reload: "Обновить", slate: "Узор", @@ -28,8 +22,8 @@ function start(){ $(".style_select option[value='2']").text(sankoreLang.pad); if(window.sankore){ - if(sankore.preference("categoriser_text","")){ - var data = jQuery.parseJSON(sankore.preference("categoriser_text","")); + if(sankore.preference("categoriser_images","")){ + var data = jQuery.parseJSON(sankore.preference("categoriser_images","")); importData(data); } else { showExample(); @@ -40,12 +34,21 @@ function start(){ if (window.widget) { window.widget.onleave = function(){ - //exportData(); + exportData(); } } $("#wgt_reload").click(function(){ - window.location.reload(); + 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(); }); $(".style_select").change(function (event){ @@ -58,6 +61,7 @@ function start(){ $(this).addClass("selected"); $("#wgt_edit").removeClass("selected"); $(".style_select").css("display","none"); + sankore.enableDropOnWidget(false); $(".add_block").remove(); $(".cont").each(function(){ var container = $(this); @@ -68,7 +72,6 @@ function start(){ container.find(".close_cont").remove(); container.find(".imgs_cont").each(function(){ $(this).find(".del_category").remove(); - $(this).find(".add_img").remove(); $(this).find(".add_category").remove(); $(this).removeAttr("ondragenter") .removeAttr("ondragleave") @@ -79,9 +82,6 @@ function start(){ $(this).find("input[name='count']").val(tmp_count); $(this).find(".img_block").each(function(){ $(this).find(".close_img").remove(); - var tmp_text = $(this).find(".text_cont"); - tmp_text.removeAttr("contenteditable") - .css("margin", ($(this).height() - tmp_text.height())/2 + "px 0px"); tmp_array.push($(this)); $(this).remove(); }); @@ -131,14 +131,19 @@ function start(){ $(this).addClass("selected"); $("#wgt_display").removeClass("selected"); $(".style_select").css("display","block"); + sankore.enableDropOnWidget(true); $(".cont").each(function(){ var container = $(this); $("
").appendTo(container); container.find(".imgs_cont").each(function(){ - $("").appendTo($(this)); - $("").appendTo($(this)); - $(this).removeClass("red_cont") + $("").appendTo($(this)); + $("").appendTo($(this)); + $(this).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);") + .removeClass("red_cont") .removeClass("green_cont") .addClass("def_cont") .droppable("destroy") @@ -146,15 +151,11 @@ function start(){ var tmp_img_cont = $(this); var tmp_mask = $(this).find("input[name='mask']").val(); container.find(".img_block").each(function(){ - $(this).draggable("destroy") - .find(".text_cont").attr("contenteditable","true") - .removeAttr("style"); if($(this).find("input").val() == tmp_mask){ $("
").appendTo($(this)); $(this).appendTo(tmp_img_cont); } }); - $("
").appendTo($(this)); }); container.find(".all_imgs").remove(); }); @@ -174,7 +175,7 @@ function start(){ //adding new img $(".add_img").live("click", function(){ - addText($(this).parent(), $(this)); + addImgBlock($(this)); }); //deleting a block @@ -202,26 +203,19 @@ function start(){ $(this).parent().remove(); } }); - - $(".text_cont").live("blur", function(){ - exportData(); - }).live("keyup", function(e){ - if (e.keyCode == 13) - exportData(); - }); } //export function exportData(){ var array_to_export = []; - if($("#wgt_edit").hasClass("selected")){ + if($("#edit").hasClass("selected")){ $(".cont").each(function(){ var cont_obj = new Object(); + cont_obj.style = $(".style_select").find("option:selected").val(); cont_obj.mode = "edit"; cont_obj.conts = []; $(this).find(".imgs_cont").each(function(){ var img_cont = new Object(); - cont_obj.style = $(".style_select").find("option:selected").val(); 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(); @@ -229,7 +223,10 @@ function exportData(){ $(this).find(".img_block").each(function(){ var img_obj = new Object(); img_obj.value = $(this).find("input").val(); - img_obj.text = $(this).find(".text_cont").text(); + img_obj.link = $(this).find("img").attr("src").replace("../../",""); + ; + 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); @@ -239,11 +236,11 @@ function exportData(){ } else { $(".cont").each(function(){ var cont_obj = new Object(); + cont_obj.style = $(".style_select").find("option:selected").val(); cont_obj.mode = "display"; cont_obj.conts = []; $(this).find(".imgs_cont").each(function(){ var img_cont = new Object(); - cont_obj.style = $(".style_select").find("option:selected").val(); 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(); @@ -251,7 +248,10 @@ function exportData(){ $(this).find(".img_block").each(function(){ var img_obj = new Object(); img_obj.value = $(this).find("input").val(); - img_obj.text = $(this).find(".text_cont").text(); + img_obj.link = $(this).find("img").attr("src").replace("../../",""); + ; + 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); @@ -260,7 +260,10 @@ function exportData(){ $(this).find(".all_imgs .img_block").each(function(){ var img = new Object(); img.value = $(this).find("input").val(); - img.text = $(this).find(".text_cont").text(); + img.link = $(this).find("img").attr("src").replace("../../",""); + ; + img.ht = $(this).find("img").height(); + img.wd = $(this).find("img").width(); cont_obj.all_imgs.push(img); }); array_to_export.push(cont_obj); @@ -274,7 +277,7 @@ function exportData(){ array_to_export.push(cont_obj); } - sankore.setPreference("categoriser_text", JSON.stringify(array_to_export)); + sankore.setPreference("categoriser_images", JSON.stringify(array_to_export)); } //import @@ -285,15 +288,14 @@ function importData(data){ if(data[i].tmp){ changeStyle(data[i].style); $(".style_select").val(data[i].style); - } - else { + } else { if(i == 0){ changeStyle(data[i].style); $(".style_select").val(data[i].style); } if(data[i].mode == "edit"){ var tmp_array = []; - var container = $("
").appendTo("#data"); + var container = $("
"); var sub_container = $("
").appendTo(container); $("
"+ (++tmp) +"
").appendTo(sub_container); @@ -306,8 +308,14 @@ function importData(data){ $("").appendTo(tmp_div); for(var k in data[i].conts[j].imgs){ var block_img = $("
"); - $("").appendTo(block_img); - $("
" + data[i].conts[j].imgs[k].text + "
").appendTo(block_img); + $("").appendTo(block_img); + var img = $("").appendTo(block_img); + if(data[i].conts[j].imgs[k].ht >= data[i].conts[j].imgs[k].wd) + img.attr("height", "120"); + else{ + img.attr("width","120"); + img.css("margin",(120 - data[i].conts[j].imgs[k].ht)/2 + "px 0"); + } tmp_array.push(block_img); } @@ -320,7 +328,7 @@ function importData(data){ checkCorrectness(tmp_ui); } } - }); + }); } var all_imgs = $("
").appendTo(container); @@ -333,8 +341,6 @@ function importData(data){ appendTo: '#data' }); tmp_array[j].appendTo(all_imgs); - var tmp_text = tmp_array[j].find(".text_cont"); - tmp_text.css("margin", (tmp_array[j].height() - tmp_text.height())/2 + "px 0px"); } all_imgs.sortable(); @@ -351,8 +357,10 @@ function importData(data){ } } }); + + container.appendTo("#data"); } else { - container = $("
").appendTo("#data"); + container = $("
"); sub_container = $("
").appendTo(container); $("
" + (++tmp) + "
").appendTo(sub_container); @@ -365,8 +373,14 @@ function importData(data){ $("").appendTo(tmp_div); for(k in data[i].conts[j].imgs){ block_img = $("
"); - $("").appendTo(block_img); - $("
" + data[i].conts[j].imgs[k].text + "
").appendTo(block_img); + $("").appendTo(block_img); + img = $("").appendTo(block_img); + if(data[i].conts[j].imgs[k].ht >= data[i].conts[j].imgs[k].wd) + img.attr("height", "120"); + else{ + img.attr("width","120"); + img.css("margin",(120 - data[i].conts[j].imgs[k].ht)/2 + "px 0"); + } tmp_img_array.push(block_img); } @@ -378,8 +392,6 @@ function importData(data){ appendTo: '#data' }); tmp_img_array[k].appendTo(imgs_container); - tmp_text = tmp_img_array[k].find(".text_cont"); - tmp_text.css("margin", (tmp_img_array[k].height() - tmp_text.height())/2 + "px 0px"); } imgs_container.droppable({ @@ -391,7 +403,7 @@ function importData(data){ checkCorrectness(tmp_ui); } } - }); + }); checkCorrectness(imgs_container); } @@ -399,8 +411,8 @@ function importData(data){ var all_imgs_arr = []; for(j in data[i].all_imgs){ block_img = $("
"); - $("").appendTo(block_img); - $("
" + data[i].all_imgs[j].text + "
").appendTo(block_img); + $("").appendTo(block_img); + $("").appendTo(block_img); all_imgs_arr.push(block_img); } @@ -412,8 +424,6 @@ function importData(data){ appendTo: '#data' }); all_imgs_arr[k].appendTo(all_imgs); - tmp_text = all_imgs_arr[k].find(".text_cont"); - tmp_text.css("margin", (all_imgs_arr[k].height() - tmp_text.height())/2 + "px 0px"); } all_imgs.sortable(); @@ -430,6 +440,7 @@ function importData(data){ } } }); + container.appendTo("#data"); } } } @@ -459,23 +470,23 @@ function showExample(){ var tmp_div_two = $("
").appendTo(imgs_container_two); $("").appendTo(tmp_div_two); - var text1 = $("
"); - $("").appendTo(text1); - $("
" + sankoreLang.potatoes + "
").appendTo(text1); - var text2 = $("
"); - $("").appendTo(text2); - $("
" + sankoreLang.apple + "
").appendTo(text2); - var text3 = $("
"); - $("").appendTo(text3); - $("
" + sankoreLang.carrot + "
").appendTo(text3); - var text4 = $("
"); - $("").appendTo(text4); - $("
" + sankoreLang.pear + "
").appendTo(text4); - var text5 = $("
"); - $("").appendTo(text5); - $("
" + sankoreLang.onion + "
").appendTo(text5); + var img1 = $("
"); + $("").appendTo(img1); + $("").appendTo(img1); + var img2 = $("
"); + $("").appendTo(img2); + $("").appendTo(img2); + var img3 = $("
"); + $("").appendTo(img3); + $("").appendTo(img3); + var img4 = $("
"); + $("").appendTo(img4); + $("").appendTo(img4); + var img5 = $("
"); + $("").appendTo(img5); + $("").appendTo(img5); - tmp_array.push(text1, text2, text3, text4, text5); + tmp_array.push(img1, img2, img3, img4, img5); tmp_array = shuffle(tmp_array); for(var i = 0; i").insertBefore(source); - $("
").appendTo(text_block); - $("").appendTo(text_block); - $("
" + sankoreLang.text + "
").appendTo(text_block); -} - //function that allows to add new category function addCategory(obj){ var imgs_container = $("
").insertAfter(obj); @@ -540,9 +541,12 @@ function addCategory(obj){ $("").appendTo(imgs_container); var tmp_div = $("
").appendTo(imgs_container); $("").appendTo(tmp_div); - $("").appendTo(imgs_container); - $("").appendTo(imgs_container); - $("
").appendTo(imgs_container); + $("").appendTo(imgs_container); + $("").appendTo(imgs_container); + imgs_container.attr("ondragenter", "return false;") + .attr("ondragleave", "$(this).css(\"background-color\",\"\"); return false;") + .attr("ondragover", "$(this).css(\"background-color\",\"\"); return false;") + .attr("ondrop", "$(this).css(\"background-color\",\"\"); return onDropTarget(this,event);"); } //add new container @@ -558,9 +562,12 @@ function addContainer(){ $("").appendTo(imgs_container); var tmp_div = $("
").appendTo(imgs_container); $("").appendTo(tmp_div); - $("").appendTo(imgs_container); - $("").appendTo(imgs_container); - $("
").appendTo(imgs_container); + $("").appendTo(imgs_container); + $("").appendTo(imgs_container); + imgs_container.attr("ondragenter", "return false;") + .attr("ondragleave", "$(this).css(\"background-color\",\"\"); return false;") + .attr("ondragover", "$(this).css(\"background-color\",\"\"); return false;") + .attr("ondrop", "$(this).css(\"background-color\",\"\"); return onDropTarget(this,event);"); container.insertBefore($(".add_block")); } @@ -598,11 +605,6 @@ function stringToXML(text){ return doc; } -//return id -function returnId(){ - var tmp = Math.random().toString(); - return tmp.substr(2); -} //changing the style function changeStyle(val){ @@ -637,6 +639,12 @@ function changeStyle(val){ } } +//return id +function returnId(){ + var tmp = Math.random().toString(); + return tmp.substr(2); +} + //a func for checking when smth will drop function checkOnDrop(dest, source){ dest.append(source); @@ -691,4 +699,61 @@ function checkCorrectness(source){ .removeClass("green_cont") .addClass("red_cont"); } +} + +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 = $("
"); + $("
").appendTo(img_block); + $("").appendTo(img_block); + var tmp_img = $("").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"); + 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"); + tmp_img.css("margin",(120 - tmp_img.height())/2 + "px 0"); + } + } + } + exportData(); + } + else { + alert ("Your browser does not support the dataTransfer object."); + } + + if (event.stopPropagation) { + event.stopPropagation (); + } + else { + event.cancelBubble = true; + } + return false; } \ No newline at end of file From b95a57f36465de76f12b4b15ade3c2eedd68805d Mon Sep 17 00:00:00 2001 From: unknown Date: Mon, 25 Jun 2012 16:47:19 +0200 Subject: [PATCH 2/4] fixed cat images widget --- .../Cat images.wgt/js/script.js | 19 ++++++++++++++----- .../Cat images.wgt/locales/fr/js/script.js | 19 ++++++++++++++----- .../Cat images.wgt/locales/ru/js/script.js | 19 ++++++++++++++----- 3 files changed, 42 insertions(+), 15 deletions(-) diff --git a/resources/library/interactivities/Cat images.wgt/js/script.js b/resources/library/interactivities/Cat images.wgt/js/script.js index 14b54c79..7f8ca614 100644 --- a/resources/library/interactivities/Cat images.wgt/js/script.js +++ b/resources/library/interactivities/Cat images.wgt/js/script.js @@ -34,12 +34,21 @@ function start(){ if (window.widget) { window.widget.onleave = function(){ - //exportData(); + exportData(); } } $("#wgt_reload").click(function(){ - window.location.reload(); + 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(); }); $(".style_select").change(function (event){ @@ -131,9 +140,9 @@ function start(){ $("").appendTo($(this)); $("").appendTo($(this)); $(this).attr("ondragenter", "return false;") - .attr("ondragleave", "$(this).css(\"background-color\",\"\"); return false;") - .attr("ondragover", "$(this).css(\"background-color\",\"\"); return false;") - .attr("ondrop", "$(this).css(\"background-color\",\"\"); return onDropTarget(this,event);") + .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);") .removeClass("red_cont") .removeClass("green_cont") .addClass("def_cont") diff --git a/resources/library/interactivities/Cat images.wgt/locales/fr/js/script.js b/resources/library/interactivities/Cat images.wgt/locales/fr/js/script.js index 371d2623..8cf62916 100644 --- a/resources/library/interactivities/Cat images.wgt/locales/fr/js/script.js +++ b/resources/library/interactivities/Cat images.wgt/locales/fr/js/script.js @@ -34,12 +34,21 @@ function start(){ if (window.widget) { window.widget.onleave = function(){ - //exportData(); + exportData(); } } $("#wgt_reload").click(function(){ - window.location.reload(); + 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(); }); $(".style_select").change(function (event){ @@ -131,9 +140,9 @@ function start(){ $("").appendTo($(this)); $("").appendTo($(this)); $(this).attr("ondragenter", "return false;") - .attr("ondragleave", "$(this).css(\"background-color\",\"\"); return false;") - .attr("ondragover", "$(this).css(\"background-color\",\"\"); return false;") - .attr("ondrop", "$(this).css(\"background-color\",\"\"); return onDropTarget(this,event);") + .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);") .removeClass("red_cont") .removeClass("green_cont") .addClass("def_cont") diff --git a/resources/library/interactivities/Cat images.wgt/locales/ru/js/script.js b/resources/library/interactivities/Cat images.wgt/locales/ru/js/script.js index d1f8f5fd..778a3ad5 100644 --- a/resources/library/interactivities/Cat images.wgt/locales/ru/js/script.js +++ b/resources/library/interactivities/Cat images.wgt/locales/ru/js/script.js @@ -34,12 +34,21 @@ function start(){ if (window.widget) { window.widget.onleave = function(){ - //exportData(); + exportData(); } } $("#wgt_reload").click(function(){ - window.location.reload(); + 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(); }); $(".style_select").change(function (event){ @@ -131,9 +140,9 @@ function start(){ $("").appendTo($(this)); $("").appendTo($(this)); $(this).attr("ondragenter", "return false;") - .attr("ondragleave", "$(this).css(\"background-color\",\"\"); return false;") - .attr("ondragover", "$(this).css(\"background-color\",\"\"); return false;") - .attr("ondrop", "$(this).css(\"background-color\",\"\"); return onDropTarget(this,event);") + .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);") .removeClass("red_cont") .removeClass("green_cont") .addClass("def_cont") From 92323f105ced71c227be6cb3c8576b27df5c360b Mon Sep 17 00:00:00 2001 From: unknown Date: Mon, 25 Jun 2012 16:54:24 +0200 Subject: [PATCH 3/4] fixed cat texte widget --- .../interactivities/Cat text.wgt/js/script.js | 251 +++++++----------- .../Cat text.wgt/locales/fr/js/script.js | 239 ++++++----------- .../Cat text.wgt/locales/ru/js/script.js | 231 ++++++---------- 3 files changed, 268 insertions(+), 453 deletions(-) diff --git a/resources/library/interactivities/Cat text.wgt/js/script.js b/resources/library/interactivities/Cat text.wgt/js/script.js index 7f8ca614..d054d43d 100644 --- a/resources/library/interactivities/Cat text.wgt/js/script.js +++ b/resources/library/interactivities/Cat text.wgt/js/script.js @@ -1,11 +1,17 @@ var sankoreLang = { display: "Display", edit: "Edit", - first_desc: "Odd numbers", - second_desc: "Even numbers", + first_desc: "Fruits", + second_desc: "Vegetables", + potatoes: "Potato", + carrot: "Carrot", + onion: "Onion", + apple: "Apple", + pear: "Pear", enter: "Enter your category name here ...", add: "Add new block", - wgt_name: "Order images", + text: "Some text", + wgt_name: "Categorize text", reload: "Reload", slate: "Wood", pad: "Pad" @@ -22,8 +28,8 @@ function start(){ $(".style_select option[value='2']").text(sankoreLang.pad); if(window.sankore){ - if(sankore.preference("categoriser_images","")){ - var data = jQuery.parseJSON(sankore.preference("categoriser_images","")); + if(sankore.preference("categoriser_text","")){ + var data = jQuery.parseJSON(sankore.preference("categoriser_text","")); importData(data); } else { showExample(); @@ -61,7 +67,6 @@ function start(){ $(this).addClass("selected"); $("#wgt_edit").removeClass("selected"); $(".style_select").css("display","none"); - sankore.enableDropOnWidget(false); $(".add_block").remove(); $(".cont").each(function(){ var container = $(this); @@ -72,6 +77,7 @@ function start(){ container.find(".close_cont").remove(); container.find(".imgs_cont").each(function(){ $(this).find(".del_category").remove(); + $(this).find(".add_img").remove(); $(this).find(".add_category").remove(); $(this).removeAttr("ondragenter") .removeAttr("ondragleave") @@ -82,6 +88,9 @@ function start(){ $(this).find("input[name='count']").val(tmp_count); $(this).find(".img_block").each(function(){ $(this).find(".close_img").remove(); + var tmp_text = $(this).find(".text_cont"); + tmp_text.removeAttr("contenteditable") + .css("margin", ($(this).height() - tmp_text.height())/2 + "px 0px"); tmp_array.push($(this)); $(this).remove(); }); @@ -131,19 +140,14 @@ function start(){ $(this).addClass("selected"); $("#wgt_display").removeClass("selected"); $(".style_select").css("display","block"); - sankore.enableDropOnWidget(true); $(".cont").each(function(){ var container = $(this); $("
").appendTo(container); container.find(".imgs_cont").each(function(){ - $("").appendTo($(this)); - $("").appendTo($(this)); - $(this).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);") - .removeClass("red_cont") + $("").appendTo($(this)); + $("").appendTo($(this)); + $(this).removeClass("red_cont") .removeClass("green_cont") .addClass("def_cont") .droppable("destroy") @@ -151,11 +155,15 @@ function start(){ var tmp_img_cont = $(this); var tmp_mask = $(this).find("input[name='mask']").val(); container.find(".img_block").each(function(){ + $(this).draggable("destroy") + .find(".text_cont").attr("contenteditable","true") + .removeAttr("style"); if($(this).find("input").val() == tmp_mask){ $("
").appendTo($(this)); $(this).appendTo(tmp_img_cont); } }); + $("
").appendTo($(this)); }); container.find(".all_imgs").remove(); }); @@ -175,7 +183,7 @@ function start(){ //adding new img $(".add_img").live("click", function(){ - addImgBlock($(this)); + addText($(this).parent(), $(this)); }); //deleting a block @@ -208,14 +216,14 @@ function start(){ //export function exportData(){ var array_to_export = []; - if($("#edit").hasClass("selected")){ + if($("#wgt_edit").hasClass("selected")){ $(".cont").each(function(){ var cont_obj = new Object(); - cont_obj.style = $(".style_select").find("option:selected").val(); cont_obj.mode = "edit"; cont_obj.conts = []; $(this).find(".imgs_cont").each(function(){ var img_cont = new Object(); + cont_obj.style = $(".style_select").find("option:selected").val(); 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(); @@ -223,9 +231,7 @@ function exportData(){ $(this).find(".img_block").each(function(){ var img_obj = new Object(); img_obj.value = $(this).find("input").val(); - img_obj.link = $(this).find("img").attr("src"); - img_obj.ht = $(this).find("img").height(); - img_obj.wd = $(this).find("img").width(); + img_obj.text = $(this).find(".text_cont").text(); img_cont.imgs.push(img_obj); }); cont_obj.conts.push(img_cont); @@ -235,11 +241,11 @@ function exportData(){ } else { $(".cont").each(function(){ var cont_obj = new Object(); - cont_obj.style = $(".style_select").find("option:selected").val(); cont_obj.mode = "display"; cont_obj.conts = []; $(this).find(".imgs_cont").each(function(){ var img_cont = new Object(); + cont_obj.style = $(".style_select").find("option:selected").val(); 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(); @@ -247,9 +253,7 @@ function exportData(){ $(this).find(".img_block").each(function(){ var img_obj = new Object(); img_obj.value = $(this).find("input").val(); - img_obj.link = $(this).find("img").attr("src"); - img_obj.ht = $(this).find("img").height(); - img_obj.wd = $(this).find("img").width(); + img_obj.text = $(this).find(".text_cont").text(); img_cont.imgs.push(img_obj); }); cont_obj.conts.push(img_cont); @@ -258,9 +262,7 @@ function exportData(){ $(this).find(".all_imgs .img_block").each(function(){ var img = new Object(); img.value = $(this).find("input").val(); - img.link = $(this).find("img").attr("src"); - img.ht = $(this).find("img").height(); - img.wd = $(this).find("img").width(); + img.text = $(this).find(".text_cont").text(); cont_obj.all_imgs.push(img); }); array_to_export.push(cont_obj); @@ -274,7 +276,7 @@ function exportData(){ array_to_export.push(cont_obj); } - sankore.setPreference("categoriser_images", JSON.stringify(array_to_export)); + sankore.setPreference("categoriser_text", JSON.stringify(array_to_export)); } //import @@ -285,14 +287,15 @@ function importData(data){ if(data[i].tmp){ changeStyle(data[i].style); $(".style_select").val(data[i].style); - } else { + } + else { if(i == 0){ changeStyle(data[i].style); $(".style_select").val(data[i].style); } if(data[i].mode == "edit"){ var tmp_array = []; - var container = $("
"); + var container = $("
").appendTo("#data"); var sub_container = $("
").appendTo(container); $("
"+ (++tmp) +"
").appendTo(sub_container); @@ -305,14 +308,8 @@ function importData(data){ $("").appendTo(tmp_div); for(var k in data[i].conts[j].imgs){ var block_img = $("
"); - $("").appendTo(block_img); - var img = $("").appendTo(block_img); - if(data[i].conts[j].imgs[k].ht >= data[i].conts[j].imgs[k].wd) - img.attr("height", "120"); - else{ - img.attr("width","120"); - img.css("margin",(120 - data[i].conts[j].imgs[k].ht)/2 + "px 0"); - } + $("").appendTo(block_img); + $("
" + data[i].conts[j].imgs[k].text + "
").appendTo(block_img); tmp_array.push(block_img); } @@ -338,6 +335,8 @@ function importData(data){ appendTo: '#data' }); tmp_array[j].appendTo(all_imgs); + var tmp_text = tmp_array[j].find(".text_cont"); + tmp_text.css("margin", (tmp_array[j].height() - tmp_text.height())/2 + "px 0px"); } all_imgs.sortable(); @@ -354,10 +353,8 @@ function importData(data){ } } }); - - container.appendTo("#data"); } else { - container = $("
"); + container = $("
").appendTo("#data"); sub_container = $("
").appendTo(container); $("
" + (++tmp) + "
").appendTo(sub_container); @@ -370,14 +367,8 @@ function importData(data){ $("").appendTo(tmp_div); for(k in data[i].conts[j].imgs){ block_img = $("
"); - $("").appendTo(block_img); - img = $("").appendTo(block_img); - if(data[i].conts[j].imgs[k].ht >= data[i].conts[j].imgs[k].wd) - img.attr("height", "120"); - else{ - img.attr("width","120"); - img.css("margin",(120 - data[i].conts[j].imgs[k].ht)/2 + "px 0"); - } + $("").appendTo(block_img); + $("
" + data[i].conts[j].imgs[k].text + "
").appendTo(block_img); tmp_img_array.push(block_img); } @@ -389,6 +380,8 @@ function importData(data){ appendTo: '#data' }); tmp_img_array[k].appendTo(imgs_container); + tmp_text = tmp_img_array[k].find(".text_cont"); + tmp_text.css("margin", (tmp_img_array[k].height() - tmp_text.height())/2 + "px 0px"); } imgs_container.droppable({ @@ -408,8 +401,8 @@ function importData(data){ var all_imgs_arr = []; for(j in data[i].all_imgs){ block_img = $("
"); - $("").appendTo(block_img); - $("").appendTo(block_img); + $("").appendTo(block_img); + $("
" + data[i].all_imgs[j].text + "
").appendTo(block_img); all_imgs_arr.push(block_img); } @@ -421,6 +414,8 @@ function importData(data){ appendTo: '#data' }); all_imgs_arr[k].appendTo(all_imgs); + tmp_text = all_imgs_arr[k].find(".text_cont"); + tmp_text.css("margin", (all_imgs_arr[k].height() - tmp_text.height())/2 + "px 0px"); } all_imgs.sortable(); @@ -437,7 +432,6 @@ function importData(data){ } } }); - container.appendTo("#data"); } } } @@ -467,23 +461,23 @@ function showExample(){ var tmp_div_two = $("
").appendTo(imgs_container_two); $("").appendTo(tmp_div_two); - var img1 = $("
"); - $("").appendTo(img1); - $("").appendTo(img1); - var img2 = $("
"); - $("").appendTo(img2); - $("").appendTo(img2); - var img3 = $("
"); - $("").appendTo(img3); - $("").appendTo(img3); - var img4 = $("
"); - $("").appendTo(img4); - $("").appendTo(img4); - var img5 = $("
"); - $("").appendTo(img5); - $("").appendTo(img5); + var text1 = $("
"); + $("").appendTo(text1); + $("
" + sankoreLang.potatoes + "
").appendTo(text1); + var text2 = $("
"); + $("").appendTo(text2); + $("
" + sankoreLang.apple + "
").appendTo(text2); + var text3 = $("
"); + $("").appendTo(text3); + $("
" + sankoreLang.carrot + "
").appendTo(text3); + var text4 = $("
"); + $("").appendTo(text4); + $("
" + sankoreLang.pear + "
").appendTo(text4); + var text5 = $("
"); + $("").appendTo(text5); + $("
" + sankoreLang.onion + "
").appendTo(text5); - tmp_array.push(img1, img2, img3, img4, img5); + tmp_array.push(text1, text2, text3, text4, text5); tmp_array = shuffle(tmp_array); for(var i = 0; i").insertBefore(source); + $("
").appendTo(text_block); + $("").appendTo(text_block); + $("
" + sankoreLang.text + "
").appendTo(text_block); +} + //function that allows to add new category function addCategory(obj){ var imgs_container = $("
").insertAfter(obj); @@ -538,12 +542,9 @@ function addCategory(obj){ $("").appendTo(imgs_container); var tmp_div = $("
").appendTo(imgs_container); $("").appendTo(tmp_div); - $("").appendTo(imgs_container); - $("").appendTo(imgs_container); - imgs_container.attr("ondragenter", "return false;") - .attr("ondragleave", "$(this).css(\"background-color\",\"\"); return false;") - .attr("ondragover", "$(this).css(\"background-color\",\"\"); return false;") - .attr("ondrop", "$(this).css(\"background-color\",\"\"); return onDropTarget(this,event);"); + $("").appendTo(imgs_container); + $("").appendTo(imgs_container); + $("
").appendTo(imgs_container); } //add new container @@ -559,12 +560,9 @@ function addContainer(){ $("").appendTo(imgs_container); var tmp_div = $("
").appendTo(imgs_container); $("").appendTo(tmp_div); - $("").appendTo(imgs_container); - $("").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);"); + $("").appendTo(imgs_container); + $("").appendTo(imgs_container); + $("
").appendTo(imgs_container); container.insertBefore($(".add_block")); } @@ -590,6 +588,24 @@ function shuffle( arr ) return arr; } +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; +} + +//return id +function returnId(){ + var tmp = Math.random().toString(); + return tmp.substr(2); +} + //changing the style function changeStyle(val){ if(val == 1){ @@ -623,24 +639,6 @@ function changeStyle(val){ } } -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; -} - -//return id -function returnId(){ - var tmp = Math.random().toString(); - return tmp.substr(2); -} - //a func for checking when smth will drop function checkOnDrop(dest, source){ dest.append(source); @@ -696,60 +694,3 @@ function checkCorrectness(source){ .addClass("red_cont"); } } - -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 = $("
"); - $("
").appendTo(img_block); - $("").appendTo(img_block); - var tmp_img = $("").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"); - 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"); - tmp_img.css("margin",(120 - tmp_img.height())/2 + "px 0"); - } - } - } - exportData(); - } - else { - alert ("Your browser does not support the dataTransfer object."); - } - - if (event.stopPropagation) { - event.stopPropagation (); - } - else { - event.cancelBubble = true; - } - return false; -} diff --git a/resources/library/interactivities/Cat text.wgt/locales/fr/js/script.js b/resources/library/interactivities/Cat text.wgt/locales/fr/js/script.js index 8cf62916..db9544e3 100644 --- a/resources/library/interactivities/Cat text.wgt/locales/fr/js/script.js +++ b/resources/library/interactivities/Cat text.wgt/locales/fr/js/script.js @@ -1,14 +1,20 @@ var sankoreLang = { display: "Afficher", - edit: "Modifier", - first_desc: "Les nombres impairs", - second_desc: "Les nombres pairs", + edit: "Modifier", + first_desc: "Fruits", + second_desc: "Légumes", + potatoes: "Pomme de terre", + carrot: "Carotte", + onion: "Oignon", + apple: "Pomme", + pear: "Poire", enter: "Saisir le nom de la catégorie ici ...", add: "Nouveau bloc", - wgt_name: "Catégoriser des images", + text: "Texte", + wgt_name: "Catégoriser des textes", reload: "Recharger", - slate: "Ardoise", - pad: "Tablette" + slate: "Bois", + pad: "Pad" }; //main function @@ -22,8 +28,8 @@ function start(){ $(".style_select option[value='2']").text(sankoreLang.pad); if(window.sankore){ - if(sankore.preference("categoriser_images","")){ - var data = jQuery.parseJSON(sankore.preference("categoriser_images","")); + if(sankore.preference("categoriser_text","")){ + var data = jQuery.parseJSON(sankore.preference("categoriser_text","")); importData(data); } else { showExample(); @@ -61,7 +67,6 @@ function start(){ $(this).addClass("selected"); $("#wgt_edit").removeClass("selected"); $(".style_select").css("display","none"); - sankore.enableDropOnWidget(false); $(".add_block").remove(); $(".cont").each(function(){ var container = $(this); @@ -72,6 +77,7 @@ function start(){ container.find(".close_cont").remove(); container.find(".imgs_cont").each(function(){ $(this).find(".del_category").remove(); + $(this).find(".add_img").remove(); $(this).find(".add_category").remove(); $(this).removeAttr("ondragenter") .removeAttr("ondragleave") @@ -82,6 +88,9 @@ function start(){ $(this).find("input[name='count']").val(tmp_count); $(this).find(".img_block").each(function(){ $(this).find(".close_img").remove(); + var tmp_text = $(this).find(".text_cont"); + tmp_text.removeAttr("contenteditable") + .css("margin", ($(this).height() - tmp_text.height())/2 + "px 0px"); tmp_array.push($(this)); $(this).remove(); }); @@ -131,19 +140,14 @@ function start(){ $(this).addClass("selected"); $("#wgt_display").removeClass("selected"); $(".style_select").css("display","block"); - sankore.enableDropOnWidget(true); $(".cont").each(function(){ var container = $(this); $("
").appendTo(container); container.find(".imgs_cont").each(function(){ - $("").appendTo($(this)); - $("").appendTo($(this)); - $(this).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);") - .removeClass("red_cont") + $("").appendTo($(this)); + $("").appendTo($(this)); + $(this).removeClass("red_cont") .removeClass("green_cont") .addClass("def_cont") .droppable("destroy") @@ -151,11 +155,15 @@ function start(){ var tmp_img_cont = $(this); var tmp_mask = $(this).find("input[name='mask']").val(); container.find(".img_block").each(function(){ + $(this).draggable("destroy") + .find(".text_cont").attr("contenteditable","true") + .removeAttr("style"); if($(this).find("input").val() == tmp_mask){ $("
").appendTo($(this)); $(this).appendTo(tmp_img_cont); } }); + $("
").appendTo($(this)); }); container.find(".all_imgs").remove(); }); @@ -175,7 +183,7 @@ function start(){ //adding new img $(".add_img").live("click", function(){ - addImgBlock($(this)); + addText($(this).parent(), $(this)); }); //deleting a block @@ -208,14 +216,14 @@ function start(){ //export function exportData(){ var array_to_export = []; - if($("#edit").hasClass("selected")){ + if($("#wgt_edit").hasClass("selected")){ $(".cont").each(function(){ var cont_obj = new Object(); - cont_obj.style = $(".style_select").find("option:selected").val(); cont_obj.mode = "edit"; cont_obj.conts = []; $(this).find(".imgs_cont").each(function(){ var img_cont = new Object(); + cont_obj.style = $(".style_select").find("option:selected").val(); 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(); @@ -223,10 +231,7 @@ function exportData(){ $(this).find(".img_block").each(function(){ var img_obj = new Object(); img_obj.value = $(this).find("input").val(); - img_obj.link = $(this).find("img").attr("src").replace("../../",""); - ; - img_obj.ht = $(this).find("img").height(); - img_obj.wd = $(this).find("img").width(); + img_obj.text = $(this).find(".text_cont").text(); img_cont.imgs.push(img_obj); }); cont_obj.conts.push(img_cont); @@ -236,11 +241,11 @@ function exportData(){ } else { $(".cont").each(function(){ var cont_obj = new Object(); - cont_obj.style = $(".style_select").find("option:selected").val(); cont_obj.mode = "display"; cont_obj.conts = []; $(this).find(".imgs_cont").each(function(){ var img_cont = new Object(); + cont_obj.style = $(".style_select").find("option:selected").val(); 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(); @@ -248,10 +253,7 @@ function exportData(){ $(this).find(".img_block").each(function(){ var img_obj = new Object(); img_obj.value = $(this).find("input").val(); - img_obj.link = $(this).find("img").attr("src").replace("../../",""); - ; - img_obj.ht = $(this).find("img").height(); - img_obj.wd = $(this).find("img").width(); + img_obj.text = $(this).find(".text_cont").text(); img_cont.imgs.push(img_obj); }); cont_obj.conts.push(img_cont); @@ -260,10 +262,7 @@ function exportData(){ $(this).find(".all_imgs .img_block").each(function(){ var img = new Object(); img.value = $(this).find("input").val(); - img.link = $(this).find("img").attr("src").replace("../../",""); - ; - img.ht = $(this).find("img").height(); - img.wd = $(this).find("img").width(); + img.text = $(this).find(".text_cont").text(); cont_obj.all_imgs.push(img); }); array_to_export.push(cont_obj); @@ -277,7 +276,7 @@ function exportData(){ array_to_export.push(cont_obj); } - sankore.setPreference("categoriser_images", JSON.stringify(array_to_export)); + sankore.setPreference("categoriser_text", JSON.stringify(array_to_export)); } //import @@ -288,14 +287,15 @@ function importData(data){ if(data[i].tmp){ changeStyle(data[i].style); $(".style_select").val(data[i].style); - } else { + } + else { if(i == 0){ changeStyle(data[i].style); $(".style_select").val(data[i].style); } if(data[i].mode == "edit"){ var tmp_array = []; - var container = $("
"); + var container = $("
").appendTo("#data"); var sub_container = $("
").appendTo(container); $("
"+ (++tmp) +"
").appendTo(sub_container); @@ -308,14 +308,8 @@ function importData(data){ $("").appendTo(tmp_div); for(var k in data[i].conts[j].imgs){ var block_img = $("
"); - $("").appendTo(block_img); - var img = $("").appendTo(block_img); - if(data[i].conts[j].imgs[k].ht >= data[i].conts[j].imgs[k].wd) - img.attr("height", "120"); - else{ - img.attr("width","120"); - img.css("margin",(120 - data[i].conts[j].imgs[k].ht)/2 + "px 0"); - } + $("").appendTo(block_img); + $("
" + data[i].conts[j].imgs[k].text + "
").appendTo(block_img); tmp_array.push(block_img); } @@ -328,7 +322,7 @@ function importData(data){ checkCorrectness(tmp_ui); } } - }); + }); } var all_imgs = $("
").appendTo(container); @@ -341,6 +335,8 @@ function importData(data){ appendTo: '#data' }); tmp_array[j].appendTo(all_imgs); + var tmp_text = tmp_array[j].find(".text_cont"); + tmp_text.css("margin", (tmp_array[j].height() - tmp_text.height())/2 + "px 0px"); } all_imgs.sortable(); @@ -357,10 +353,8 @@ function importData(data){ } } }); - - container.appendTo("#data"); } else { - container = $("
"); + container = $("
").appendTo("#data"); sub_container = $("
").appendTo(container); $("
" + (++tmp) + "
").appendTo(sub_container); @@ -373,14 +367,8 @@ function importData(data){ $("").appendTo(tmp_div); for(k in data[i].conts[j].imgs){ block_img = $("
"); - $("").appendTo(block_img); - img = $("").appendTo(block_img); - if(data[i].conts[j].imgs[k].ht >= data[i].conts[j].imgs[k].wd) - img.attr("height", "120"); - else{ - img.attr("width","120"); - img.css("margin",(120 - data[i].conts[j].imgs[k].ht)/2 + "px 0"); - } + $("").appendTo(block_img); + $("
" + data[i].conts[j].imgs[k].text + "
").appendTo(block_img); tmp_img_array.push(block_img); } @@ -392,6 +380,8 @@ function importData(data){ appendTo: '#data' }); tmp_img_array[k].appendTo(imgs_container); + tmp_text = tmp_img_array[k].find(".text_cont"); + tmp_text.css("margin", (tmp_img_array[k].height() - tmp_text.height())/2 + "px 0px"); } imgs_container.droppable({ @@ -403,7 +393,7 @@ function importData(data){ checkCorrectness(tmp_ui); } } - }); + }); checkCorrectness(imgs_container); } @@ -411,8 +401,8 @@ function importData(data){ var all_imgs_arr = []; for(j in data[i].all_imgs){ block_img = $("
"); - $("").appendTo(block_img); - $("").appendTo(block_img); + $("").appendTo(block_img); + $("
" + data[i].all_imgs[j].text + "
").appendTo(block_img); all_imgs_arr.push(block_img); } @@ -424,6 +414,8 @@ function importData(data){ appendTo: '#data' }); all_imgs_arr[k].appendTo(all_imgs); + tmp_text = all_imgs_arr[k].find(".text_cont"); + tmp_text.css("margin", (all_imgs_arr[k].height() - tmp_text.height())/2 + "px 0px"); } all_imgs.sortable(); @@ -440,7 +432,6 @@ function importData(data){ } } }); - container.appendTo("#data"); } } } @@ -470,23 +461,23 @@ function showExample(){ var tmp_div_two = $("
").appendTo(imgs_container_two); $("").appendTo(tmp_div_two); - var img1 = $("
"); - $("").appendTo(img1); - $("").appendTo(img1); - var img2 = $("
"); - $("").appendTo(img2); - $("").appendTo(img2); - var img3 = $("
"); - $("").appendTo(img3); - $("").appendTo(img3); - var img4 = $("
"); - $("").appendTo(img4); - $("").appendTo(img4); - var img5 = $("
"); - $("").appendTo(img5); - $("").appendTo(img5); + var text1 = $("
"); + $("").appendTo(text1); + $("
" + sankoreLang.potatoes + "
").appendTo(text1); + var text2 = $("
"); + $("").appendTo(text2); + $("
" + sankoreLang.apple + "
").appendTo(text2); + var text3 = $("
"); + $("").appendTo(text3); + $("
" + sankoreLang.carrot + "
").appendTo(text3); + var text4 = $("
"); + $("").appendTo(text4); + $("
" + sankoreLang.pear + "
").appendTo(text4); + var text5 = $("
"); + $("").appendTo(text5); + $("
" + sankoreLang.onion + "
").appendTo(text5); - tmp_array.push(img1, img2, img3, img4, img5); + tmp_array.push(text1, text2, text3, text4, text5); tmp_array = shuffle(tmp_array); for(var i = 0; i").insertBefore(source); + $("
").appendTo(text_block); + $("").appendTo(text_block); + $("
" + sankoreLang.text + "
").appendTo(text_block); +} + //function that allows to add new category function addCategory(obj){ var imgs_container = $("
").insertAfter(obj); @@ -541,12 +542,9 @@ function addCategory(obj){ $("").appendTo(imgs_container); var tmp_div = $("
").appendTo(imgs_container); $("").appendTo(tmp_div); - $("").appendTo(imgs_container); - $("").appendTo(imgs_container); - imgs_container.attr("ondragenter", "return false;") - .attr("ondragleave", "$(this).css(\"background-color\",\"\"); return false;") - .attr("ondragover", "$(this).css(\"background-color\",\"\"); return false;") - .attr("ondrop", "$(this).css(\"background-color\",\"\"); return onDropTarget(this,event);"); + $("").appendTo(imgs_container); + $("").appendTo(imgs_container); + $("
").appendTo(imgs_container); } //add new container @@ -562,12 +560,9 @@ function addContainer(){ $("").appendTo(imgs_container); var tmp_div = $("
").appendTo(imgs_container); $("").appendTo(tmp_div); - $("").appendTo(imgs_container); - $("").appendTo(imgs_container); - imgs_container.attr("ondragenter", "return false;") - .attr("ondragleave", "$(this).css(\"background-color\",\"\"); return false;") - .attr("ondragover", "$(this).css(\"background-color\",\"\"); return false;") - .attr("ondrop", "$(this).css(\"background-color\",\"\"); return onDropTarget(this,event);"); + $("").appendTo(imgs_container); + $("").appendTo(imgs_container); + $("
").appendTo(imgs_container); container.insertBefore($(".add_block")); } @@ -605,6 +600,11 @@ function stringToXML(text){ return doc; } +//return id +function returnId(){ + var tmp = Math.random().toString(); + return tmp.substr(2); +} //changing the style function changeStyle(val){ @@ -639,12 +639,6 @@ function changeStyle(val){ } } -//return id -function returnId(){ - var tmp = Math.random().toString(); - return tmp.substr(2); -} - //a func for checking when smth will drop function checkOnDrop(dest, source){ dest.append(source); @@ -700,60 +694,3 @@ function checkCorrectness(source){ .addClass("red_cont"); } } - -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 = $("
"); - $("
").appendTo(img_block); - $("").appendTo(img_block); - var tmp_img = $("").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"); - 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"); - tmp_img.css("margin",(120 - tmp_img.height())/2 + "px 0"); - } - } - } - exportData(); - } - else { - alert ("Your browser does not support the dataTransfer object."); - } - - if (event.stopPropagation) { - event.stopPropagation (); - } - else { - event.cancelBubble = true; - } - return false; -} diff --git a/resources/library/interactivities/Cat text.wgt/locales/ru/js/script.js b/resources/library/interactivities/Cat text.wgt/locales/ru/js/script.js index 778a3ad5..6abe92ac 100644 --- a/resources/library/interactivities/Cat text.wgt/locales/ru/js/script.js +++ b/resources/library/interactivities/Cat text.wgt/locales/ru/js/script.js @@ -1,10 +1,16 @@ var sankoreLang = { display: "Показать", edit: "Изменить", - first_desc: "Нечетные числа", - second_desc: "Четные числа", + first_desc: "Фрукты", + second_desc: "Овощи", + potatoes: "Картофель", + carrot: "Морковь", + onion: "Лук", + apple: "Яблоко", + pear: "Груша", enter: "Введите название категории ...", add: "Новый блок", + text: "Какой-то текст", wgt_name: "Категории", reload: "Обновить", slate: "Узор", @@ -22,8 +28,8 @@ function start(){ $(".style_select option[value='2']").text(sankoreLang.pad); if(window.sankore){ - if(sankore.preference("categoriser_images","")){ - var data = jQuery.parseJSON(sankore.preference("categoriser_images","")); + if(sankore.preference("categoriser_text","")){ + var data = jQuery.parseJSON(sankore.preference("categoriser_text","")); importData(data); } else { showExample(); @@ -61,7 +67,6 @@ function start(){ $(this).addClass("selected"); $("#wgt_edit").removeClass("selected"); $(".style_select").css("display","none"); - sankore.enableDropOnWidget(false); $(".add_block").remove(); $(".cont").each(function(){ var container = $(this); @@ -72,6 +77,7 @@ function start(){ container.find(".close_cont").remove(); container.find(".imgs_cont").each(function(){ $(this).find(".del_category").remove(); + $(this).find(".add_img").remove(); $(this).find(".add_category").remove(); $(this).removeAttr("ondragenter") .removeAttr("ondragleave") @@ -82,6 +88,9 @@ function start(){ $(this).find("input[name='count']").val(tmp_count); $(this).find(".img_block").each(function(){ $(this).find(".close_img").remove(); + var tmp_text = $(this).find(".text_cont"); + tmp_text.removeAttr("contenteditable") + .css("margin", ($(this).height() - tmp_text.height())/2 + "px 0px"); tmp_array.push($(this)); $(this).remove(); }); @@ -131,19 +140,14 @@ function start(){ $(this).addClass("selected"); $("#wgt_display").removeClass("selected"); $(".style_select").css("display","block"); - sankore.enableDropOnWidget(true); $(".cont").each(function(){ var container = $(this); $("
").appendTo(container); container.find(".imgs_cont").each(function(){ - $("").appendTo($(this)); - $("").appendTo($(this)); - $(this).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);") - .removeClass("red_cont") + $("").appendTo($(this)); + $("").appendTo($(this)); + $(this).removeClass("red_cont") .removeClass("green_cont") .addClass("def_cont") .droppable("destroy") @@ -151,11 +155,15 @@ function start(){ var tmp_img_cont = $(this); var tmp_mask = $(this).find("input[name='mask']").val(); container.find(".img_block").each(function(){ + $(this).draggable("destroy") + .find(".text_cont").attr("contenteditable","true") + .removeAttr("style"); if($(this).find("input").val() == tmp_mask){ $("
").appendTo($(this)); $(this).appendTo(tmp_img_cont); } }); + $("
").appendTo($(this)); }); container.find(".all_imgs").remove(); }); @@ -175,7 +183,7 @@ function start(){ //adding new img $(".add_img").live("click", function(){ - addImgBlock($(this)); + addText($(this).parent(), $(this)); }); //deleting a block @@ -208,14 +216,14 @@ function start(){ //export function exportData(){ var array_to_export = []; - if($("#edit").hasClass("selected")){ + if($("#wgt_edit").hasClass("selected")){ $(".cont").each(function(){ var cont_obj = new Object(); - cont_obj.style = $(".style_select").find("option:selected").val(); cont_obj.mode = "edit"; cont_obj.conts = []; $(this).find(".imgs_cont").each(function(){ var img_cont = new Object(); + cont_obj.style = $(".style_select").find("option:selected").val(); 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(); @@ -223,10 +231,7 @@ function exportData(){ $(this).find(".img_block").each(function(){ var img_obj = new Object(); img_obj.value = $(this).find("input").val(); - img_obj.link = $(this).find("img").attr("src").replace("../../",""); - ; - img_obj.ht = $(this).find("img").height(); - img_obj.wd = $(this).find("img").width(); + img_obj.text = $(this).find(".text_cont").text(); img_cont.imgs.push(img_obj); }); cont_obj.conts.push(img_cont); @@ -236,11 +241,11 @@ function exportData(){ } else { $(".cont").each(function(){ var cont_obj = new Object(); - cont_obj.style = $(".style_select").find("option:selected").val(); cont_obj.mode = "display"; cont_obj.conts = []; $(this).find(".imgs_cont").each(function(){ var img_cont = new Object(); + cont_obj.style = $(".style_select").find("option:selected").val(); 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(); @@ -248,10 +253,7 @@ function exportData(){ $(this).find(".img_block").each(function(){ var img_obj = new Object(); img_obj.value = $(this).find("input").val(); - img_obj.link = $(this).find("img").attr("src").replace("../../",""); - ; - img_obj.ht = $(this).find("img").height(); - img_obj.wd = $(this).find("img").width(); + img_obj.text = $(this).find(".text_cont").text(); img_cont.imgs.push(img_obj); }); cont_obj.conts.push(img_cont); @@ -260,10 +262,7 @@ function exportData(){ $(this).find(".all_imgs .img_block").each(function(){ var img = new Object(); img.value = $(this).find("input").val(); - img.link = $(this).find("img").attr("src").replace("../../",""); - ; - img.ht = $(this).find("img").height(); - img.wd = $(this).find("img").width(); + img.text = $(this).find(".text_cont").text(); cont_obj.all_imgs.push(img); }); array_to_export.push(cont_obj); @@ -277,7 +276,7 @@ function exportData(){ array_to_export.push(cont_obj); } - sankore.setPreference("categoriser_images", JSON.stringify(array_to_export)); + sankore.setPreference("categoriser_text", JSON.stringify(array_to_export)); } //import @@ -288,14 +287,15 @@ function importData(data){ if(data[i].tmp){ changeStyle(data[i].style); $(".style_select").val(data[i].style); - } else { + } + else { if(i == 0){ changeStyle(data[i].style); $(".style_select").val(data[i].style); } if(data[i].mode == "edit"){ var tmp_array = []; - var container = $("
"); + var container = $("
").appendTo("#data"); var sub_container = $("
").appendTo(container); $("
"+ (++tmp) +"
").appendTo(sub_container); @@ -308,14 +308,8 @@ function importData(data){ $("").appendTo(tmp_div); for(var k in data[i].conts[j].imgs){ var block_img = $("
"); - $("").appendTo(block_img); - var img = $("").appendTo(block_img); - if(data[i].conts[j].imgs[k].ht >= data[i].conts[j].imgs[k].wd) - img.attr("height", "120"); - else{ - img.attr("width","120"); - img.css("margin",(120 - data[i].conts[j].imgs[k].ht)/2 + "px 0"); - } + $("").appendTo(block_img); + $("
" + data[i].conts[j].imgs[k].text + "
").appendTo(block_img); tmp_array.push(block_img); } @@ -328,7 +322,7 @@ function importData(data){ checkCorrectness(tmp_ui); } } - }); + }); } var all_imgs = $("
").appendTo(container); @@ -341,6 +335,8 @@ function importData(data){ appendTo: '#data' }); tmp_array[j].appendTo(all_imgs); + var tmp_text = tmp_array[j].find(".text_cont"); + tmp_text.css("margin", (tmp_array[j].height() - tmp_text.height())/2 + "px 0px"); } all_imgs.sortable(); @@ -357,10 +353,8 @@ function importData(data){ } } }); - - container.appendTo("#data"); } else { - container = $("
"); + container = $("
").appendTo("#data"); sub_container = $("
").appendTo(container); $("
" + (++tmp) + "
").appendTo(sub_container); @@ -373,14 +367,8 @@ function importData(data){ $("").appendTo(tmp_div); for(k in data[i].conts[j].imgs){ block_img = $("
"); - $("").appendTo(block_img); - img = $("").appendTo(block_img); - if(data[i].conts[j].imgs[k].ht >= data[i].conts[j].imgs[k].wd) - img.attr("height", "120"); - else{ - img.attr("width","120"); - img.css("margin",(120 - data[i].conts[j].imgs[k].ht)/2 + "px 0"); - } + $("").appendTo(block_img); + $("
" + data[i].conts[j].imgs[k].text + "
").appendTo(block_img); tmp_img_array.push(block_img); } @@ -392,6 +380,8 @@ function importData(data){ appendTo: '#data' }); tmp_img_array[k].appendTo(imgs_container); + tmp_text = tmp_img_array[k].find(".text_cont"); + tmp_text.css("margin", (tmp_img_array[k].height() - tmp_text.height())/2 + "px 0px"); } imgs_container.droppable({ @@ -403,7 +393,7 @@ function importData(data){ checkCorrectness(tmp_ui); } } - }); + }); checkCorrectness(imgs_container); } @@ -411,8 +401,8 @@ function importData(data){ var all_imgs_arr = []; for(j in data[i].all_imgs){ block_img = $("
"); - $("").appendTo(block_img); - $("").appendTo(block_img); + $("").appendTo(block_img); + $("
" + data[i].all_imgs[j].text + "
").appendTo(block_img); all_imgs_arr.push(block_img); } @@ -424,6 +414,8 @@ function importData(data){ appendTo: '#data' }); all_imgs_arr[k].appendTo(all_imgs); + tmp_text = all_imgs_arr[k].find(".text_cont"); + tmp_text.css("margin", (all_imgs_arr[k].height() - tmp_text.height())/2 + "px 0px"); } all_imgs.sortable(); @@ -440,7 +432,6 @@ function importData(data){ } } }); - container.appendTo("#data"); } } } @@ -470,23 +461,23 @@ function showExample(){ var tmp_div_two = $("
").appendTo(imgs_container_two); $("").appendTo(tmp_div_two); - var img1 = $("
"); - $("").appendTo(img1); - $("").appendTo(img1); - var img2 = $("
"); - $("").appendTo(img2); - $("").appendTo(img2); - var img3 = $("
"); - $("").appendTo(img3); - $("").appendTo(img3); - var img4 = $("
"); - $("").appendTo(img4); - $("").appendTo(img4); - var img5 = $("
"); - $("").appendTo(img5); - $("").appendTo(img5); + var text1 = $("
"); + $("").appendTo(text1); + $("
" + sankoreLang.potatoes + "
").appendTo(text1); + var text2 = $("
"); + $("").appendTo(text2); + $("
" + sankoreLang.apple + "
").appendTo(text2); + var text3 = $("
"); + $("").appendTo(text3); + $("
" + sankoreLang.carrot + "
").appendTo(text3); + var text4 = $("
"); + $("").appendTo(text4); + $("
" + sankoreLang.pear + "
").appendTo(text4); + var text5 = $("
"); + $("").appendTo(text5); + $("
" + sankoreLang.onion + "
").appendTo(text5); - tmp_array.push(img1, img2, img3, img4, img5); + tmp_array.push(text1, text2, text3, text4, text5); tmp_array = shuffle(tmp_array); for(var i = 0; i").insertBefore(source); + $("
").appendTo(text_block); + $("").appendTo(text_block); + $("
" + sankoreLang.text + "
").appendTo(text_block); +} + //function that allows to add new category function addCategory(obj){ var imgs_container = $("
").insertAfter(obj); @@ -541,12 +542,9 @@ function addCategory(obj){ $("").appendTo(imgs_container); var tmp_div = $("
").appendTo(imgs_container); $("").appendTo(tmp_div); - $("").appendTo(imgs_container); - $("").appendTo(imgs_container); - imgs_container.attr("ondragenter", "return false;") - .attr("ondragleave", "$(this).css(\"background-color\",\"\"); return false;") - .attr("ondragover", "$(this).css(\"background-color\",\"\"); return false;") - .attr("ondrop", "$(this).css(\"background-color\",\"\"); return onDropTarget(this,event);"); + $("").appendTo(imgs_container); + $("").appendTo(imgs_container); + $("
").appendTo(imgs_container); } //add new container @@ -562,12 +560,9 @@ function addContainer(){ $("").appendTo(imgs_container); var tmp_div = $("
").appendTo(imgs_container); $("").appendTo(tmp_div); - $("").appendTo(imgs_container); - $("").appendTo(imgs_container); - imgs_container.attr("ondragenter", "return false;") - .attr("ondragleave", "$(this).css(\"background-color\",\"\"); return false;") - .attr("ondragover", "$(this).css(\"background-color\",\"\"); return false;") - .attr("ondrop", "$(this).css(\"background-color\",\"\"); return onDropTarget(this,event);"); + $("").appendTo(imgs_container); + $("").appendTo(imgs_container); + $("
").appendTo(imgs_container); container.insertBefore($(".add_block")); } @@ -605,6 +600,11 @@ function stringToXML(text){ return doc; } +//return id +function returnId(){ + var tmp = Math.random().toString(); + return tmp.substr(2); +} //changing the style function changeStyle(val){ @@ -639,12 +639,6 @@ function changeStyle(val){ } } -//return id -function returnId(){ - var tmp = Math.random().toString(); - return tmp.substr(2); -} - //a func for checking when smth will drop function checkOnDrop(dest, source){ dest.append(source); @@ -699,61 +693,4 @@ function checkCorrectness(source){ .removeClass("green_cont") .addClass("red_cont"); } -} - -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 = $("
"); - $("
").appendTo(img_block); - $("").appendTo(img_block); - var tmp_img = $("").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"); - 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"); - tmp_img.css("margin",(120 - tmp_img.height())/2 + "px 0"); - } - } - } - exportData(); - } - else { - alert ("Your browser does not support the dataTransfer object."); - } - - if (event.stopPropagation) { - event.stopPropagation (); - } - else { - event.cancelBubble = true; - } - return false; } \ No newline at end of file From d09cfc1449c9362246966e83c02bed48dc9c52e9 Mon Sep 17 00:00:00 2001 From: unknown Date: Mon, 25 Jun 2012 19:04:33 +0200 Subject: [PATCH 4/4] fixed orde images widget --- .../Ordre images.wgt/index.html | 11 +++--- .../Ordre images.wgt/js/script.js | 37 +++++++++++++----- .../Ordre images.wgt/locales/fr/js/script.js | 37 +++++++++++++----- .../Ordre images.wgt/locales/ru/js/script.js | 38 ++++++++++++++----- 4 files changed, 90 insertions(+), 33 deletions(-) diff --git a/resources/library/interactivities/Ordre images.wgt/index.html b/resources/library/interactivities/Ordre images.wgt/index.html index 5b38539e..e8e11b60 100644 --- a/resources/library/interactivities/Ordre images.wgt/index.html +++ b/resources/library/interactivities/Ordre images.wgt/index.html @@ -5,7 +5,7 @@ - + @@ -17,7 +17,8 @@ } else lang = "en"; if(lang == "en"){ - sankore.enableDropOnWidget(false); + if(window.sankore) + sankore.enableDropOnWidget(false); start(); } else{ @@ -57,17 +58,17 @@   - +  
- +
  - +     diff --git a/resources/library/interactivities/Ordre images.wgt/js/script.js b/resources/library/interactivities/Ordre images.wgt/js/script.js index 22b08946..f2992318 100644 --- a/resources/library/interactivities/Ordre images.wgt/js/script.js +++ b/resources/library/interactivities/Ordre images.wgt/js/script.js @@ -34,12 +34,21 @@ function start(){ //events if (window.widget) { window.widget.onleave = function(){ - //exportData(); + exportData(); } } $("#wgt_reload").click(function(){ - window.location.reload(); + 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(); }); $(".style_select").change(function (event){ @@ -204,6 +213,10 @@ function exportData(){ array_to_export.push(cont_obj); } sankore.setPreference("odr_des_imgs", JSON.stringify(array_to_export)); + if($("#wgt_display").hasClass("selected")) + sankore.setPreference("odr_des_imgs_state", "display"); + else + sankore.setPreference("odr_des_imgs_state", "edit"); } //import @@ -240,13 +253,19 @@ function importData(data){ img_block.append(hidden_input).append(img); tmp_array.push(img_block); } - tmp_array = shuffle(tmp_array); + if(sankore.preference("odr_des_imgs_state","")){ + if(sankore.preference("odr_des_imgs_state","") == "edit") + tmp_array = shuffle(tmp_array); + } else + tmp_array = shuffle(tmp_array); + for(j = 0; j