var sankoreLang = {
display : "Afficher" ,
edit : "Modifier" ,
first _desc : "Les nombres impairs" ,
second _desc : "Les nombres pairs" ,
enter : "Saisir le nom de la catégorie ici ..." ,
add : "Nouveau bloc" ,
wgt _name : "Catégoriser des images" ,
reload : "Recharger" ,
slate : "ardoise" ,
pad : "tablette" ,
none : "aucun" ,
help : "Aide" ,
help _content : "<p><h2>Catégoriser des images</h2></p>" +
"<p><h3>Classer des images en fonction de la dénomination de la catégorie.</h3></p>" +
"<p>L’activité s’effectue par un glisser-déposer de l’image dans la catégorie correspondante. Tant que toutes les images d’une catégorie ne sont pas classées, la zone reste rouge. Une fois que toutes les images sont classées dans la bonne catégorie, la zone se colore en vert.</p>" +
"<p>Le bouton “Recharger” réinitialise les exercices.</p>" +
"<p>Le bouton “Modifier” vous permet :</p>" +
"<ul><li>de choisir le thème de l’interactivité : tablette, ardoise ou aucun (par défaut aucun) ,</li>" +
"<li>de modifier un exercice ou d’en créer de nouveaux dans la même activité.</li></ul>" +
"<p>En mode édition, pour créer un nouvel exercice, cliquez sur “Nouveau bloc” en bas, une zone bleue apparaît, c’est une catégorie, puis</p>" +
"<ul><li>insérez le nom de la catégorie (par exemple “fruits”, “légumes”, “mammifères”...) en cliquant dans le champ de texte “Saisir le nom de la catégorie ici …”,</li>" +
"<li>insérez des images dans la catégorie par glisser-déposer des images à partir de votre bibliothèque,</li>" +
"<li>ajoutez ensuite une catégorie (ou plusieurs) en cliquant sur le signe “+” situé à droite de la catégorie, complétez par son nom et ajoutez des images.</li></ul>" +
"<p>Pour supprimer une image, cliquez sur la croix située dans le coin supérieur droit de l’image.</p>" +
"<p>Pour supprimer une catégorie, cliquez sur le signe “-” situé à droite de celle-ci.</p>" +
"<p>Pour supprimer un exercice, cliquez sur la croix à gauche du numéro de l’exercice.</p>" +
"<p>Le bouton “Afficher” vous permet d’utiliser l’activité.</p>" ,
theme : "Thème"
} ;
//main function
function start ( ) {
$ ( "#wgt_display" ) . text ( sankoreLang . display ) ;
$ ( "#wgt_edit" ) . text ( sankoreLang . edit ) ;
$ ( "#wgt_name" ) . text ( sankoreLang . wgt _name ) ;
$ ( "#wgt_reload" ) . text ( sankoreLang . reload ) ;
$ ( "#wgt_help" ) . text ( sankoreLang . help ) ;
$ ( "#help" ) . html ( sankoreLang . help _content ) ;
$ ( "#style_select option[value='1']" ) . text ( sankoreLang . slate ) ;
$ ( "#style_select option[value='2']" ) . text ( sankoreLang . pad ) ;
$ ( "#style_select option[value='3']" ) . text ( sankoreLang . none ) ;
var tmpl = $ ( "div.inline label" ) . html ( ) ;
$ ( "div.inline label" ) . html ( sankoreLang . theme + tmpl )
if ( window . sankore ) {
if ( sankore . preference ( "categoriser_images" , "" ) ) {
var data = jQuery . parseJSON ( sankore . preference ( "categoriser_images" , "" ) ) ;
importData ( data ) ;
} else {
showExample ( ) ;
}
}
else
showExample ( ) ;
if ( window . widget ) {
window . widget . onleave = function ( ) {
exportData ( ) ;
}
}
$ ( "#wgt_help" ) . click ( function ( ) {
var tmp = $ ( this ) ;
if ( $ ( this ) . hasClass ( "open" ) ) {
$ ( this ) . removeClass ( "help_pad" ) . removeClass ( "help_wood" )
$ ( "#help" ) . slideUp ( "100" , function ( ) {
tmp . removeClass ( "open" ) ;
$ ( "#data" ) . show ( ) ;
} ) ;
} else {
( $ ( "#style_select" ) . val ( ) == 1 ) ? $ ( this ) . removeClass ( "help_pad" ) . addClass ( "help_wood" ) : $ ( this ) . removeClass ( "help_wood" ) . addClass ( "help_pad" ) ;
$ ( "#data" ) . hide ( ) ;
$ ( "#help" ) . slideDown ( "100" , function ( ) {
tmp . addClass ( "open" ) ;
} ) ;
}
} ) ;
$ ( "#wgt_reload" ) . click ( function ( ) {
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 ) {
changeStyle ( $ ( this ) . find ( "option:selected" ) . val ( ) ) ;
} )
$ ( "#wgt_display, #wgt_edit" ) . click ( function ( event ) {
if ( this . id == "wgt_display" ) {
if ( ! $ ( this ) . hasClass ( "selected" ) ) {
$ ( this ) . addClass ( "selected" ) ;
$ ( "#wgt_edit" ) . removeClass ( "selected" ) ;
$ ( "#parameters" ) . css ( "display" , "none" ) ;
sankore . enableDropOnWidget ( false ) ;
$ ( ".add_block" ) . remove ( ) ;
$ ( ".cont" ) . each ( function ( ) {
var container = $ ( this ) ;
var tmp _i = 0 ;
var tmp _right = "" ;
var tmp _array = [ ] ;
container . find ( ".close_cont" ) . remove ( ) ;
container . find ( ".imgs_cont" ) . each ( function ( ) {
$ ( this ) . find ( ".del_category" ) . remove ( ) ;
$ ( this ) . find ( ".add_category" ) . remove ( ) ;
$ ( this ) . removeAttr ( "ondragenter" )
. removeAttr ( "ondragleave" )
. removeAttr ( "ondragover" )
. removeAttr ( "ondrop" )
. find ( ".cat_desc" ) . attr ( "disabled" , "disabled" ) ;
var tmp _count = $ ( this ) . find ( ".img_block" ) . size ( ) ;
$ ( this ) . find ( "input[name='count']" ) . val ( tmp _count ) ;
$ ( this ) . find ( ".img_block" ) . each ( function ( ) {
$ ( this ) . find ( ".close_img" ) . remove ( ) ;
tmp _array . push ( $ ( this ) ) ;
$ ( this ) . remove ( ) ;
} ) ;
$ ( this ) . droppable ( {
hoverClass : 'dropHere' ,
drop : function ( event , ui ) {
if ( $ ( ui . draggable ) . parent ( ) . parent ( ) . html ( ) == $ ( this ) . parent ( ) . html ( ) ) {
var tmp _ui = $ ( ui . draggable ) . parent ( ) ;
$ ( this ) . append ( $ ( ui . draggable ) ) ;
checkCorrectness ( tmp _ui ) ;
}
}
} ) ;
$ ( this ) . removeAttr ( "style" ) ;
} ) ;
var all _imgs = $ ( "<div class='all_imgs'>" ) . appendTo ( container ) ;
tmp _array = shuffle ( tmp _array ) ;
for ( var i = 0 ; i < tmp _array . length ; i ++ ) {
tmp _array [ i ] . draggable ( {
helper : 'clone' ,
zIndex : 100 ,
appendTo : '#data'
} ) ;
tmp _array [ i ] . appendTo ( all _imgs ) ;
}
all _imgs . droppable ( {
hoverClass : 'dropBack' ,
drop : function ( event , ui ) {
if ( $ ( ui . draggable ) . parent ( ) . parent ( ) . html ( ) == $ ( this ) . parent ( ) . html ( ) ) {
if ( this != $ ( ui . draggable ) . parent ( ) [ 0 ] ) {
var tmp _ui = $ ( ui . draggable ) . parent ( ) ;
$ ( this ) . append ( $ ( ui . draggable ) ) ;
checkCorrectness ( tmp _ui ) ;
}
}
}
} ) ;
} ) ;
$ ( this ) . css ( "display" , "none" ) ;
$ ( "#wgt_edit" ) . css ( "display" , "block" ) ;
}
} else {
if ( ! $ ( this ) . hasClass ( "selected" ) ) {
$ ( this ) . addClass ( "selected" ) ;
$ ( "#wgt_display" ) . removeClass ( "selected" ) ;
$ ( "#parameters" ) . css ( "display" , "block" ) ;
sankore . enableDropOnWidget ( true ) ;
$ ( ".cont" ) . each ( function ( ) {
var container = $ ( this ) ;
$ ( "<div class='close_cont'>" ) . appendTo ( container ) ;
container . find ( ".imgs_cont" ) . each ( function ( ) {
$ ( "<button class='del_category'></button>" ) . appendTo ( $ ( this ) ) ;
$ ( "<button class='add_category'></button>" ) . 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" )
. find ( ".cat_desc" ) . removeAttr ( "disabled" ) ;
var tmp _img _cont = $ ( this ) ;
var tmp _mask = $ ( this ) . find ( "input[name='mask']" ) . val ( ) ;
container . find ( ".img_block" ) . each ( function ( ) {
if ( $ ( this ) . find ( "input" ) . val ( ) == tmp _mask ) {
$ ( "<div class='close_img'>" ) . appendTo ( $ ( this ) ) ;
$ ( this ) . appendTo ( tmp _img _cont ) ;
}
} ) ;
} ) ;
container . find ( ".all_imgs" ) . remove ( ) ;
} ) ;
$ ( "<div class='add_block'>" + sankoreLang . add + "</div>" ) . appendTo ( "#data" ) ;
$ ( this ) . css ( "display" , "none" ) ;
$ ( "#wgt_display" ) . css ( "display" , "block" ) ;
}
}
} ) ;
//add new block
$ ( ".add_block" ) . live ( "click" , function ( ) {
addContainer ( ) ;
} ) ;
//adding new img
$ ( ".add_img" ) . live ( "click" , function ( ) {
addImgBlock ( $ ( this ) ) ;
} ) ;
//deleting a block
$ ( ".close_cont" ) . live ( "click" , function ( ) {
$ ( this ) . parent ( ) . remove ( ) ;
refreshBlockNumbers ( ) ;
} ) ;
//deleting the img block
$ ( ".close_img" ) . live ( "click" , function ( ) {
$ ( this ) . parent ( ) . remove ( ) ;
} ) ;
//adding new category
$ ( ".add_category" ) . live ( "click" , function ( ) {
addCategory ( $ ( this ) . parent ( ) ) ;
} ) ;
//deleting the category
$ ( ".del_category" ) . live ( "click" , function ( ) {
if ( $ ( this ) . parent ( ) . parent ( ) . find ( ".imgs_cont" ) . size ( ) == 1 ) {
$ ( this ) . parent ( ) . find ( ".img_block" ) . remove ( ) ;
$ ( this ) . parent ( ) . find ( ".cat_desc" ) . val ( sankoreLang . enter ) ;
} else {
$ ( this ) . parent ( ) . remove ( ) ;
}
} ) ;
}
//export
function exportData ( ) {
var array _to _export = [ ] ;
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 ( ) ;
img _cont . mask = $ ( this ) . find ( "input[name='mask']" ) . val ( ) ;
img _cont . count = $ ( this ) . find ( ".img_block" ) . size ( ) ;
img _cont . text = $ ( this ) . find ( ".cat_desc" ) . val ( ) ;
img _cont . imgs = [ ] ;
$ ( this ) . find ( ".img_block" ) . each ( function ( ) {
var img _obj = new Object ( ) ;
img _obj . value = $ ( this ) . find ( "input" ) . val ( ) ;
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 ) ;
} ) ;
array _to _export . push ( cont _obj ) ;
} ) ;
} 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 ( ) ;
img _cont . mask = $ ( this ) . find ( "input[name='mask']" ) . val ( ) ;
img _cont . count = $ ( this ) . find ( "input[name='count']" ) . val ( ) ;
img _cont . text = $ ( this ) . find ( ".cat_desc" ) . val ( ) ;
img _cont . imgs = [ ] ;
$ ( this ) . find ( ".img_block" ) . each ( function ( ) {
var img _obj = new Object ( ) ;
img _obj . value = $ ( this ) . find ( "input" ) . val ( ) ;
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 ) ;
} ) ;
cont _obj . all _imgs = [ ] ;
$ ( 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 ( ) ;
cont _obj . all _imgs . push ( img ) ;
} ) ;
array _to _export . push ( cont _obj ) ;
} ) ;
}
if ( $ ( ".cont" ) . size ( ) == 0 ) {
var cont _obj = new Object ( ) ;
cont _obj . style = $ ( "#style_select" ) . find ( "option:selected" ) . val ( ) ;
cont _obj . tmp = "clear" ;
array _to _export . push ( cont _obj ) ;
}
sankore . setPreference ( "categoriser_images" , JSON . stringify ( array _to _export ) ) ;
}
//import
function importData ( data ) {
var tmp = 0 ;
for ( var i in data ) {
if ( data [ i ] . tmp ) {
changeStyle ( data [ i ] . style ) ;
$ ( "#style_select" ) . val ( data [ i ] . style ) ;
} else {
if ( i == 0 ) {
changeStyle ( data [ i ] . style ) ;
$ ( "#style_select" ) . val ( data [ i ] . style ) ;
}
if ( data [ i ] . mode == "edit" ) {
var tmp _array = [ ] ;
var container = $ ( "<div class='cont'>" ) ;
var sub _container = $ ( "<div class='sub_cont'>" ) . appendTo ( container ) ;
$ ( "<div class='number_cont'>" + ( ++ tmp ) + "</div>" ) . appendTo ( sub _container ) ;
for ( var j in data [ i ] . conts ) {
var imgs _container = $ ( "<div class='imgs_cont def_cont'>" ) . appendTo ( container ) ;
$ ( "<input type='hidden' name='mask' value='" + data [ i ] . conts [ j ] . mask + "'/>" ) . appendTo ( imgs _container ) ;
$ ( "<input type='hidden' name='count' value='" + data [ i ] . conts [ j ] . count + "'/>" ) . appendTo ( imgs _container ) ;
var tmp _div = $ ( "<div style='width: 100%; overflow: hidden;'>" ) . appendTo ( imgs _container ) ;
$ ( "<input type='text' class='cat_desc' value='" + data [ i ] . conts [ j ] . text + "' disabled/>" ) . appendTo ( tmp _div ) ;
for ( var k in data [ i ] . conts [ j ] . imgs ) {
var block _img = $ ( "<div class='img_block' style='text-align: center;'></div>" ) ;
$ ( "<input type='hidden' value='" + data [ i ] . conts [ j ] . imgs [ k ] . value + "'/>" ) . appendTo ( block _img ) ;
var img = $ ( "<img src=\"../../" + data [ i ] . conts [ j ] . imgs [ k ] . link + "\" style=\"display: inline;\"/>" ) . appendTo ( block _img ) ;
img . height ( data [ i ] . conts [ j ] . imgs [ k ] . ht ) ;
if ( ( 120 - data [ i ] . conts [ j ] . imgs [ k ] . ht ) > 0 )
img . css ( "margin" , ( 120 - data [ i ] . conts [ j ] . imgs [ k ] . ht ) / 2 + "px 0" ) ;
tmp _array . push ( block _img ) ;
}
imgs _container . droppable ( {
hoverClass : 'dropHere' ,
drop : function ( event , ui ) {
if ( $ ( ui . draggable ) . parent ( ) . parent ( ) . html ( ) == $ ( this ) . parent ( ) . html ( ) ) {
var tmp _ui = $ ( ui . draggable ) . parent ( ) ;
$ ( this ) . append ( $ ( ui . draggable ) ) ;
checkCorrectness ( tmp _ui ) ;
}
}
} ) ;
}
var all _imgs = $ ( "<div class='all_imgs'>" ) . appendTo ( container ) ;
tmp _array = shuffle ( tmp _array ) ;
for ( j in tmp _array ) {
tmp _array [ j ] . draggable ( {
helper : 'clone' ,
zIndex : 100 ,
appendTo : '#data'
} ) ;
tmp _array [ j ] . appendTo ( all _imgs ) ;
}
all _imgs . sortable ( ) ;
all _imgs . droppable ( {
hoverClass : 'dropBack' ,
drop : function ( event , ui ) {
if ( $ ( ui . draggable ) . parent ( ) . parent ( ) . html ( ) == $ ( this ) . parent ( ) . html ( ) ) {
if ( this != $ ( ui . draggable ) . parent ( ) [ 0 ] ) {
var tmp _ui = $ ( ui . draggable ) . parent ( ) ;
$ ( this ) . append ( $ ( ui . draggable ) ) ;
checkCorrectness ( tmp _ui ) ;
}
}
}
} ) ;
container . appendTo ( "#data" ) ;
} else {
container = $ ( "<div class='cont'>" ) ;
sub _container = $ ( "<div class='sub_cont'>" ) . appendTo ( container ) ;
$ ( "<div class='number_cont'>" + ( ++ tmp ) + "</div>" ) . appendTo ( sub _container ) ;
for ( j in data [ i ] . conts ) {
var tmp _img _array = [ ] ;
imgs _container = $ ( "<div class='imgs_cont def_cont'>" ) . appendTo ( container ) ;
$ ( "<input type='hidden' name='mask' value='" + data [ i ] . conts [ j ] . mask + "'/>" ) . appendTo ( imgs _container ) ;
$ ( "<input type='hidden' name='count' value='" + data [ i ] . conts [ j ] . count + "'/>" ) . appendTo ( imgs _container ) ;
tmp _div = $ ( "<div style='width: 100%; overflow: hidden;'>" ) . appendTo ( imgs _container ) ;
$ ( "<input type='text' class='cat_desc' value='" + data [ i ] . conts [ j ] . text + "' disabled/>" ) . appendTo ( tmp _div ) ;
for ( k in data [ i ] . conts [ j ] . imgs ) {
block _img = $ ( "<div class='img_block' style='text-align: center;'></div>" ) ;
$ ( "<input type='hidden' value='" + data [ i ] . conts [ j ] . imgs [ k ] . value + "'/>" ) . appendTo ( block _img ) ;
img = $ ( "<img src=\"../../" + data [ i ] . conts [ j ] . imgs [ k ] . link + "\" style=\"display: inline;\"/>" ) . appendTo ( block _img ) ;
img . height ( data [ i ] . conts [ j ] . imgs [ k ] . ht ) ;
if ( ( 120 - data [ i ] . conts [ j ] . imgs [ k ] . ht ) > 0 )
img . css ( "margin" , ( 120 - data [ i ] . conts [ j ] . imgs [ k ] . ht ) / 2 + "px 0" ) ;
tmp _img _array . push ( block _img ) ;
}
tmp _img _array = shuffle ( tmp _img _array ) ;
for ( k in tmp _img _array ) {
tmp _img _array [ k ] . draggable ( {
helper : 'clone' ,
zIndex : 100 ,
appendTo : '#data'
} ) ;
tmp _img _array [ k ] . appendTo ( imgs _container ) ;
}
imgs _container . droppable ( {
hoverClass : 'dropHere' ,
drop : function ( event , ui ) {
if ( $ ( ui . draggable ) . parent ( ) . parent ( ) . html ( ) == $ ( this ) . parent ( ) . html ( ) ) {
var tmp _ui = $ ( ui . draggable ) . parent ( ) ;
$ ( this ) . append ( $ ( ui . draggable ) ) ;
checkCorrectness ( tmp _ui ) ;
}
}
} ) ;
checkCorrectness ( imgs _container ) ;
}
all _imgs = $ ( "<div class='all_imgs'>" ) . appendTo ( container ) ;
var all _imgs _arr = [ ] ;
for ( j in data [ i ] . all _imgs ) {
block _img = $ ( "<div class='img_block' style='text-align: center;'></div>" ) ;
$ ( "<input type='hidden' value='" + data [ i ] . all _imgs [ j ] . value + "'/>" ) . appendTo ( block _img ) ;
img = $ ( "<img src=\"../../" + data [ i ] . all _imgs [ j ] . link + "\" style=\"display: inline;\"/>" ) . appendTo ( block _img ) ;
img . height ( data [ i ] . all _imgs [ j ] . ht ) ;
if ( ( 120 - data [ i ] . all _imgs [ j ] . ht ) > 0 )
img . css ( "margin" , ( 120 - data [ i ] . all _imgs [ j ] . ht ) / 2 + "px 0" ) ;
all _imgs _arr . push ( block _img ) ;
}
all _imgs _arr = shuffle ( all _imgs _arr ) ;
for ( k in all _imgs _arr ) {
all _imgs _arr [ k ] . draggable ( {
helper : 'clone' ,
zIndex : 100 ,
appendTo : '#data'
} ) ;
all _imgs _arr [ k ] . appendTo ( all _imgs ) ;
}
all _imgs . sortable ( ) ;
all _imgs . droppable ( {
hoverClass : 'dropBack' ,
drop : function ( event , ui ) {
if ( $ ( ui . draggable ) . parent ( ) . parent ( ) . html ( ) == $ ( this ) . parent ( ) . html ( ) ) {
if ( this != $ ( ui . draggable ) . parent ( ) [ 0 ] ) {
var tmp _ui = $ ( ui . draggable ) . parent ( ) ;
$ ( this ) . append ( $ ( ui . draggable ) ) ;
checkCorrectness ( tmp _ui ) ;
}
}
}
} ) ;
container . appendTo ( "#data" ) ;
checkCorrectness ( all _imgs ) ;
}
}
}
}
//example
function showExample ( ) {
changeStyle ( "3" ) ;
var tmp _array = [ ] ;
var container = $ ( "<div class='cont'>" ) . appendTo ( "#data" ) ;
var sub _container = $ ( "<div class='sub_cont'>" ) . appendTo ( container ) ;
var imgs _container _one = $ ( "<div class='imgs_cont def_cont'>" ) . appendTo ( container ) ;
var imgs _container _two = $ ( "<div class='imgs_cont def_cont'>" ) . appendTo ( container ) ;
var all _imgs = $ ( "<div class='all_imgs'>" ) . appendTo ( container ) ;
var number = $ ( "<div class='number_cont'>1</div>" ) . appendTo ( sub _container ) ;
$ ( "<input type='hidden' name='mask' value='1'/>" ) . appendTo ( imgs _container _one ) ;
$ ( "<input type='hidden' name='count' value='2'/>" ) . appendTo ( imgs _container _one ) ;
var tmp _div _one = $ ( "<div style='width: 100%; overflow: hidden;'>" ) . appendTo ( imgs _container _one ) ;
$ ( "<input type='text' class='cat_desc' value='" + sankoreLang . first _desc + "' disabled/>" ) . appendTo ( tmp _div _one ) ;
$ ( "<input type='hidden' name='mask' value='2'/>" ) . appendTo ( imgs _container _two ) ;
$ ( "<input type='hidden' name='count' value='3'/>" ) . appendTo ( imgs _container _two ) ;
var tmp _div _two = $ ( "<div style='width: 100%; overflow: hidden;'>" ) . appendTo ( imgs _container _two ) ;
$ ( "<input type='text' class='cat_desc' value='" + sankoreLang . second _desc + "' disabled/>" ) . appendTo ( tmp _div _two ) ;
var img1 = $ ( "<div class='img_block' style='text-align: center;'></div>" ) ;
$ ( "<input type='hidden' value='2'/>" ) . appendTo ( img1 ) ;
$ ( "<img src=\"../../objects/0.gif\" style=\"display: inline;\" height=\"120\"/>" ) . appendTo ( img1 ) ;
var img2 = $ ( "<div class='img_block' style='text-align: center;'></div>" ) ;
$ ( "<input type='hidden' value='1'/>" ) . appendTo ( img2 ) ;
$ ( "<img src=\"../../objects/1.gif\" style=\"display: inline;\" height=\"120\"/>" ) . appendTo ( img2 ) ;
var img3 = $ ( "<div class='img_block' style='text-align: center;'></div>" ) ;
$ ( "<input type='hidden' value='2'/>" ) . appendTo ( img3 ) ;
$ ( "<img src=\"../../objects/2.gif\" style=\"display: inline;\" height=\"120\"/>" ) . appendTo ( img3 ) ;
var img4 = $ ( "<div class='img_block' style='text-align: center;'></div>" ) ;
$ ( "<input type='hidden' value='1'/>" ) . appendTo ( img4 ) ;
$ ( "<img src=\"../../objects/3.gif\" style=\"display: inline;\" height=\"120\"/>" ) . appendTo ( img4 ) ;
var img5 = $ ( "<div class='img_block' style='text-align: center;'></div>" ) ;
$ ( "<input type='hidden' value='2'/>" ) . appendTo ( img5 ) ;
$ ( "<img src=\"../../objects/4.gif\" style=\"display: inline;\" height=\"120\"/>" ) . appendTo ( img5 ) ;
tmp _array . push ( img1 , img2 , img3 , img4 , img5 ) ;
tmp _array = shuffle ( tmp _array ) ;
for ( var i = 0 ; i < tmp _array . length ; i ++ ) {
tmp _array [ i ] . draggable ( {
helper : 'clone' ,
zIndex : 100 ,
appendTo : '#data'
} ) ;
tmp _array [ i ] . appendTo ( all _imgs ) ;
}
all _imgs . sortable ( ) ;
imgs _container _one . droppable ( {
hoverClass : 'dropHere' ,
drop : function ( event , ui ) {
if ( $ ( ui . draggable ) . parent ( ) . parent ( ) . html ( ) == $ ( this ) . parent ( ) . html ( ) ) {
var tmp _ui = $ ( ui . draggable ) . parent ( ) ;
$ ( this ) . append ( $ ( ui . draggable ) ) ;
checkCorrectness ( tmp _ui ) ;
}
}
} ) ;
imgs _container _two . droppable ( {
hoverClass : 'dropHere' ,
drop : function ( event , ui ) {
if ( $ ( ui . draggable ) . parent ( ) . parent ( ) . html ( ) == $ ( this ) . parent ( ) . html ( ) ) {
var tmp _ui = $ ( ui . draggable ) . parent ( ) ;
$ ( this ) . append ( $ ( ui . draggable ) ) ;
checkCorrectness ( tmp _ui ) ;
}
}
} ) ;
all _imgs . droppable ( {
hoverClass : 'dropBack' ,
drop : function ( event , ui ) {
if ( $ ( ui . draggable ) . parent ( ) . parent ( ) . html ( ) == $ ( this ) . parent ( ) . html ( ) ) {
if ( this != $ ( ui . draggable ) . parent ( ) [ 0 ] ) {
var tmp _ui = $ ( ui . draggable ) . parent ( ) ;
$ ( this ) . append ( $ ( ui . draggable ) ) ;
checkCorrectness ( tmp _ui ) ;
}
}
}
} ) ;
}
//function that allows to add new category
function addCategory ( obj ) {
var imgs _container = $ ( "<div class='imgs_cont def_cont'>" ) . insertAfter ( obj ) ;
$ ( "<input type='hidden' name='mask' value='" + returnId ( ) + "'/>" ) . appendTo ( imgs _container ) ;
$ ( "<input type='hidden' name='count' value=''/>" ) . appendTo ( imgs _container ) ;
var tmp _div = $ ( "<div style='width: 100%; overflow: hidden;'>" ) . appendTo ( imgs _container ) ;
$ ( "<input type='text' class='cat_desc' value='" + sankoreLang . enter + "'>" ) . appendTo ( tmp _div ) ;
$ ( "<button class='del_category'></button>" ) . appendTo ( imgs _container ) ;
$ ( "<button class='add_category'></button>" ) . appendTo ( imgs _container ) ;
imgs _container . attr ( "ondragenter" , "return false;" )
. attr ( "ondragleave" , "$(this).css(\"background-color\",\"#e6f6ff\"); return false;" )
. attr ( "ondragover" , "$(this).css(\"background-color\",\"#c3e9ff\"); return false;" )
. attr ( "ondrop" , "$(this).css(\"background-color\",\"#e6f6ff\"); return onDropTarget(this,event);" ) ;
}
//add new container
function addContainer ( ) {
var container = $ ( "<div class='cont'>" ) ;
var sub _container = $ ( "<div class='sub_cont'>" ) . appendTo ( container ) ;
var imgs _container = $ ( "<div class='imgs_cont def_cont'>" ) . appendTo ( container ) ;
var close = $ ( "<div class='close_cont'>" ) . appendTo ( container ) ;
var number = $ ( "<div class='number_cont'>" + ( $ ( ".cont" ) . size ( ) + 1 ) + "</div>" ) . appendTo ( sub _container ) ;
$ ( "<input type='hidden' name='mask' value='" + returnId ( ) + "'/>" ) . appendTo ( imgs _container ) ;
$ ( "<input type='hidden' name='count' value=''/>" ) . appendTo ( imgs _container ) ;
var tmp _div = $ ( "<div style='width: 100%; overflow: hidden;'>" ) . appendTo ( imgs _container ) ;
$ ( "<input type='text' class='cat_desc' value='" + sankoreLang . enter + "'/>" ) . appendTo ( tmp _div ) ;
$ ( "<button class='del_category'></button>" ) . appendTo ( imgs _container ) ;
$ ( "<button class='add_category'></button>" ) . appendTo ( imgs _container ) ;
imgs _container . attr ( "ondragenter" , "return false;" )
. attr ( "ondragleave" , "$(this).css(\"background-color\",\"#e6f6ff\"); return false;" )
. attr ( "ondragover" , "$(this).css(\"background-color\",\"#c3e9ff\"); return false;" )
. attr ( "ondrop" , "$(this).css(\"background-color\",\"#e6f6ff\"); return onDropTarget(this,event);" ) ;
container . insertBefore ( $ ( ".add_block" ) ) ;
}
function refreshBlockNumbers ( ) {
var i = 0 ;
$ ( ".cont" ) . each ( function ( ) {
$ ( this ) . find ( ".number_cont" ) . text ( ++ i ) ;
} )
}
//shuffles an array
function shuffle ( arr )
{
var pos , tmp ;
for ( var i = 0 ; i < arr . length ; i ++ )
{
pos = Math . round ( Math . random ( ) * ( arr . length - 1 ) ) ;
tmp = arr [ pos ] ;
arr [ pos ] = arr [ i ] ;
arr [ i ] = tmp ;
}
return arr ;
}
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 ;
}
//changing the style
function changeStyle ( val ) {
switch ( val ) {
case "1" :
$ ( ".b_top_left" ) . removeClass ( "btl_pad" ) . removeClass ( "without_back" ) ;
$ ( ".b_top_center" ) . removeClass ( "btc_pad" ) . removeClass ( "without_back" ) ;
$ ( ".b_top_right" ) . removeClass ( "btr_pad" ) . removeClass ( "without_back" ) ;
$ ( ".b_center_left" ) . removeClass ( "bcl_pad" ) . removeClass ( "without_back" ) ;
$ ( ".b_center_right" ) . removeClass ( "bcr_pad" ) . removeClass ( "without_back" ) ;
$ ( ".b_bottom_right" ) . removeClass ( "bbr_pad" ) . removeClass ( "without_back" ) ;
$ ( ".b_bottom_left" ) . removeClass ( "bbl_pad" ) . removeClass ( "without_back" ) ;
$ ( ".b_bottom_center" ) . removeClass ( "bbc_pad" ) . removeClass ( "without_back" ) ;
$ ( "#wgt_reload" ) . removeClass ( "pad_color" ) . removeClass ( "pad_reload" ) ;
$ ( "#wgt_help" ) . removeClass ( "pad_color" ) . removeClass ( "pad_help" ) ;
$ ( "#wgt_edit" ) . removeClass ( "pad_color" ) . removeClass ( "pad_edit" ) ;
$ ( "#wgt_name" ) . removeClass ( "pad_color" ) ;
$ ( "#wgt_display" ) . addClass ( "display_wood" ) ;
$ ( "#style_select" ) . val ( val ) ;
$ ( "body, html" ) . removeClass ( "without_radius" ) . addClass ( "radius_ft" ) ;
break ;
case "2" :
$ ( ".b_top_left" ) . addClass ( "btl_pad" ) . removeClass ( "without_back" ) ;
$ ( ".b_top_center" ) . addClass ( "btc_pad" ) . removeClass ( "without_back" ) ;
$ ( ".b_top_right" ) . addClass ( "btr_pad" ) . removeClass ( "without_back" ) ;
$ ( ".b_center_left" ) . addClass ( "bcl_pad" ) . removeClass ( "without_back" ) ;
$ ( ".b_center_right" ) . addClass ( "bcr_pad" ) . removeClass ( "without_back" ) ;
$ ( ".b_bottom_right" ) . addClass ( "bbr_pad" ) . removeClass ( "without_back" ) ;
$ ( ".b_bottom_left" ) . addClass ( "bbl_pad" ) . removeClass ( "without_back" ) ;
$ ( ".b_bottom_center" ) . addClass ( "bbc_pad" ) . removeClass ( "without_back" ) ;
$ ( "#wgt_reload" ) . addClass ( "pad_color" ) . addClass ( "pad_reload" ) ;
$ ( "#wgt_help" ) . addClass ( "pad_color" ) . addClass ( "pad_help" ) ;
$ ( "#wgt_edit" ) . addClass ( "pad_color" ) . addClass ( "pad_edit" ) ;
$ ( "#wgt_name" ) . addClass ( "pad_color" ) ;
$ ( "#wgt_display" ) . removeClass ( "display_wood" ) ;
$ ( "#style_select" ) . val ( val ) ;
$ ( "body, html" ) . removeClass ( "without_radius" ) . removeClass ( "radius_ft" ) ;
break ;
case "3" :
$ ( ".b_top_left" ) . addClass ( "without_back" ) . removeClass ( "btl_pad" ) ;
$ ( ".b_top_center" ) . addClass ( "without_back" ) . removeClass ( "btc_pad" ) ;
$ ( ".b_top_right" ) . addClass ( "without_back" ) . removeClass ( "btr_pad" ) ;
$ ( ".b_center_left" ) . addClass ( "without_back" ) . removeClass ( "bcl_pad" ) ;
$ ( ".b_center_right" ) . addClass ( "without_back" ) . removeClass ( "bcr_pad" ) ;
$ ( ".b_bottom_right" ) . addClass ( "without_back" ) . removeClass ( "bbr_pad" ) ;
$ ( ".b_bottom_left" ) . addClass ( "without_back" ) . removeClass ( "bbl_pad" ) ;
$ ( ".b_bottom_center" ) . addClass ( "without_back" ) . removeClass ( "bbc_pad" ) ;
$ ( "#wgt_help" ) . addClass ( "pad_color" ) . addClass ( "pad_help" ) ;
$ ( "#wgt_reload" ) . addClass ( "pad_color" ) . addClass ( "pad_reload" ) ;
$ ( "#wgt_edit" ) . addClass ( "pad_color" ) . addClass ( "pad_edit" ) ;
$ ( "#wgt_name" ) . addClass ( "pad_color" ) ;
$ ( "#wgt_display" ) . removeClass ( "display_wood" ) ;
$ ( "#style_select" ) . val ( val ) ;
$ ( "body, html" ) . addClass ( "without_radius" ) . removeClass ( "radius_ft" ) ;
break ;
}
}
//return id
function returnId ( ) {
var tmp = Math . random ( ) . toString ( ) ;
return tmp . substr ( 2 ) ;
}
//a func for checking when smth will drop
function checkOnDrop ( dest ) {
var tmp _count = dest . find ( "input[name='count']" ) . val ( ) ;
var tmp _mask = dest . find ( "input[name='mask']" ) . val ( ) ;
if ( dest . find ( ".img_block" ) . size ( ) == tmp _count ) {
var tmp _right = true ;
dest . find ( ".img_block" ) . each ( function ( ) {
if ( $ ( this ) . find ( "input" ) . val ( ) != tmp _mask )
tmp _right = false ;
} ) ;
if ( tmp _right )
dest . removeClass ( "def_cont" ) . removeClass ( "red_cont" ) . addClass ( "green_cont" ) ;
else
dest . removeClass ( "def_cont" ) . removeClass ( "green_cont" ) . addClass ( "red_cont" ) ;
} else
dest . removeClass ( "def_cont" ) . removeClass ( "green_cont" ) . addClass ( "red_cont" ) ;
}
//checking source on correctness
function checkCorrectness ( source ) {
if ( ! source . hasClass ( "all_imgs" ) ) {
if ( source . parent ( ) . find ( ".all_imgs" ) . find ( ".img_block" ) . size ( ) == 0 ) {
source . parent ( ) . find ( ".imgs_cont" ) . each ( function ( ) {
checkOnDrop ( $ ( this ) )
} )
} else {
source . parent ( ) . find ( ".imgs_cont" ) . each ( function ( ) {
$ ( this ) . addClass ( "def_cont" ) . removeClass ( "green_cont" ) . removeClass ( "red_cont" ) ;
} )
}
} else {
if ( source . find ( ".img_block" ) . size ( ) > 0 ) {
source . parent ( ) . find ( ".imgs_cont" ) . each ( function ( ) {
$ ( this ) . addClass ( "def_cont" ) . removeClass ( "green_cont" ) . removeClass ( "red_cont" ) ;
} )
} else {
source . parent ( ) . find ( ".imgs_cont" ) . each ( function ( ) {
checkOnDrop ( $ ( this ) )
} )
}
}
}
function onDropTarget ( obj , event ) {
if ( event . dataTransfer ) {
var format = "text/plain" ;
var textData = event . dataTransfer . getData ( format ) ;
if ( ! textData ) {
alert ( ":(" ) ;
}
textData = stringToXML ( textData ) ;
if ( textData . getElementsByTagName ( "ready" ) [ 0 ] . firstChild . textContent == "true" ) {
var tmp = textData . getElementsByTagName ( "path" ) [ 0 ] . firstChild . textContent ;
var img _block = $ ( "<div class='img_block' style='text-align: center;'>" ) ;
$ ( "<div class='close_img'>" ) . appendTo ( img _block ) ;
$ ( "<input type='hidden' value='" + $ ( obj ) . find ( "input[name='mask']" ) . val ( ) + "'/>" ) . appendTo ( img _block ) ;
var tmp _img = $ ( "<img style='display: inline;'/>" ) . attr ( "src" , "../../" + tmp ) . appendTo ( img _block ) ;
img _block . draggable ( {
helper : 'clone' ,
zIndex : 100 ,
appendTo : '#data'
} ) ;
$ ( obj ) . append ( img _block ) ;
if ( tmp _img . height ( ) == 0 ) {
var tmp _id = setInterval ( function ( ) {
if ( tmp _img . height ( ) != 0 ) {
if ( tmp _img . height ( ) >= tmp _img . width ( ) )
tmp _img . attr ( "height" , "120" ) ;
else {
tmp _img . attr ( "width" , "120" ) ;
var h = tmp _img . height ( ) ;
tmp _img . attr ( "height" , h ) ;
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" ) ;
var h = tmp _img . height ( ) ;
tmp _img . attr ( "height" , h ) ;
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 ;
}