1/** 2 * Codice JS per la homepage 3 */ 4define(['hammer', 'jquery', 'fc/utils', 'i18n'], function (hammer, $, fc_utils, i18n) { 5 var module = {}; 6 7 module.init = function () { 8 module.random_phrases.init(); 9 module.focuses.init(); 10 module.newsletter.init(); 11 module.dayphrase.init(); 12 } 13 14 module.focuses = (function () { 15 16 var previews = 6; 17 var focus_req = false; 18 var total_focuses = 0; 19 20 function swap_image(new_image, old_image) { 21 var old_attrs = old_image.get(0).attributes; 22 for (var i = 0; i < old_attrs.length; i++) { 23 var attr_name = old_attrs[i].name; 24 var tmp = new_image.attr(attr_name); 25 new_image.attr(attr_name, old_attrs[i].value); 26 old_image.attr(attr_name, tmp); 27 } 28 29 old_image.attr('src', old_image.attr('data-color-src')); 30 new_image.attr('src', new_image.attr('data-bw-src')); 31 } 32 33 function swap_link(new_link, old_link) { 34 var href = new_link.attr('href'); 35 new_link.attr('href', old_link.attr('href')); 36 old_link.attr('href', href); 37 38 var index = new_link.data('index'); 39 new_link.data('index', old_link.data('index')); 40 old_link.data('index', index); 41 42 if ($('#focus-active').data('opened')) { 43 var old_height = $('.focus-details').height(); 44 $('.focus-details').height(old_height); 45 close_current_focus(false); 46 open_current_focus(false); 47 } 48 } 49 50 function set_curdate() { 51 var new_date = $('#focus-active').find('img').attr('data-date'); 52 $('#focus-container .focus-date .date-text').text(new_date); 53 } 54 55 function preload_image($item, type) { 56 if ($item.hasClass(type + '-preloaded')) { 57 return; 58 } 59 60 if ($item.find('img').length > 0) { 61 fc_utils.preloadImage.load($item.find('img').data(type + '-src')); 62 $item.addClass(type + '-preloaded'); 63 } 64 } 65 66 function remove_background_on_esc(e) { 67 if (e.keyCode == 27) { 68 close_current_focus(true); 69 } 70 } 71 72 function open_current_focus(add_expose) { 73 if (focus_req) { 74 focus_req.abort(); 75 } 76 var focus_url = $('#focus-active').attr('href'); 77 $('#focus-active').data('opened', 1).addClass('opened'); 78 $('.focus-details').addClass('waiting opened'); 79 $('.focus-details-box').html(i18n.gettext('Attendere ...')); 80 $('.focus-details').disableTextSelect(); 81 focus_req = $.ajax(focus_url, {dataType: 'html'}).done(function (data) { 82 $('.focus-details').height('').removeClass('waiting'); 83 $('.focus-details-box').html($(data).html()); 84
85 var indicators_container = $('<div class="indicators-container"></div>'); 86 for (i = 0; i < total_focuses; i++) { 87 if (i == $('#focus-active').data('index')) { 88 indicators_container.append('<span class="active" data-index="' + i + '"></span>'); 89 } else { 90 indicators_container.append('<span data-index="' + i + '"></span>'); 91 } 92 } 93 $('.focus-details-box').prepend(indicators_container); 94 95 $('.focus-details').enableTextSelect(); 96 $('.focus-details-box .no-select-text').disableTextSelect(); 97 98 var social_parent = $('.focus-details-box'); 99 require(['fc/fb', 'fc/tw'], function (fc_fb, fc_tw) { 100 fc_fb.init(social_parent); 101 fc_tw.init(social_parent); 102 }); 103 104 if (add_expose) { 105 $('#main,#content').css('z-index', 'auto'); 106 $('body').append($('<div id="focus-background" class="display: none"></div>')); 107 var max_opacity = $('#focus-background').css('opacity'); 108 $('#focus-background').css('opacity', 0); 109 $('#focus-background').animate({'opacity': max_opacity}, 500); 110 $(document).on('keyup', remove_background_on_esc); 111 } 112 }).fail(function () { 113 $('.focus-details').height('').removeClass('waiting opened'); 114 $('.focus-details-box').html(''); 115 $('#focus-active').removeClass('opened'); 116 }); 117 118 } 119 120 function close_current_focus(remove_expose) { 121 if ($('#focus-active').data('opened')) { 122 $('.focus-details').removeClass('waiting opened'); 123 $('.focus-details-box').html(''); 124 $('#focus-active').data('opened', '').removeClass('opened'); 125 126 if (remove_expose) { 127 $(document).off('keyup', remove_background_on_esc); 128 $('#focus-background').animate({'opacity': 0}, 500, function () { 129 $('#main,#content').css('z-index', ''); 130 $('#focus-background').remove(); 131 }); 132 } 133 } 134 } 135 136 function next_item() { 137 var next_item = false; 138 var next_item_i = $('#focus-active').data('index') + 1; 139 if (next_item_i >= total_focuses) { 140 next_item_i = 0; 141 } 142 $('#focus-container .items a').each(function () { 143 $this = $(this); 144 if ($this.data('index') == next_item_i) { 145 next_item = $this; 146 return false; 147 } 148 }); 149 if (next_item) { 150 swap_image(next_item.find('img'), $('#focus-active').find('img')); 151 swap_link(next_item, $('#focus-active')); 152 set_curdate(); 153 $('#focus-container').find('.items a').last().after(next_item); 154 preload_image($('#focus-container').find('.items a') 155 .eq(previews - 1), 'color'); 156 preload_image($('#focus-container').find('.items a') 157 .eq(previews), 'bw'); 158 } 159 } 160 161 function previous_item() { 162 var previous_item = false; 163 var previous_item_i = $('#focus-active').data('index') - 1; 164 if (previous_item_i < 0) { 165 previous_item_i = total_focuses - 1; 166 } 167 $('#focus-container .items a').each(function () { 168 $this = $(this); 169 if ($this.data('index') == previous_item_i) { 170 previous_item = $this; 171 return false; 172 } 173 }); 174 if (previous_item) { 175 swap_image(previous_item.find('img'), $('#focus-active').find('img')); 176 swap_link(previous_item, $('#focus-active')); 177 set_curdate(); 178 $('#focus-container').find('.items a').first().before(previous_item); 179 } 180 } 181 182 function init() { 183 total_focuses = $('#focus-container').find('.items a').length + 1; 184 185 $('#focus-active').data('index', 0); 186 $('#focus-container').find('.items a').each(function (index) { 187 $(this).data('index', index + 1); 188 }); 189 190 $('#focus-container').on('click', '.items a', function (e) { 191 if ($(this).attr('id') != 'focus-active') { 192 e.preventDefault(); 193 _gaq.push(['_trackEvent', 'Current Focus', 'Change', '']); 194 swap_image($(this).find('img'), $('#focus-active').find('img')); 195 swap_link($(this), $('#focus-active')); 196 set_curdate(); 197 } 198 }); 199 200 $('#focus-container').on('click', 'div.selector', function (e) { 201 e.preventDefault(); 202 _gaq.push(['_trackEvent', 'Current Focus', 'Next', '']); 203 next_item(); 204 }); 205 206 $('.focus-box').on('click', '.focus-details-box div.selector', function (e) { 207 e.preventDefault(); 208 _gaq.push(['_trackEvent', 'Current Focus', 'Next (Lateral focus)', '']); 209 next_item(); 210 }); 211
212 $('.focus-box').on('click', '.focus-details-box .selector-back', function (e) { 213 e.preventDefault(); 214 _gaq.push(['_trackEvent', 'Current Focus', 'Back (Lateral focus)', '']); 215 previous_item(); 216 }); 217 218 $('#focus-container').find('.items a').slice(0, previews).each(function() { 219 preload_image($(this), 'color'); 220 }); 221 222 $('.focus-box').on('click', '.focus-details-link', function (e) { 223 e.preventDefault(); 224 _gaq.push(['_trackEvent', 'Current Focus', 'Show Details', 'Detail link']); 225 if ($('#focus-active').data('opened')) { 226 open_current_focus(false); 227 } else { 228 open_current_focus(true); 229 } 230 }); 231 232 $('.focus-box').on('click', '#focus-active', function (e) { 233 e.preventDefault(); 234 _gaq.push(['_trackEvent', 'Current Focus', 'Show Details', 'Image']); 235 if ($('#focus-active').data('opened')) { 236 close_current_focus(true); 237 } else { 238 open_current_focus(true); 239 } 240 }); 241 242 $(document).on('click', '#focus-background', function (e) { 243 _gaq.push(['_trackEvent', 'Current Focus', 'Close', '']); 244 close_current_focus(true); 245 }); 246 247 $('.focus-box').on('click', '.indicators-container > span', function (e) { 248 e.preventDefault(); 249 _gaq.push(['_trackEvent', 'Current Focus', 'Change (Indicator)', '']); 250 var new_element_index = $(this).data('index'); 251 var new_element = false; 252 $('#focus-container .items a').each(function () { 253 $this = $(this); 254 if ($this.data('index') == new_element_index) { 255 new_element = $this; 256 return false; 257 } 258 }); 259 if (new_element) { 260 swap_image(new_element.find('img'), $('#focus-active').find('img')); 261 swap_link(new_element, $('#focus-active')); 262 set_curdate(); 263 } 264 }); 265 266 var hammertime = $('#focus-container').hammer(); 267 hammertime.on("dragleft", function(e) { 268 e.preventDefault(); // Blocca il bounce della viewport 269 }); 270 hammertime.on("dragright", function(e) { 271 e.preventDefault(); // Blocca il bounce della viewport 272 }); 273 hammertime.on('dragend', function (e) { 274 var deltaYignorable = Math.abs(e.gesture.deltaY) < Math.abs(e.gesture.deltaX / 3); 275 if (!deltaYignorable) { 276 return; 277 } 278 e.preventDefault(); 279 if (e.gesture.deltaX < 0) { 280 _gaq.push(['_trackEvent', 'Current Focus', 'Next (Gesture)', '']); 281 next_item(); 282 } else { 283 _gaq.push(['_trackEvent', 'Current Focus', 'Previous (Gesture)', '']); 284 previous_item(); 285 } 286 }); 287 288 preload_image($('#focus-active'), 'bw'); 289 preload_image($('#focus-container').find('.items a') 290 .eq(previews), 'bw'); 291 } 292 return { 293 'init': init 294 } 295 }()); 296 297 module.random_phrases = (function () { 298 function init() { 299 if ($('.randomquotes').length == 0) { 300 return; 301 } 302 303 var current_request = false; 304 305 function get_quotes(e) { 306 e.preventDefault(); 307 _gaq.push(['_trackEvent', 'Random Quotes', 'More', '']); 308 309 var $target = $(e.target); 310 var $parent = $target.closest('.randomquotes'); 311 var page = $parent.data('random-phrases-page') || 1; 312 313 if (! current_request) { 314 $target.css('display', 'none').closest('.button').find('div.loading').css('display', 'block'); 315 316 current_request = $.ajax({ 317 url: $target.attr('href'), 318 complete: function (jqXHR, status) { 319 if (status == 'success') { 320 $parent.find('ul.quote-box').append($(jqXHR.responseText).find('li')); 321 $parent.data('random-phrases-page', page); 322 fc_utils.responsive.onDocumentResize(); 323 324 // reload tooltips 325 $parent.find("ul.quote-box a[rel=twipsy]").tooltip({live: true, animation: false}); 326 // reload terms links 327 require(['fc/ui/phrase_list'], function (fc_ui_phrase_list) { 328 fc_ui_phrase_list.linked_text.init(); 329 fc_ui_phrase_list.show_context.init(); 330 fc_ui_phrase_list.share.init($parent.find("ul.quote-box")); 331 }); 332 333 var label = $parent.find('.randomquotes-buttontext').eq((page % $parent.find('.randomquotes-buttontext').length) - 1); 334 $target.text(label.val()); 335 } 336 else { 337 require(['fc/login'], function(fc_login) { 338 fc_login.logged_action(function() { 339 get_quotes(e); 340 }, i18n.gettext('Per continuare a leggere altre frasi estratte a caso dal nostro archivio è necessario registrarsi'), undefined); 341 }); 342 } 343 344 $target.css('display', '').closest('.button').find('div.loading').css('display', 'none'); 345 346 current_request = false;
347 }, 348 data: { 'page': ++page }, 349 dataType: 'text', 350 async: true 351 }); 352 } 353 } 354 355 $('.randomquotes .get-random-phrases').on('click', get_quotes); 356 } 357 return { 358 'init': init 359 }; 360 }()); 361 362 module.newsletter = (function() { 363 function init() { 364 require(['fc/newsletter'], function(fc_newsletter) { 365 fc_newsletter.init($('.content-top-links .newsletter')); 366 }); 367 } 368 return { 369 'init': init 370 } 371 }()); 372 373 module.dayphrase = (function () { 374 var timeout; 375 var interval = 5000; 376 var duration = 700; 377 378 function transition($current, $next) { 379 if ($next.length == 0) { 380 $next = $('.phrase-day .navigator a').eq(0); 381 } 382 383 if ($current.data('index') == $next.data('index')) { 384 return; 385 } 386 387 if (timeout) { 388 clearTimeout(timeout); 389 } 390 391 var dir = ($current.data('index') < $next.data('index') ? 1 : -1); 392 393 $current.removeClass('active'); 394 $next.addClass('active'); 395 396 $current_quote = $('.phrase-day .quote-wrapper').eq($current.data('index')); 397 $next_quote = $('.phrase-day .quote-wrapper').eq($next.data('index')); 398 399 $current_quote.stop(true, false); 400 $next_quote.stop(true, false).css('opacity', '1'); 401 402 var height = $('.phrase-day .quote-window').height(); 403 404 $current_quote 405 .removeClass('hidden') // per le animazioni interrotte 406 .animate({ 407 top: (-dir * height) + 'px' 408 }, duration, function() { 409 $current_quote.removeAttr('style'); 410 $current_quote.addClass('hidden'); 411 }); 412 413 $next_quote 414 .removeClass('hidden') 415 .css({ 416 'top': dir * height 417 }) 418 .animate({ 419 top: '0' 420 }, duration, function() { 421 $next_quote.removeAttr('style'); 422 }); 423 424 loop($next); 425 } 426 427 function init() { 428 $('.phrase-day .navigator').on('click', 'a', function (e) { 429 e.preventDefault(); 430 _gaq.push(['_trackEvent', 'Day Phrase', 'Change', '']); 431 var $this = $(e.target); 432 var $current = $this.parent().find('.active'); 433 transition($current, $this); 434 }); 435 436 $('.phrase-day').on('mouseenter', '.quote-window', function (e) { 437 stop($('.phrase-day .navigator a.active')); 438 }); 439 440 // Calcolo la massima altezza delle frasi 441 var max_height = $('.phrase-day .quote-window .quote-wrapper').not('.hidden').height(); 442 $('.phrase-day .quote-window .quote-wrapper.hidden').each(function () { 443 var $this = $(this); 444 var this_height = $this.css({'top': 1000}).removeClass('hidden').height(); 445 if (this_height > max_height) { 446 max_height = this_height; 447 } 448 }); 449 $('.phrase-day .quote-window').height(max_height); 450 451 var hammertime = $('.phrase-day').hammer(); 452 hammertime.on("dragleft", function(e) { 453 e.preventDefault(); // Blocca il bounce della viewport 454 }); 455 hammertime.on("dragright", function(e) { 456 e.preventDefault(); // Blocca il bounce della viewport 457 }); 458 hammertime.on('dragend', function (e) { 459 var deltaYignorable = Math.abs(e.gesture.deltaY) < Math.abs(e.gesture.deltaX / 3); 460 if (!deltaYignorable) { 461 return; 462 } 463 e.preventDefault(); 464 if (e.gesture.deltaX < 0) { 465 $current = $('.phrase-day .navigator .active'); 466 transition($current, $current.next()); 467 } else if (e.gesture.deltaX > 0) { 468 $current = $('.phrase-day .navigator .active'); 469 transition($current, $current.prev()); 470 } 471 }); 472 473 // start 474 loop($('.phrase-day .navigator a').first().addClass('active')); 475 } 476 477 function stop($current) { 478 clearTimeout(timeout); 479 $('.quote-window').one('mouseout', function(e) { 480 if ($(this).find(e.relatedTarget).length == 0) { 481 loop($current); 482 } 483 else { 484 stop($current); 485 } 486 }); 487 } 488 489 function loop($start) { 490 timeout = setTimeout(function() { 491 transition($start, $start.next()); 492 }, 493 interval); 494 } 495 496 return { 497 'init': init 498 } 499 }()); 500 501 return module; 502});
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.