diff --git a/src/scripts/build.coffee b/src/scripts/build.coffee new file mode 100644 index 0000000..2ff0929 --- /dev/null +++ b/src/scripts/build.coffee @@ -0,0 +1,454 @@ +### +# @description This module is used to generate HTML-Code. +# @copyright 2014 by Tobias Reich +### + +window.build = {} + +build.divider = (title) -> + + "

#{ title }

" + +build.editIcon = (id) -> + + "
" + +build.multiselect = (top, left) -> + + "
" + +build.album = (data) -> + + return '' if not data? + + title = data.title + longTitle = '' + typeThumb = '' + + if title? and title.length > 18 + + title = data.title.substr(0, 18) + '...' + longTitle = data.title + + if data.thumb0.split('.').pop() is 'svg' then typeThumb = 'nonretina' + + html = """ +
+ thumb + thumb + thumb +
+ """ + + if data.password and lychee.publicMode is false + html += "

#{ title }

"; + else + html += "

#{ title }

" + + html += """ + #{ data.sysdate } +
+ """ + + if lychee.publicMode is false + + if data.star is '1' then html += "" + if data.public is '1' then html += "" + if data.unsorted is '1' then html += "" + if data.recent is '1' then html += "" + + html += "
" + + return html + +build.photo = (data) -> + + return '' if not data? + + title = data.title + longTitle = '' + + if title? and title.length > 18 + + title = data.title.substr(0, 18) + '...' + longTitle = data.title + + html = """ +
+ thumb +
+

#{ title }

+ """ + + if data.cameraDate is '1' + html += "#{ data.sysdate }" + else + html += "#{ data.sysdate }" + + html += "
" + + if data.star is '1' then html += "" + if lychee.publicMode is false and data.public is '1' and album.json.public isnt '1' then html += "" + + html += "
" + + return html + +build.imageview = (data, size, visibleControls) -> + + return '' if not data? + + html = """ + + + """ + + if size is 'big' + + if visibleControls is true + html += "
" + else + html += "
" + + else if size is 'medium' + + if visibleControls is true + html += "
" + else + html += "
" + + else if size is 'small' + + if visibleControls is true + html += "
" + else + html += "
" + + return html + +build.no_content = (typ) -> + + html = """ +
+ + """ + + switch typ + when 'search' then html += "

No results

" + when 'share' then html += "

No public albums

" + when 'cog' then html += "

No configuration

" + + html += "
" + + return html + +build.modal = (title, text, button, marginTop, closeButton) -> + + if marginTop? then custom_style = "style='margin-top: #{ marginTop }px;'" + else custom_style = '' + + html = """ +
+
+

#{ title }

+ """ + + if closeButton isnt false then html += "" + + html += "

#{ text }

" + + $.each button, (index) -> + + if this[0] isnt '' + + if index is 0 then html += "#{ this[0] }" + else html += "#{ this[0] }" + + html += """ +
+
+ """ + + return html + +build.signInModal = -> + + html = """ +
+
+

Sign In

+ + +
Version #{ lychee.version }Update available!
+ Sign in +
+
+ """ + + return html + +build.uploadModal = (title, files) -> + + html = """ +
+
+

#{ title }

+ +
+ """ + + console.log files + + files.forEach (file, i, files) -> + + if file.name.length > 40 + file.name = file.name.substr(0, 17) + '...' + file.name.substr(file.name.length-20, 20) + + html += """ +
+ #{ lychee.escapeHTML(file.name) } + """ + + if file.supported is true then html += "" + else html += "Not supported" + + html += """ +

+
+ """ + + html += """ +
+
+
+ """ + + return html + +build.contextMenu = (items) -> + + html = """ +
+
+ + + """ + + items.forEach (item, i, items) -> + + if item[0] is 'separator' and item[1] is -1 + + html += "" + + else if item[1] is -1 + + html += "" + + else if item[2]? + + html += "" + + else + + html += ""; + + html += """ + +
#{ item[0] }
#{ item[0] }
#{ item[0] }
+
+ """ + + return html + +build.tags = (tags, forView) -> + + html = '' + + if forView is true or lychee.publicMode is true then editTagsHTML = '' + else editTagsHTML = ' ' + build.editIcon('edit_tags') + + if tags isnt '' + + tags = tags.split ',' + + tags.forEach (tag, index, array) -> + html += "#{ tag }" + + html += editTagsHTML + + else + + html = "
No Tags#{ editTagsHTML }
" + + return html + +build.infoboxPhoto = (data, forView) -> + + html = """ +

