1define(['hammer', 'jquery', 'fc/ui/stars', 'fc/fb'], function (hammer, $, fc_ui_stars, fc_fb) { 2 function animate(square, current, next, forward) { 3 square.css('overflow', 'hidden'); 4 square.width(square.width() + 'px'); 5 6 var shift = current.width(); 7 8 if (! forward) { 9 shift = -shift; 10 } 11 12 current 13 .css({ 14 position: 'absolute' 15 }) 16 .addClass('running'); 17 18 next 19 .css({ 20 position: 'absolute', 21 left: shift + 'px' 22 }).removeClass('hidden') 23 .addClass('running'); 24 25 var next_width = current.width(); 26 current.width(next_width); 27 next.width(next_width); 28 var square_height = square.height(); 29 var next_height = next.height(); 30 31 if (square_height < next_height) { 32 square.stop(true, false).animate({ 33 height: next_height 34 }, 300, function () { 35 }); 36 } 37 else { 38 var phrases_container_height = square.closest('.grouped-phrases-container').height(); 39 next.find('.phrase').css('height', phrases_container_height + 'px'); 40 next.find('.side-actions').css('top', phrases_container_height + 'px'); 41 } 42 43 current 44 .stop(true, false) 45 .animate({ 46 left: -1 * shift + 'px' 47 }, 400, function() { 48 current.removeAttr('style'); 49 current.addClass('hidden'); 50 current.removeClass('running'); 51 current.width(''); 52 //current.find('.side-actions').css('top', ''); 53 current.find('.phrase').css('height', ''); 54 }); 55 56 next 57 .stop(true, false) 58 .animate({ 59 left: 0 60 }, 400, function() { 61 next.removeAttr('style'); 62 next.removeClass('running'); 63 square.css('overflow', ''); 64 square.width(''); 65 next.width(''); 66 }); 67 } 68 69 function previous(square) { 70 var active = false; 71 var next_active = false; 72 73 _gaq.push(['_trackEvent', 'Phrase Square', 'Previous', '']); 74 75 $.each(square.find('.quote-block-square').get().reverse(), function (i, item) { 76 var item = $(item); 77 if (!item.hasClass('hidden')) { 78 active = item; 79 } else if (active && item.hasClass('hidden')) { 80 next_active = item; 81 return false; 82 } 83 }); 84 85 if (! next_active) { 86 next_active = square.children().last(); 87 } 88 89 animate(square, active, next_active, false); 90 } 91 92 function next(square) { 93 var active = false; 94 var next_active = false; 95 96 _gaq.push(['_trackEvent', 'Phrase Square', 'Next', '']); 97 98 $.each(square.find('.quote-block-square').get(), function (i, item) { 99 var item = $(item); 100 if (!item.hasClass('hidden')) { 101 active = item; 102 } else if (active && item.hasClass('hidden')) { 103 next_active = item; 104 return false; 105 } 106 }); 107 108 if (! next_active) { 109 next_active = square.children().eq(0); 110 } 111 112 animate(square, active, next_active, true); 113 } 114 115 function init_square(square) { 116 var $square = $(square); 117 var hammertime = $square.hammer(); 118 119 if ($square.find('.quote-block-square').length > 1) { 120 if ($square.find('.quote-block-square').length < 4) { 121 $square.find('.grouped-phrases-container').append($square.find('.quote-block-square').clone().addClass('hidden')); 122 } 123 $square.children('.next').on('click', function(e) { 124 next($square.find('.grouped-phrases-container')); 125 e.preventDefault(); 126 }); 127 $square.children('.previous').on('click', function(e) { 128 previous($square.find('.grouped-phrases-container')); 129 e.preventDefault(); 130 }); 131 hammertime.on("dragleft", function(e) { 132 e.preventDefault(); // Blocca il bounce della viewport 133 }); 134 hammertime.on("dragright", function(e) { 135 e.preventDefault(); // Blocca il bounce della viewport 136 }); 137 hammertime.on('dragend', function (e) { 138 var deltaYignorable = Math.abs(e.gesture.deltaY) < Math.abs(e.gesture.deltaX / 3); 139 if (!deltaYignorable) { 140 return; 141 } 142 e.preventDefault(); 143 if (e.gesture.deltaX < 0) { 144 next($square.find('.grouped-phrases-container')); 145 } else if (e.gesture.deltaX > 0) { 146 previous($square.find('.grouped-phrases-container')); 147 } 148 }); 149 } else { 150 $square.children('.next').remove(); 151 $square.children('.previous').remove(); 152 } 153 154 var active_square = $square.find('.quote-block-square').not('.hidden'); 155 active_square.find('.phrase').css('height', $square.height() + 'px'); 156 } 157
158 function init() { 159 $('.grouped-phrases').each(function() { 160 init_square(this); 161 }); 162 $('#content').on('mouseenter', '.quote-block-square .side-actions .share', function (e) { 163 e.preventDefault(); 164 $(this).addClass('active'); 165 $(this).parent().parent().find('.share-box').show(); 166 }); 167 $('#content').on('mouseleave', '.quote-block-square .side-actions .share', function (e) { 168 e.preventDefault(); 169 $(this).removeClass('active'); 170 $(this).parent().parent().find('.share-box').hide(); 171 }); 172 173 fc_ui_stars.init($('.quote-block-square .side-actions')); 174 } 175 176 return { 177 'init': init 178 }; 179});
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.