-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathscript-album.js
83 lines (70 loc) · 2.71 KB
/
script-album.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
var FILTERS = ['grass', 'water', 'building', 'sculpture'];
var PHOTO_FILES = ['alchemist','dome','dome2','kresge','redsculpture','river','simmons','stata','stata2','stata3'];
var NUM_PHOTOS = 8;
//loads pictures (with preloaded tags)
function loadPictures(){
for (p=0; p<NUM_PHOTOS; p++) {
var available = FILTERS.slice();
var filters = [];
var num_filters = Math.floor(Math.random()*FILTERS.length)+1;
for (r=0; r<num_filters; r++) {
var random = Math.floor(Math.random()*available.length);
var f = available[random];
available.splice(random,1);
filters.push(f);
}
var photoFile = PHOTO_FILES[Math.floor(Math.random()*PHOTO_FILES.length)];//file containing the photo chosen
//the entire div
var photoInfo = document.createElement('div');
//the photo div
var photo = document.createElement('div');
photo.setAttribute('id', 'photo-'+p);
photo.setAttribute('class', 'photo');
//the actual picture
var pic = document.createElement('img');
pic.setAttribute('id', 'uploadphoto-'+p);
pic.setAttribute('class', 'pic');
pic.setAttribute('src',"images/" + photoFile + ".jpg");
pic.setAttribute('width', '200px');
pic.setAttribute('height', '200px');
photo.appendChild(pic);
photoInfo.appendChild(photo);
//name for each photo
var name = document.createElement('div');
name.innerHTML = photoFile;
photoInfo.appendChild(name);
//tags for each photo
var tags = document.createElement('div');
tags.innerHTML = "Tags<br>";
//actual tag box
var tagBox = document.createElement('input');
tagBox.setAttribute('type', 'text');
tagBox.setAttribute('data-role', 'tagsinput');
var tagString = "";
for (var i = 0; i < filters.length; i++){
var filter = filters[i];
if (i == 0){
tagString = filter;
} else {
tagString += "," + filter;
}
}
tagBox.setAttribute('value', tagString);
tags.appendChild(tagBox);
photoInfo.appendChild(tags);
var column = document.getElementById('uploadphotos-col-' + (p%4 + 1));
column.appendChild(photoInfo);
}
}
$(document).on('click', '#save-button', function(evt) {
window.location.href = "./portfolio.html";
//somehow get a dialog to appear to show the user that upload was successful
/*
$(document).ready(function(){
$(".container").prepend("<dialog>Successful album upload</dialog>");
});
*/
});
$(document).ready(function() {
loadPictures();
});