About

+
+ """ + + switch data.public + when '0' then visible = 'No' + when '1' then visible = 'Yes' + when '2' then visible = 'Yes (Album)' + else visible = '-' + + if forView is true or lychee.publicMode is true then editTitleHTML = '' + else editTitleHTML = ' ' + build.editIcon('edit_title') + + if forView is true or lychee.publicMode is true then editDescriptionHTML = '' + else editDescriptionHTML = ' ' + build.editIcon('edit_description') + + infos = [ + ['', 'Basics'] + ['Title', data.title + editTitleHTML] + ['Uploaded', data.sysdate] + ['Description', data.description + editDescriptionHTML] + ['', 'Image'] + ['Size', data.size] + ['Format', data.type] + ['Resolution', data.width + ' x ' + data.height] + ['Tags', build.tags(data.tags, forView)] + ] + + exifHash = data.takestamp+data.make+data.model+data.shutter+data.aperture+data.focal+data.iso + + if exifHash isnt '0' or exifHash isnt '0' + + infos = infos.concat [ + ['', 'Camera'] + ['Captured', data.takedate] + ['Make', data.make] + ['Type/Model', data.model] + ['Shutter Speed', data.shutter] + ['Aperture', data.aperture] + ['Focal Length', data.focal] + ['ISO', data.iso] + ] + + infos = infos.concat [ + ['', 'Share'] + ['Public', visible] + ] + + infos.forEach (info, i, items) -> + + if info[1] is '' or + not info[1]? + + info[1] = '-' + + switch info[0] + + when '' + + # Separator + html += """ + +

#{ info[1] }

+ + """ + + when 'Tags' + + # Tags + if forView isnt true and lychee.publicMode is false + + html += """ +
+

#{ info[0] }

+
#{ info[1] }
+ """ + + else + + # Item + html += """ + + #{ info[0] } + #{ info[1] } + + """ + + html += """ + +
+
+ """ + + return html + +build.infoboxAlbum = (data, forView) -> + + html = """ +

About

+
+ """ + + switch data.public + when '0' then visible = 'No' + when '1' then visible = 'Yes' + else visible = '-' + + switch data.password + when false then password = 'No' + when true then password = 'Yes' + else password = '-' + + switch data.downloadable + when '0' then downloadable = 'No' + when '1' then downloadable = 'Yes' + else downloadable = '-' + + if forView is true or lychee.publicMode is true then editTitleHTML = '' + else editTitleHTML = ' ' + build.editIcon('edit_title_album') + + if forView is true or lychee.publicMode is true then editDescriptionHTML = '' + else editDescriptionHTML = ' ' + build.editIcon('edit_description_album') + + infos = [ + ['', 'Basics'] + ['Title', data.title + editTitleHTML] + ['Description', data.description + editDescriptionHTML] + ['', 'Album'] + ['Created', data.sysdate] + ['Images', data.num] + ['', 'Share'] + ['Public', visible] + ['Downloadable', downloadable] + ['Password', password] + ] + + infos.forEach (info, i, items) -> + + if info[0] is '' + + # Separator + html += """ + +

#{ info[1] }

