Skip to content

Commit a838fc2

Browse files
committed
img list in sessionStorage
1 parent da4b819 commit a838fc2

File tree

10 files changed

+43
-13
lines changed

10 files changed

+43
-13
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ On the other hand put
3333
<ul id="gal_list">drop an image here</ul>
3434
```
3535
for the list where you can drop an enlarged image (which is stored as a name of the file, but it can be easily
36-
used in some different way).
36+
used in some different way by using sessionStorage item named imgList).
3737

3838
To init gallery, put in script.js the following command:
3939

img/gal_close.png

3.66 KB
Loading

img/gal_close.xcf

11 KB
Binary file not shown.

img/gal_left.png

93 Bytes
Loading

img/gal_left.xcf

51 Bytes
Binary file not shown.

img/gal_right.png

93 Bytes
Loading

img/gal_right.xcf

49 Bytes
Binary file not shown.

index.html

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,7 @@
1717
<img src="img/04.jpg" />
1818
<img src="img/05.jpg" />
1919
<img src="img/06.jpg" />
20-
<img src="img/07.jpg" />
21-
<img src="img/08.jpg" />
22-
<img src="img/09.jpg" />
23-
<img src="img/10.jpg" />
24-
20+
<img src="img/07.jpg" />
2521
</div>
2622

2723
<ul id="gal_list">drop an image here</ul>

jquery.gal.js

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,11 @@ $.fn.gal=function(options){
88
var opt={},
99
gal_scene=this;
1010
libs.deepExt.apply(opt,[$.fn.gal.defaults]);
11-
libs.deepExt.apply(opt,[options]);
12-
13-
//console.log(options);
14-
//console.log(opt);
11+
libs.deepExt.apply(opt,[options]),
1512

1613

14+
sessionStorage.removeItem("imgList");
15+
1716

1817
this.children("img").wrap("<div></div>");
1918
this.addClass("gal_scene");
@@ -36,12 +35,29 @@ $.fn.gal=function(options){
3635
var imgName=$(this).parent().children(".gal_img").attr("src"),
3736
li=$("<li></li>");
3837
var button=$("<button />").css({"border":"1px solid #111111", "width":"10px"}).on("click",function(){
39-
$(this).parent().animate({"opacity":"0","width":"0px"},500,function(){$(this).remove();});
38+
$(this).parent().animate({"opacity":"0","width":"0px"},500,function(){
39+
libs.removeFromLocalStorage("imgList",$(this).index());
40+
41+
42+
// console.log($(this).index());
43+
$(this).remove();
44+
});
4045
});
4146
button.html("-");
4247
li.html(imgName);
4348
li.append(button);
4449
gal_list.append(li);
50+
//var listStorage=sessionStorage.getItem("imgList")===null?[]:sessionStorage.getItem("imgList");
51+
//listStorage+=imgName+";";
52+
//sessionStorage.setItem("imgList",listStorage);
53+
//
54+
//
55+
//sessionStorage.setItem(json2menu++,imgName);
56+
57+
libs.addToLocalStorage("imgList",imgName);
58+
59+
60+
4561

4662
$(".gal_enlarged").css({"background-color":"transparent"}).animate({"left":gal_list.offset().left+"px",
4763
"top":gal_list.offset().top+"px",

libs.js

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,26 @@ var libs=(function (){
1717
}
1818
}
1919
};
20-
21-
return {deepExt: deepExt};
20+
21+
22+
var addToLocalStorage=function(listName,value){
23+
var listStorage=sessionStorage.getItem(listName)===null?[]:sessionStorage.getItem(listName);
24+
listStorage+=value+";";
25+
sessionStorage.setItem(listName,listStorage);
26+
27+
28+
};
29+
30+
31+
var removeFromLocalStorage=function(listName,index){
32+
var listStorage=sessionStorage.getItem(listName)===null?[]:sessionStorage.getItem(listName);
33+
var listArray=listStorage.split(";");
34+
listArray.splice(index,1);
35+
sessionStorage.setItem(listName,listArray.join(";"));
36+
}
37+
38+
39+
return {deepExt: deepExt, addToLocalStorage: addToLocalStorage, removeFromLocalStorage: removeFromLocalStorage};
2240
})();
2341

2442

0 commit comments

Comments
 (0)