[9188] | 1 | //IF IPHONE SAFARI USER "tap" INSTEAD OF "click" |
---|
| 2 | var userAgent = navigator.userAgent.toLowerCase(); |
---|
| 3 | var isiPhone = (userAgent.indexOf('iphone') != -1 || userAgent.indexOf('ipod') != -1) ? true : false; |
---|
| 4 | clickEvent = isiPhone ? 'tap' : 'click'; |
---|
| 5 | |
---|
| 6 | //SCREENSIZE |
---|
| 7 | |
---|
| 8 | $(document).ready(function() { |
---|
| 9 | |
---|
| 10 | jQuery('#save_settings').click(function(e){ |
---|
| 11 | |
---|
| 12 | // WRITE USER SETTINGS |
---|
| 13 | var name = $("#piwigo_name").val(); |
---|
| 14 | localStorage.setItem("piwigo_name", name); |
---|
| 15 | |
---|
| 16 | var url = $("#piwigo_url").val(); |
---|
| 17 | localStorage.setItem("piwigo_url", url); |
---|
| 18 | |
---|
| 19 | var username = $("#piwigo_username").val(); |
---|
| 20 | localStorage.setItem("piwigo_username", username); |
---|
| 21 | |
---|
| 22 | var password = $("#piwigo_password").val(); |
---|
| 23 | localStorage.setItem("piwigo_password", password); |
---|
| 24 | |
---|
| 25 | // WRITE HIGH_RES |
---|
| 26 | var highres = $('#piwigo_highres:checked').val(); |
---|
| 27 | localStorage.setItem("piwigo_highres", highres); |
---|
| 28 | e.preventDefault(); |
---|
| 29 | |
---|
| 30 | // IMAGE SIZE |
---|
| 31 | var width = $("#piwigo_width").val(); |
---|
| 32 | localStorage.setItem("piwigo_width", width); |
---|
| 33 | |
---|
| 34 | var height = $("#piwigo_height").val(); |
---|
| 35 | localStorage.setItem("piwigo_height", height); |
---|
| 36 | |
---|
| 37 | |
---|
| 38 | var urlLogin = url + 'ws.php?format=json&method=pwg.session.login&username=' +username+ '&password=' +password; |
---|
| 39 | //alert(urlLogin); |
---|
| 40 | |
---|
| 41 | $.ajax({ |
---|
| 42 | type: "POST", |
---|
| 43 | url: "http://localhost:8888/piwigo/ws.php", |
---|
| 44 | data: "format=json&method=pwg.session.login&username=admin&password=admin", |
---|
| 45 | success: function(msg){ |
---|
| 46 | //$("#settings .bindSuccess").hide().prepend('<ul id="success" class="success"><li>User data saved!</li></ul>'); |
---|
| 47 | $('<ul id="success" class="success"><li>User data saved!' +msg+ '</li></ul>').hide().prependTo('#settings .bindSuccess').fadeIn(200); |
---|
| 48 | $("#settings #success").delay(2000).fadeOut("slow"); |
---|
| 49 | } |
---|
| 50 | }); |
---|
| 51 | |
---|
| 52 | |
---|
| 53 | }); |
---|
| 54 | |
---|
| 55 | // LOAD USER SETTINGS |
---|
| 56 | var name = localStorage.getItem("piwigo_name"); |
---|
| 57 | $("#piwigo_name").val(name); |
---|
| 58 | |
---|
| 59 | var url = localStorage.getItem("piwigo_url"); |
---|
| 60 | $("#piwigo_url").val(url); |
---|
| 61 | |
---|
| 62 | var username = localStorage.getItem("piwigo_username"); |
---|
| 63 | $("#piwigo_username").val(username); |
---|
| 64 | |
---|
| 65 | var password = localStorage.getItem("piwigo_password"); |
---|
| 66 | $("#piwigo_password").val(password); |
---|
| 67 | |
---|
| 68 | // HIGH_RES - LOAD |
---|
| 69 | var highres = localStorage.getItem("piwigo_highres"); |
---|
| 70 | |
---|
| 71 | if(highres=='on'){ |
---|
| 72 | $('#piwigo_highres').attr("checked","checked"); |
---|
| 73 | } |
---|
| 74 | else{ |
---|
| 75 | |
---|
| 76 | } |
---|
| 77 | |
---|
| 78 | // IMAGE SIZE |
---|
| 79 | var width = localStorage.getItem("piwigo_width"); |
---|
| 80 | $("#piwigo_width").val(width); |
---|
| 81 | |
---|
| 82 | var height = localStorage.getItem("piwigo_height"); |
---|
| 83 | $("#piwigo_height").val(height); |
---|
| 84 | |
---|
| 85 | |
---|
| 86 | $("a.categoriesLink").tap(function(e){ |
---|
| 87 | var url = $(this).attr('url'); |
---|
| 88 | $('.images').empty(); |
---|
| 89 | |
---|
| 90 | $.getJSON(url, |
---|
| 91 | function(data) { |
---|
| 92 | for (var i=0; i<data.result.images._content.length; i++) { |
---|
| 93 | var image = data.result.images._content[i]; |
---|
| 94 | console.log('image loaded ' +image.file); |
---|
| 95 | $('.images').append('<li url="' +image.element_url+ '" class="rounded"><a class="imagesLink pop" file="' +image.file+ '" thumbnail="' +image.tn_url+ '" rel="' +image.high_url+ '" url="' +image.element_url+ '" href="#imageZoom"><img width="143px" src="'+image.tn_url+'"/><div class="file">'+image.file+ '</div></a></li>'); |
---|
| 96 | } |
---|
| 97 | |
---|
| 98 | }); |
---|
| 99 | }); |
---|
| 100 | |
---|
| 101 | $("a.imagesLink").tap(function(e){ |
---|
| 102 | var url = $(this).attr('url'); |
---|
| 103 | $('ul.images li').removeClass('selected'); |
---|
| 104 | $(this).parent('li').addClass('selected'); |
---|
| 105 | $('.imageZoom').empty(); |
---|
| 106 | $('.imageZoom').append('<li class="fullscreen"><img src="'+url+'"/></li>'); |
---|
| 107 | }); |
---|
| 108 | |
---|
| 109 | |
---|
| 110 | $("a.prev").tap(function(e){ |
---|
| 111 | var url = $('li.selected').prev().attr('url'); |
---|
| 112 | var prevLi = $('li.selected').prev(); |
---|
| 113 | var title = $('li.selected .file').html(); |
---|
| 114 | if (typeof url == 'undefined') { |
---|
| 115 | e.preventDefault(); |
---|
| 116 | } else { |
---|
| 117 | //alert(url); |
---|
| 118 | $('.imageZoom').empty(); |
---|
| 119 | $('.imageZoom').append('<li class="fullscreen"><img src="'+url+'"/></li>'); |
---|
| 120 | $('#imageZoom h1').text(title); |
---|
| 121 | console.log('Big image loaded ' +url); |
---|
| 122 | $('ul.images li:not(:first)').removeClass('selected'); |
---|
| 123 | $(prevLi).addClass('selected'); |
---|
| 124 | } |
---|
| 125 | }); |
---|
| 126 | |
---|
| 127 | |
---|
| 128 | |
---|
| 129 | $("a.play").tap(function(e){ |
---|
| 130 | var interval = $(this).replaceWith('<a class="pause" href="#">Pause</a>'); |
---|
| 131 | var url = $('li.selected').next().attr('url'); |
---|
| 132 | var nextLi = $('li.selected').next(); |
---|
| 133 | if (typeof url == 'undefined') { |
---|
| 134 | e.preventDefault(); |
---|
| 135 | } else { |
---|
| 136 | window.setInterval(function(play){ |
---|
| 137 | $("a.next").click(); |
---|
| 138 | },2000); |
---|
| 139 | } |
---|
| 140 | }); |
---|
| 141 | |
---|
| 142 | $("a.pause").tap(function(e){ |
---|
| 143 | $(this).replaceWith('<a class="play" href="#">Play</a>'); |
---|
| 144 | window.clearInterval(function(play){ |
---|
| 145 | $("a.next").click(); |
---|
| 146 | },2000); }); |
---|
| 147 | |
---|
| 148 | |
---|
| 149 | $("a.next").tap(function(e){ |
---|
| 150 | var url = $('li.selected').next().attr('url'); |
---|
| 151 | var nextLi = $('li.selected').next(); |
---|
| 152 | var title = $('li.selected .file').html(); |
---|
| 153 | if (typeof url == 'undefined') { |
---|
| 154 | e.preventDefault(); |
---|
| 155 | } else { |
---|
| 156 | //alert(url); |
---|
| 157 | $('.imageZoom').empty(); |
---|
| 158 | $('.imageZoom').append('<li class="fullscreen"><img src="'+url+'"/></li>'); |
---|
| 159 | $('#imageZoom h1').text(title); |
---|
| 160 | console.log('Big image loaded ' +url); |
---|
| 161 | $('ul.images li:not(:last)').removeClass('selected'); |
---|
| 162 | $(nextLi).addClass('selected'); |
---|
| 163 | } |
---|
| 164 | }); |
---|
| 165 | |
---|
| 166 | |
---|
| 167 | $.getJSON( |
---|
| 168 | /* "http://piwigo.knallimall.org/ws.php?format=json&method=pwg.categories.getList", */ |
---|
| 169 | "http://localhost:8888/piwigo/ws.php?format=json&method=pwg.categories.getList", |
---|
| 170 | function(data) { |
---|
| 171 | /* alert(dump(data)); */ |
---|
| 172 | for (var i=0; i<data.result.categories.length; i++) { |
---|
| 173 | var category = data.result.categories[i]; |
---|
| 174 | console.log('category loaded ' +category.name); |
---|
| 175 | $('.categories').append('<li><a class="categoriesLink" url="http://localhost:8888/piwigo/ws.php?format=json&method=pwg.categories.getImages&cat_id='+category.id+'" href="#images">'+category.name+' </a> <small class="counter">'+category.total_nb_images+' </small></li>'); |
---|
| 176 | } |
---|
| 177 | } |
---|
| 178 | ); |
---|
| 179 | |
---|
| 180 | /** |
---|
| 181 | * Function : dump() |
---|
| 182 | * Arguments: The data - array,hash(associative array),object |
---|
| 183 | * The level - OPTIONAL |
---|
| 184 | * Returns : The textual representation of the array. |
---|
| 185 | * This function was inspired by the print_r function of PHP. |
---|
| 186 | * This will accept some data as the argument and return a |
---|
| 187 | * text that will be a more readable version of the |
---|
| 188 | * array/hash/object that is given. |
---|
| 189 | */ |
---|
| 190 | function dump(arr,level) { |
---|
| 191 | var dumped_text = ""; |
---|
| 192 | if(!level) level = 0; |
---|
| 193 | |
---|
| 194 | //The padding given at the beginning of the line. |
---|
| 195 | var level_padding = ""; |
---|
| 196 | for(var j=0;j<level+1;j++) level_padding += " "; |
---|
| 197 | |
---|
| 198 | if(typeof(arr) == 'object') { //Array/Hashes/Objects |
---|
| 199 | for(var item in arr) { |
---|
| 200 | var value = arr[item]; |
---|
| 201 | |
---|
| 202 | if(typeof(value) == 'object') { //If it is an array, |
---|
| 203 | dumped_text += level_padding + "'" + item + "' ...\n"; |
---|
| 204 | dumped_text += dump(value,level+1); |
---|
| 205 | } else { |
---|
| 206 | dumped_text += level_padding + "'" + item + "' => \"" + value + "\"\n"; |
---|
| 207 | } |
---|
| 208 | } |
---|
| 209 | } else { //Stings/Chars/Numbers etc. |
---|
| 210 | dumped_text = "===>"+arr+"<===("+typeof(arr)+")"; |
---|
| 211 | } |
---|
| 212 | return dumped_text; |
---|
| 213 | } |
---|
| 214 | }); |
---|
| 215 | |
---|
| 216 | // JQTOUCH |
---|
| 217 | var jQT = new $.jQTouch({ |
---|
| 218 | icon: 'jqtouch.png', |
---|
| 219 | addGlossToIcon: false, |
---|
| 220 | startupScreen: 'jqt_startup.png', |
---|
| 221 | statusBar: 'black', |
---|
| 222 | preloadImages: [ |
---|
| 223 | 'themes/piwigo/img/back_button.png', |
---|
| 224 | 'themes/piwigo/img/back_button_clicked.png', |
---|
| 225 | 'themes/piwigo/img/button_clicked.png', |
---|
| 226 | 'themes/piwigo/img/grayButton.png', |
---|
| 227 | 'themes/piwigo/img/whiteButton.png', |
---|
| 228 | 'themes/piwigo/img/loading.gif' |
---|
| 229 | ] |
---|
| 230 | }); |
---|
| 231 | // Some sample Javascript functions: |
---|
| 232 | $(function(){ |
---|
| 233 | // Orientation callback event |
---|
| 234 | $('body').bind('turn', function(e, data){ |
---|
| 235 | if (data.orientation == 'landscape') |
---|
| 236 | { |
---|
| 237 | $(this).addClass('wide'); |
---|
| 238 | $(this).removeClass('small'); |
---|
| 239 | |
---|
| 240 | var $winWidth = $(window).width(); |
---|
| 241 | var $winHeight = $(window).height(); |
---|
| 242 | $(".fullscreen img").attr({ |
---|
| 243 | width: $winWidth, |
---|
| 244 | height: $winHeight |
---|
| 245 | }); |
---|
| 246 | } else{ |
---|
| 247 | $(this).addClass('small'); |
---|
| 248 | $(this).removeClass('wide'); |
---|
| 249 | var $winWidth = $(window).width(); |
---|
| 250 | var $winHeight = $(window).height(); |
---|
| 251 | $(".fullscreen img").attr({ |
---|
| 252 | width: $winWidth, |
---|
| 253 | height: $winHeight |
---|
| 254 | }); |
---|
| 255 | } |
---|
| 256 | |
---|
| 257 | }); |
---|
| 258 | }); |
---|