+ + """ + + else + + # Item + html += """ + + + + + """ + + html += """ +
#{ info[0] }#{ info[1] }
+
+
+ """ + + return html \ No newline at end of file diff --git a/src/scripts/build.js b/src/scripts/build.js deleted file mode 100644 index a74d2f1..0000000 --- a/src/scripts/build.js +++ /dev/null @@ -1,495 +0,0 @@ -/** - * @name Build Module - * @description This module is used to generate HTML-Code. - * @author Tobias Reich - * @copyright 2014 by Tobias Reich - */ - -build = {} - -build.divider = function(title) { - - return "

" + title + "

"; - -} - -build.editIcon = function(id) { - - return "
"; - -} - -build.multiselect = function(top, left) { - - return "
"; - -} - -build.album = function(albumJSON) { - - if (!albumJSON) return ""; - - var album = "", - longTitle = "", - title = albumJSON.title, - typeThumb = ""; - - if (title!==null&&title.length>18) { - title = albumJSON.title.substr(0, 18) + "..."; - longTitle = albumJSON.title; - } - - if (albumJSON.thumb0.split('.').pop()==="svg") typeThumb = "nonretina"; - - album += "
"; - album += "thumb"; - album += "thumb"; - album += "thumb"; - album += "
"; - - if (albumJSON.password&&!lychee.publicMode) album += "

" + title + "

"; - else album += "

" + title + "

"; - - album += "" + albumJSON.sysdate + ""; - album += "
"; - - if (!lychee.publicMode) { - - if(albumJSON.star==1) album += ""; - if(albumJSON.public==1) album += ""; - if(albumJSON.unsorted==1) album += ""; - if(albumJSON.recent==1) album += ""; - - } - - album += "
"; - - return album; - -} - -build.photo = function(photoJSON) { - - if (!photoJSON) return ""; - - var photo = "", - longTitle = "", - title = photoJSON.title; - - if (title!==null&&title.length>18) { - title = photoJSON.title.substr(0, 18) + "..."; - longTitle = photoJSON.title; - } - - photo += "
"; - photo += "thumb"; - photo += "
"; - photo += "

" + title + "

"; - - if (photoJSON.cameraDate==1) { - photo += "" + photoJSON.sysdate + ""; - } else { - photo += "" + photoJSON.sysdate + ""; - } - - photo += "
"; - - if (photoJSON.star==1) photo += ""; - if (!lychee.publicMode&&photoJSON.public==1&&album.json.public!=1) photo += ""; - - photo += "
"; - - return photo; - -} - -build.imageview = function(photoJSON, size, visibleControls) { - - if (!photoJSON) return ""; - - var view = ""; - - view += ""; - view += ""; - - if (size==="big") { - - if (visibleControls) - view += "
"; - else - view += "
"; - - } else if (size==="medium") { - - if (visibleControls) - view += "
"; - else - view += "
"; - - } else if (size==='small') { - - if (visibleControls) - view += "
"; - else - view += "
"; - - - } - - return view; - -} - -build.no_content = function(typ) { - - var no_content = ""; - - no_content += "
"; - no_content += ""; - - if (typ==="search") no_content += "

No results

"; - else if (typ==="share") no_content += "

No public albums

"; - else if (typ==="cog") no_content += "

No configuration

"; - - no_content += "
"; - - return no_content; - -} - -build.modal = function(title, text, button, marginTop, closeButton) { - - var modal = "", - custom_style = ""; - - if (marginTop) custom_style = "style='margin-top: " + marginTop + "px;'"; - - modal += "
"; - modal += "
"; - modal += "

" + title + "

"; - - if (closeButton!==false) { - - modal += ""; - - } - - modal += "

" + text + "

"; - - $.each(button, function(index) { - - if (this[0]!=="") { - - if (index===0) modal += "" + this[0] + ""; - else modal += "" + this[0] + ""; - - } - - }); - - modal += "
"; - modal += "
"; - - return modal; - -} - -build.signInModal = function() { - - var modal = ""; - - modal += "
"; - modal += "
"; - modal += "

Sign In

"; - modal += ""; - modal += ""; - modal += "
Version " + lychee.version + "Update available!
"; - modal += "Sign in"; - modal += "
"; - modal += "
"; - - return modal; - -} - -build.uploadModal = function(title, files) { - - var modal = ""; - - modal += "
"; - modal += "
"; - modal += "

" + title + "

"; - modal += ""; - modal += "
"; - - for (var i = 0; i < files.length; i++) { - - if (files[i].name.length>40) files[i].name = files[i].name.substr(0, 17) + "..." + files[i].name.substr(files[i].name.length-20, 20); - - modal += "
"; - modal += "" + lychee.escapeHTML(files[i].name) + ""; - - if (files[i].supported===true) modal += ""; - else modal += "Not supported"; - - modal += "

"; - modal += "
"; - - } - - modal += "
"; - modal += "
"; - modal += "
"; - - return modal; - -} - -build.contextMenu = function(items) { - - var menu = ""; - - menu += "
"; - menu += "
"; - menu += ""; - menu += ""; - - $.each(items, function(index) { - - if (items[index][0]==="separator"&&items[index][1]===-1) menu += ""; - else if (items[index][1]===-1) menu += ""; - else if (items[index][2]!=undefined) menu += ""; - else menu += ""; - - }); - - menu += ""; - menu += "
" + items[index][0] + "
" + items[index][0] + "
" + items[index][0] + "
"; - menu += "
"; - - return menu; - -} - -build.tags = function(tags, forView) { - - var html = "", - editTagsHTML = (forView===true||lychee.publicMode) ? "" : " " + build.editIcon("edit_tags"); - - if (tags!=="") { - - tags = tags.split(","); - - tags.forEach(function(tag, index, array) { - - html += "" + tag + ""; - - }); - - html += editTagsHTML; - - } else { - - - html = "
No Tags" + editTagsHTML + "
"; - - } - - return html; - -} - -build.infoboxPhoto = function(photoJSON, forView) { - - if (!photoJSON) return ""; - - var infobox = "", - public, - editTitleHTML, - editDescriptionHTML, - infos, - exifHash = ""; - - infobox += "

About

"; - infobox += "
"; - - switch (photoJSON.public) { - case "0": - public = "No"; - break; - case "1": - public = "Yes"; - break; - case "2": - public = "Yes (Album)"; - break; - default: - public = "-"; - break; - } - - editTitleHTML = (forView===true||lychee.publicMode) ? "" : " " + build.editIcon("edit_title"); - editDescriptionHTML = (forView===true||lychee.publicMode) ? "" : " " + build.editIcon("edit_description"); - - infos = [ - ["", "Basics"], - ["Title", photoJSON.title + editTitleHTML], - ["Uploaded", photoJSON.sysdate], - ["Description", photoJSON.description + editDescriptionHTML], - ["", "Image"], - ["Size", photoJSON.size], - ["Format", photoJSON.type], - ["Resolution", photoJSON.width + " x " + photoJSON.height], - ["Tags", build.tags(photoJSON.tags, forView)] - ]; - - exifHash = photoJSON.takestamp+photoJSON.make+photoJSON.model+photoJSON.shutter+photoJSON.aperture+photoJSON.focal+photoJSON.iso; - - if (exifHash!="0"&&exifHash!=="null") { - - infos = infos.concat([ - ["", "Camera"], - ["Captured", photoJSON.takedate], - ["Make", photoJSON.make], - ["Type/Model", photoJSON.model], - ["Shutter Speed", photoJSON.shutter], - ["Aperture", photoJSON.aperture], - ["Focal Length", photoJSON.focal], - ["ISO", photoJSON.iso] - ]); - - } - - infos = infos.concat([ - ["", "Share"], - ["Public", public] - ]); - - $.each(infos, function(index) { - - if (infos[index][1]===""||infos[index][1]===undefined||infos[index][1]===null) infos[index][1] = "-"; - - switch (infos[index][0]) { - - case "": // Separator - infobox += ""; - infobox += "

" + infos[index][1] + "

"; - infobox += ""; - break; - - case "Tags": // Tags - if (forView!==true&&!lychee.publicMode) { - infobox += "
"; - infobox += "

" + infos[index][0] + "

"; - infobox += "
" + infos[index][1] + "
"; - } - break; - - default: // Item - infobox += ""; - infobox += "" + infos[index][0] + ""; - infobox += "" + infos[index][1] + ""; - infobox += ""; - break; - - } - - }); - - infobox += ""; - infobox += "
"; - infobox += "
"; - - return infobox; - -} - -build.infoboxAlbum = function(albumJSON, forView) { - - if (!albumJSON) return ""; - - var infobox = "", - public = "-", - password = "-", - downloadable = "-", - editTitleHTML, - editDescriptionHTML, - infos; - - infobox += "

About

"; - infobox += "
"; - - switch (albumJSON.public) { - case "0": - public = "No"; - break; - case "1": - public = "Yes"; - break; - } - - switch (albumJSON.password) { - case false: - password = "No"; - break; - case true: - password = "Yes"; - break; - } - - switch (albumJSON.downloadable) { - case "0": - downloadable = "No"; - break; - case "1": - downloadable = "Yes"; - break; - } - - editTitleHTML = (forView===true||lychee.publicMode) ? "" : " " + build.editIcon("edit_title_album"); - editDescriptionHTML = (forView===true||lychee.publicMode) ? "" : " " + build.editIcon("edit_description_album"); - - infos = [ - ["", "Basics"], - ["Title", albumJSON.title + editTitleHTML], - ["Description", albumJSON.description + editDescriptionHTML], - ["", "Album"], - ["Created", albumJSON.sysdate], - ["Images", albumJSON.num], - ["", "Share"], - ["Public", public], - ["Downloadable", downloadable], - ["Password", password] - ]; - - $.each(infos, function(index) { - - if (infos[index][1]===""||infos[index][1]===undefined||infos[index][1]===null) infos[index][1] = "-"; - - if (infos[index][0]==="") { - - infobox += ""; - infobox += "

" + infos[index][1] + "

"; - infobox += ""; - - } else { - - infobox += ""; - infobox += ""; - infobox += ""; - infobox += ""; - - } - - }); - - infobox += "
" + infos[index][0] + "" + infos[index][1] + "
"; - infobox += "
"; - infobox += "
"; - - return infobox; - -} \ No newline at end of file