-
Notifications
You must be signed in to change notification settings - Fork 0
/
flickr2facebook.js
832 lines (676 loc) · 26.1 KB
/
flickr2facebook.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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
/*
* ----------------------------- Flickr2Facebook -------------------------------------
* Simply upload Flickr photos to Facebook with Drag and Drop
*
* Copyright (c) 2012 Martin Wessely, me@creativehead.at
* Project homepage: www.flickr2facebook.com
*
* Licensed under MIT-style license:
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
(function(){
// check if user is on flickr.com #TODO: put if statement to bookmarklet link
if(window.location.href.indexOf("flickr.com") == -1 ) {
alert('Ooops! \n This bookmarklet only works at www.flickr.com.');
return;
}
// check if bookmarklet already is running #TODO: put if statement to bookmarklet link
if(document.getElementById("f2f-overlay") != null) {
alert('Ooops! \n Looks like Flickr2Facebook is already running.');
return;
}
console.log('init Flickr2Facebook ...');
var libraries = [
'http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js',
'https://ajax.googleapis.com/ajax/libs/jqueryui/1.8.18/jquery-ui.min.js',
'https://raw.github.com/andris9/jStorage/master/jstorage.min.js'
];
var dependencies = {
fbApi: 'http://connect.facebook.net/en_US/all.js',
css: 'http://crtvhd.crux.uberspace.de/flickr2facebook/css/style.css'
};
var originalPageSettings = {};
originalPageSettings['paddingTop'] = document.getElementsByTagName('body')[0].style.paddingTop;
var mouse_over_drop = false;
var minimizedHeight = 70;
var dropHeight = 220;
var dropWidth = 220;
var firstUpload = true;
function loadLibraries(){
if (libraries.length === 0) {
initFlickr2Facebook();
return;
}
var done = false;
var script = document.createElement("script");
script.src = libraries.shift();
script.async = true;
script.onload = script.onreadystatechange = function(){
if (!done && (!this.readyState || this.readyState == "loaded" || this.readyState == "complete")) {
done = true;
loadLibraries();
}
};
document.getElementsByTagName("head")[0].appendChild(script);
}
function loadCSS() {
var done = false;
var script = document.createElement("link");
script.rel = "stylesheet";
script.href = dependencies['css'];
script.async = true;
script.onload = script.onreadystatechange = function(){
if (!done && (!this.readyState || this.readyState == "loaded" || this.readyState == "complete")) {
done = true;
//initFlickr2Facebook();
}
};
document.getElementsByTagName("head")[0].appendChild(script);
}
loadCSS();
loadLibraries();
// init bookmarklet
function initFlickr2Facebook () {
var session = getSession();
var htmlBase = '\
<div id="f2f-overlay">\
<div id="f2f-workingarea">\
<div class="f2f-fluid-left">\
<div id="f2f-dropzone" data-state="closed">\
<!-- drops come here -->\
<div class="drop-indicator">\
<div class="center">\
<b>Drop your photos here</b>\
<span>' + ((jQuery.isArray(session)) ? '<i>' + session.length + '</i> photos already dropped' : 'You dropped no photo so far') + '</span>\
</div>\
</div>\
</div>\
</div>\
<div class="f2f-fluid-right">\
<div id="f2f-facebook">\
<div class="protector"></div>\
<div class="init-facebook buttonbar">\
<a id="init-facebook" class="button" href="#">Start editing your photos</a>\
<a class="close-bookmarklet" href="#">or close this bookmarklet</a>\
</div>\
<div class="auth-facebook buttonbar" >\
<a id="auth-facebook" class="button" href="#">Authenticate with facebook</a>\
<span>In order to use this app you need to authenticate with facebook</span>\
</div>\
<form class="album-settings" >\
<div class="status">Connecting to Facebook ...</div>\
<div class="profile">\
<div class="profile-pic"></div>\
<div class="fb-user">\
<h2>User Name</h2>\
<div class="change-user">Not you? <a href="#" id="f2f-logout">Change account</a></div>\
</div>\
</div>\
<div class="album-information">\
<input type="text" id="album-name" placeholder="Your album name" />\
<textarea id="album-description" placeholder="Your album description"></textarea>\
</div>\
<div class="album-url">\
<div class="switch">\
<a class="toggle" data-state="off" id="add-to-photo" href="#" title="Toggle me"></a>\
<span>Add gallery link to each photo</span>\
</div>\
<div class="switch">\
<a class="toggle" data-state="off" id="add-to-album" href="#" title="Toggle me"></a>\
<span>Add gallery link to album description</span>\
</div>\
<input type="text" id="album-url" placeholder="e.g. www.flickr.com/photos/[username]" disabled="disabled" />\
</div>\
<div class="buttonbar">\
<a id="init-upload" class="button" href="#">Upload to Facebook</a>\
<a class="close-bookmarklet" href="#">or close this bookmarklet</a>\
</div>\
</form>\
</div>\
</div>\
</div>\
</div>';
dragifyFlickrPhotos();
$('body').append($(htmlBase));
// set up dropzone
initDropzone();
// first slide down page, second fade in overlay, third load session
var preload = $('<img />').attr('src', '//d26ecy1es9i5xz.cloudfront.net/images/backgrounds/wood-b49ee40a3eaafaa599b1758f4a3253acb944fc18-gz.jpg');
$('body').animate({
'padding-top' : 96
}, 700, 'easeInOutQuart', function(){
$('#f2f-overlay').css('display', 'block').animate({
'opacity' : 1
}, 300, 'easeInOutQuart');
});
// make flickr photos draggable
function dragifyFlickrPhotos(){
$('#photo-drag-proxy, .facade-of-protection, .spaceball').remove();
$('img').not('.drop-src, .buddyicon, .BuddyIconX').each( function (e){
var source = $(this).attr('src');
if (typeof source !== 'undefined' && source.indexOf('staticflickr.com') != -1) {
// add move cursor and append drag handler
$(this).css({
cursor : 'move'
}).attr({
title : 'Drag me to your album'}
).draggable({
appendTo: "body",
helper: "clone",
cursor: "move",
cursorAt: { top: 30, left: 30 }
});
}
});
}
//read session
function getSession(){
// return local storage
try {
return JSON.parse($.jStorage.get('f2f-droped-photos'));
} catch(e) {
return null;
}
}
//prevent duplicates in dropzone
function preventDuplicates(id){
// read local storage
var session = getSession();
// check if current photo id already exists in session
if(jQuery.isArray(session)){
for(var i = 0; i < session.length; i++){
if(session[i].original == id)
return false;
}
}
// drop does not exist in session
return true;
}
// remove drop from session
function removeFromSession(id){
// read local storage
var session = getSession();
// search for current photo is in session and remove
for(var i = 0; i < session.length; i++){
if(session[i].original == id){
session.splice(i,1);
}
}
// save changes
$.jStorage.set('f2f-droped-photos', JSON.stringify(session));
}
// add drop to session
function addToSession(id, thumb, highRes, description){
// Y?
thumb = thumb.toString();
// create object of drop
var update = {
source: thumb,
highRes: highRes,
description: description,
original: id
};
// add object to session
var session = (getSession() == null) ? [] : getSession();
session[session.length] = update;
// write drop data in local storage
$.jStorage.set('f2f-droped-photos', JSON.stringify(session));
// update drop count
if($('.drop-indicator span i').length == 0){
$('.drop-indicator span').empty().append('<i>' + session.length + '</i> photos already dropped');
}else{
$('.drop-indicator span i').text(session.length);
}
}
// load session and append to dropzone
function loadSession(){
// read local storage
var session = getSession();
if (session == null) return;
// add drops to dropzone
for(var i = 0; i < session.length; i++){
appendDrop(session[i].original, session[i].source, session[i].highRes, session[i].description);
}
}
function clearSession(){
$.jStorage.deleteKey('f2f-droped-photos');
}
// append drop to dropzone
function appendDrop(id, thumb, highRes, description){
// build html and append
var item = $('\
<div class="drop ui-selectee">\
<div class="drop-preview">\
<div class="drop-image">\
<img class="drop-src" src="' + thumb + '"/>\
<div class="loader"></div>\
<a class="drop-delete" title="Remove" href="#"><span>[x]</span></a>\
</div>\
</div>\
<div class="drop-meta">\
<textarea class="description" rows="1" title="Description" placeholder="Add a description" wrap="off">' + description + '</textarea>\
<input type="hidden" id="highRes" name="highRes" class="highRes" value="' + highRes +'">\
<input type="hidden" id="dropId" name="dropId" class="dropId" value="' + id + '">\
</div>\
</div>')
.appendTo('#f2f-dropzone');
// add delete functionality to current drop
addDeleteDropHandler();
updateCurrentSelection();
$("#f2f-dropzone").scrollTop($("#f2f-dropzone").get(0).scrollHeight - dropHeight);
}
// use flickr api to get all photos sizes of a flickr photo
function getPhotoSizes(id, description){
// ["Square", "Large Square", "Thumbnail", "Small", "Small 320", "Medium", "Medium 640", "Medium 800", "Large", "Large 1600"]
$.getJSON('http://api.flickr.com/services/rest/?method=flickr.photos.getSizes&api_key=3d4c2cd9b91afa47c3447b552f709d00&photo_id=' + id + '&format=json&nojsoncallback=1', function(data) {
// save path to thumbnail
thumb = jQuery.map(data['sizes'].size, function(o) {
if(o.label === 'Small')
return o.source;
});
// save path to highest resolution available
highRes = data['sizes'].size[data['sizes'].size.length-1].source;
// if edit mode on, add drop to dropzone
if($('#f2f-dropzone').attr('data-state') == 'opened')
appendDrop(id, thumb, highRes, description);
// add photo to session
addToSession(id, thumb, highRes, description);
});
}
// ultra complex animation for expanding working area
function expandDropzone(){
// calculate how many drop fit in a row and how many rows exist
var dropsInRow = Math.floor( $('#f2f-dropzone').width() / $('.drop').width() );
var numberOfRows = Math.ceil( $('.drop').length / dropsInRow );
// expand dropzone to height of 2 rows or more
if(numberOfRows > 2){
var newHeight = dropHeight * numberOfRows;
var maxHeight = (newHeight > $(window).height()-100) ? $(window).height()-100 : newHeight;
}else{
maxHeight = 2 * dropHeight;
}
$('#f2f-dropzone').stop().animate({
height : maxHeight
}, 800, 'easeInOutQuart', function(){
if(!firstUpload)
$('#f2f-facebook .album-settings').addClass('loaded');
}).attr('data-state', 'opened');
$('body').stop().animate({
paddingTop : (maxHeight+26)
}, 800, 'easeInOutQuart');
}
// update topbar with current selected items
function updateCurrentSelection(location){
if(typeof location != 'undefined')
$('.selection #current').text($('.drop' + location).length);
$('.selection #total').text($('.drop').length);
}
// make drop deletable
function addDeleteDropHandler(){
$('.drop-delete').click(function(e){
e.preventDefault();
$(this).closest('.drop').stop().fadeOut('500', function(){
removeFromSession($(this).closest('.drop').find('#dropId').val());
$(this).remove();
});
});
}
// validate upload form
function validateUploadForm(){
if($('#album-name').val() == ''){
alert('Ooops! Looks like you forgot to give your album a name.');
return false;
}else if($('#album-description').val() == ''){
alert('Ooops! Looks like you forgot to give your album a description.');
return false
}else if($('.toggle[data-state="on"]').length > 0 && $('#album-url').val() == ''){
alert('Ooops! Looks like you forgot to add an URL to your album.');
return false
}else{
return true;
}
}
// trigger facebook init
function run_fb(){
// check if flickr api is already loaded
var isFacebookified = function () {
return typeof window.FB === 'object';
};
if (isFacebookified()) {
// connect to facebook
FB.getLoginStatus(updateFacebookUI);
FB.Event.subscribe('auth.statusChange', updateFacebookUI);
} else {
var root_node = document.createElement('div');
root_node.id = 'fb-root';
document.getElementsByTagName('body')[0].appendChild(root_node);
var js = document.createElement('script');
js.id = 'facebook-jssdk';
js.async = true;
js.src = dependencies['fbApi'];
js.onreadystatechange = js.onload = function () {
// connect to facebook
fb_connect();
};
document.getElementsByTagName('head')[0].appendChild(js);
}
}
// call FB.init and get login status
function fb_connect(){
// facebook connect configuration
window.fbAsyncInit = function() {
FB.init({ appId: '353631031369003',
status: true,
cookie: true,
xfbml: true,
oauth: true
});
// run once with current status and whenever the status changes
FB.getLoginStatus(updateFacebookUI);
FB.Event.subscribe('auth.statusChange', updateFacebookUI);
};
}
function updateFacebookUI(response) {
if (response.authResponse) {
//user is already logged in and connected
FB.api('/me', function(info) {
loginToFacebook(response, info);
});
} else {
//user is not connected to your app or logged out
$('.album-settings').removeClass('init').removeClass('loaded');
$('.auth-facebook').addClass('init');
$('#auth-facebook').click(function(){
FB.login(function(response) {
if (response.authResponse) {
FB.api('/me', function(info) {
loginToFacebook(response, info);
});
} else {
//user cancelled login or did not grant authorization
}
}, {scope:'status_update,publish_stream,user_about_me'});
});
}
}
// try login to facebook
function loginToFacebook(response, info){
if (response.authResponse) {
var accessToken = response.authResponse.accessToken;
$('.auth-facebook').removeClass('init');
$('#f2f-facebook .profile-pic').css('background-image', 'https://graph.facebook.com/' + info.id + '/picture');
$('#f2f-facebook .fb-user h2').text(info.name);
$('#f2f-facebook .album-settings').removeClass('init').addClass('loaded');
}else{
alert('Ooops! Looks like the facebook login didn\'t succeed');
}
}
var uploadToFacebook;
var alreadyUploaded = 0;
var albumId = '';
// create album and call upload method
function initFacebookUpload(){
blockUI();
uploadToFacebook = getSession();
var albumName = $('#album-name').val();
var albumMessage = $('#album-description').val();
if($('#add-to-album').attr('data-state') == 'on')
albumMessage = albumMessage + '\n\n' + $('#album-url').val();
FB.api('/me/albums', 'post', {
name : albumName,
message : albumMessage
}, function(response) {
if (!response || response.error) {
alert('Ooops. There occured an error while uploading your photos to facebook :(');
} else {
albumId = response.id;
fb_upload_photo();
}
});
}
function blockUI(){
$('.drop').die().css({ opacity : 0.5 });
$('.description').attr('disabled', 'disabled');
$('#f2f-dropzone').selectable('disable').droppable('disable');
$('.ui-selected').removeClass('ui-selected');
$('#f2f-facebook').addClass('disabled').find('.protector').css({ height : $('#f2f-dropzone').height() });
$('#init-upload').text('Uploading photos to Facebook ...');
}
function showSuccess(){
firstUpload = false;
$('.album-settings').removeClass('loaded');
$('#f2f-facebook').removeClass('disabled');
$('#f2f-dropzone .drop-indicator').css({ display : 'none' });
$('#f2f-dropzone .drop').remove();
$('#f2f-dropzone').animate({
height : minimizedHeight
}, 1000, 'easeInOutQuart', function(){
var success = $('<div id="f2f-success"><span>Your photos have been uploaded to Facebook <a class="close-bookmarklet" href="#">Close</a></span></div>');
$('#f2f-workingarea').addClass('uploadDone');
$('#f2f-dropzone').append(success);
$('#f2f-dropzone').unbind('mousedown').die();
});
$('body').animate({
paddingTop : (minimizedHeight+26)
}, 1000, 'easeInOutQuart');
}
// upload photos to album
function fb_upload_photo(){
if((uploadToFacebook.length) == (alreadyUploaded)){
$('.uploading').removeClass('uploading').not('.uploaded').addClass('uploaded');
clearSession();
showSuccess();
//alert('Voila. Your photos have been uploaded to facebook :)');
}else{
alreadyUploaded++;
$('.uploading').removeClass('uploading').addClass('uploaded');
//console.log($('#dropId[value="' + uploadToFacebook[alreadyUploaded-1].original + '"]').closest('.drop').find('.loader').css({ display : 'block' }));
$('#dropId[value="' + uploadToFacebook[alreadyUploaded-1].original + '"]').closest('.drop').addClass('uploading');
var imgURL = uploadToFacebook[alreadyUploaded-1].highRes;
var imgDesc = uploadToFacebook[alreadyUploaded-1].description;
if($('#add-to-photo').attr('data-state') == 'on')
imgDesc = imgDesc + '\n\n' + $('#album-url').val();
FB.api('/' + albumId + '/photos', 'post', {
message: imgDesc,
url: imgURL
}, function(response){
if (!response || response.error) {
alert('Ooops! Looks like there was an error with uploading: ' + imgURL);
} else {
fb_upload_photo();
}
});
}
}
// add select and sort functionality to dropzone
function extendDropzone(){
// make dropzone selectable
$('#f2f-dropzone').selectable({
selecting: function(event, ui) {
// update current selection info on each drop added to selection
updateCurrentSelection('.ui-selecting');
},
unselecting: function(event, ui) {
// update current selection info on each drop added to selection
updateCurrentSelection('.ui-selecting');
},
selected: function(event, ui){
$('.drop textarea:focus').blur().attr('wrap', 'off');
}
});
}
$('#init-facebook').live('click', function(e){
e.preventDefault();
$(this).parent().hide();
$('.drop-indicator').hide();
if(firstUpload){
$('#f2f-facebook .album-settings').addClass('init');
run_fb();
loadSession();
expandDropzone();
extendDropzone();
}else{
$('#f2f-success').remove();
$('#init-upload').text('Upload to Facebook');
$('#album-name').val('');
$('#album-description').text('');
$('#album-url').val('');
$('.toggle').attr('data-state', 'off');
expandDropzone();
extendDropzone();
}
});
$('.close-bookmarklet').live('click', function(e){
e.preventDefault();
$('#f2f-overlay').fadeOut(1000, function(){
$(this).empty().remove();
$('body').animate({
paddingTop : originalPageSettings['paddingTop']
}, 1000, 'easeInOutQuart', function(){
// detach events, clean up
$('#init-facebook').die();
$('.drop').die();
$('#f2f-dropzone').die();
$('.drop textarea').die();
$('#clear-session').die();
$('#f2f-overlay .toggle').die();
$('#f2f-logout').die();
$('#init-upload').die();
});
});
});
$('#f2f-logout').live('click', function(e){
e.preventDefault();
FB.logout(function(response) {
//user logged out
});
});
// trigger facebook upload
$('#init-upload').live('click', function(e){
e.preventDefault();
if(validateUploadForm())
initFacebookUpload();
});
// initialize dropzone
function initDropzone(){
//append drop handler to dropzone
$('#f2f-dropzone').droppable({
activeClass: 'ui-state-default',
hoverClass: "ui-state-hover",
tolerance: "pointer",
over: function(event, ui) { // add placeholder when drop enters dropzone
$(ui.helper).addClass('allowed');
if($(this).attr('data-state') != 'closed' && $('.drop-placeholder').length == 0)
$('<div class="drop-placeholder"/>').stop().fadeIn(300, 'easeInOutQuart').appendTo(this);
// scroll to bottom when user enters dropzone
$("#f2f-dropzone").scrollTop($("#f2f-dropzone").get(0).scrollHeight - dropHeight);
},
out: function(event, ui){ //remove placeholder when drop leaves dropzone
$(ui.helper).removeClass('allowed');
$('.drop-placeholder').stop().fadeOut(500, 'easeInOutQuart', function(){ $(this).remove(); });
},
drop: function( event, ui ) {
$('.drop-placeholder').remove();
if(!$(ui.draggable).hasClass('ui-sortable-helper')){
var id = $(ui.draggable).attr('src') || '';
id = id.split('/');
id = id[id.length-1].split('_');
id = id[0];
// prevent duplicates in collection
if(preventDuplicates(id)){
// create dom for new drop and append to dropzone
getPhotoSizes(id, (typeof ui.draggable.attr('alt') != 'undefined') ? ui.draggable.attr('alt') : '');
}else{
alert('This photo is already in your album.');
}
}
}
}).mousedown(function(e){
// if command/windows key is pressed, add drop to selection
if(e.metaKey && mouse_over_drop){
$(e.target).closest('.drop').toggleClass('ui-selected');
e.stopImmediatePropagation();
e.stopPropagation();
e.preventDefault();
return false;
}
});
// add hover effect for drops when only when user is not drawing selection
// jquery solution because of issue with css hover when drawing selection
$('.drop')
.live('mouseenter', function(e){
mouse_over_drop=true;
if($('.ui-selectable-helper').length == 0){
$(this).css({ background : 'rgba(34,34,34,0.25)'})
.find('.drop-delete').stop().fadeIn('300');
}
}).live('mouseleave', function(e){
mouse_over_drop=false;
$(this).css({ background : 'none'})
.find('.drop-delete').stop().fadeOut('300');
});
// blur textarea on click outside of any drop
$("#f2f-dropzone").live('mousedown', function(){
if(! mouse_over_drop) {
$('.drop textarea:focus').blur().attr('wrap', 'off');
}
});
// select drop when textarea gets focus
$('.drop textarea').live('focus', function(){
$('.ui-selected').removeClass('ui-selected');
$(this).attr('wrap', 'on').closest('.drop').addClass('ui-selected');
});
// save session when drop description loses focus
$('.drop textarea').live('blur', function(){
$(this).attr('wrap', 'off');
});
// save session when when user presses enter
$('.drop textarea').live('keydown', function(e){
if(e.which == 13 && e.shiftKey) {
$(this).blur().attr('wrap', 'off');
}
});
// select all drops when user presses command/windows + a
$(document).live('keydown', function(e){
if($('textarea[wrap="on"]').length === 0 && e.metaKey && e.keyCode == '65'){
e.preventDefault();
$('.drop').addClass('ui-selected');
}
});
// on click clear session
$('#clear-session').live('click', function(e){
e.preventDefault();
$('#f2f-dropzone').empty();
$.jStorage.deleteKey('f2f-droped-photos');
});
// switch toggles
$('#f2f-overlay .toggle').live('click', function(e){
e.preventDefault();
if($(this).attr('data-state') == 'off'){
$(this).attr('data-state', 'on');
$('#album-url').removeAttr('disabled').focus();
}else{
$(this).attr('data-state', 'off');
if($('.toggle[data-state="on"]').length == 0)
$('#album-url').attr('disabled', 'disabled');
}
});
// END initDropzone()
}
}
// YOU REACHED THE FUCKING END. GRATS!
})();