Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // PLUGIN
- // Form add fields
- function add_fields(link, association, content) {
- var new_id = new Date().getTime();
- var regexp = new RegExp("new_" + association, "g");
- $(link).parent().before(content.replace(regexp, new_id));
- }
- // Clear default input text
- $('input.default_tex_switch').each(function() {
- var default_value = this.value;
- $(this).css('color', '#666'); // this could be in the style sheet instead
- $(this).focus(function() {
- if(this.value == default_value) {
- this.value = '';
- $(this).css('color', '#333');
- }
- });
- $(this).blur(function() {
- if(this.value === '') {
- $(this).css('color', '#666');
- this.value = default_value;
- }
- });
- });
- jQuery.fn.confirmRequired = function() {
- this.live('click', function (){
- return confirm(I18n.t('warnings.areyousure'));
- });
- };
- jQuery.fn.submitOnce = function() {
- $(this).live('submit',function(e){
- // If this form has a .valid() function attached, run it and ensure that
- // it returns true. (Both this and validation are bound to submit event,
- // so we can't be sure that validation ran first.)
- if ($(this).valid && typeof($(this).valid) == 'function') {
- // console.log('validation attached');
- if ($(this).valid()) {
- // console.log('valid!');
- } else {
- // console.log('not valid!');
- return false;
- }
- } else {
- // console.log('no validation attached');
- }
- if ($(this).data('submitted')) {
- // console.log('already submitted!');
- // Prevent submission
- return false;
- } else {
- $(this).data('submitted', true);
- // console.log('not submitted yet!');
- // NOTE: We were binding to the submit event and making it use AJAX
- // instead. If you don't need to do that, you can discard the if/else
- // below and just return true.
- // If you do, this will ensure that things run in the correct order -
- // ensure it's not a dupe submission, then submit it with ajax.
- // Your ajaxifying function should be something like:
- // $('form.ajax').bind('firstsubmit', function(){ // do stuff });
- // For any forms that should be submitted by ajax
- if ($(this).hasClass('ajax')){
- // Custom event needed because prevent_double_submission is already
- // bound to the submit event. We need it to execute before any ajax
- // submission starts, but if they both bind to the submit event, we
- // can't guarantee which will execute first. So instead, we bind
- // prevent_double_submission to submit and any ajax submitter to the
- // firstsubmit event, which we trigger here
- $(this).trigger('firstsubmit');
- // Prevent NORMAL submit - ajax will handle this
- return false;
- // Non-ajax forms submit as usual
- } else {
- return true;
- }
- }
- });
- // Keep chainability
- return $(this);
- };
- // Require all fields to be filled in
- jQuery.fn.requireContent = function() {
- $(this).each(function() {
- var form = $(this);
- if (form.find('input[value=""], textarea:empty').length > 0) {
- $('button[type=submit], input[type=submit]', form).attr('disabled','disabled');
- }
- $("input[type=text], input[type=password], textarea").bind("change keyup blur focus", function() {
- // Check all fields in the form and disable the submit buttons if not all filled
- var emptyfields = 0;
- form.find('input[type=text], textarea').each(function() {
- if ($(this).val() === "") {
- $('button[type=submit], input[type=submit]', form).attr('disabled','disabled');
- emptyfields++;
- }
- });
- if (emptyfields === 0) {
- $('button[type=submit], input[type=submit]', form).removeAttr('disabled');
- }
- });
- });
- };
- // Select All/ Select None
- jQuery.fn.selectAll = function() {
- var form = $(this).parents('form');
- this.live('click', function (){
- form.find('input[type=checkbox][disabled!=true]').attr('checked', true);
- });
- };
- jQuery.fn.selectNone = function() {
- var form = $(this).parents('form');
- this.live('click', function (){
- form.find('input[type=checkbox][disabled!=true]').attr('checked', false);
- });
- };
- jQuery.fn.hideNewAddressForm = function() {
- var fields = this.children("div.field");
- fields.hide();
- this.find('h2').replaceWith("<h2 id='reset'>ou <a href='#order_new_address_form'>introduisez une nouvelle adresse</a></h2>");
- this.find('h2').find('a').click(function() {
- fields.show();
- });
- };
- jQuery.fn.imageRollover = function() {
- $(this).live('mouseover', function() {
- var images = $(this).find("img");
- images.eq(0).hide();
- images.eq(1).show();
- }).live('mouseout', function () {
- var images = $(this).find("img");
- images.eq(1).hide();
- images.eq(0).show();
- });
- };
- jQuery.fn.imageRolloverWithFade = function() {
- $(this).hover(function(){
- $(this).find("img:last").fadeOut("fast");
- }, function(){
- $(this).find("img:last").show();
- });
- };
- //plugin
- jQuery.fn.topLink = function(settings) {
- settings = jQuery.extend({
- min: 1,
- fadeSpeed: 200,
- ieOffset: 50
- }, settings);
- return this.each(function() {
- //listen for scroll
- var el = $(this);
- el.css('display','none'); //in case the user forgot
- $(window).scroll(function() {
- //stupid IE hack
- if(!jQuery.support.hrefNormalized) {
- el.css({
- 'position': 'absolute',
- 'top': $(window).scrollTop() + $(window).height() - settings.ieOffset
- });
- }
- if($(window).scrollTop() >= settings.min)
- {
- el.fadeIn(settings.fadeSpeed);
- }
- else
- {
- el.fadeOut(settings.fadeSpeed);
- }
- });
- });
- };
- // AJAX
- jQuery.ajaxSetup({
- 'beforeSend': function(xhr) {
- //xhr.setRequestHeader("Accept", "text/javascript")
- xhr.setRequestHeader("Accept", "text/javascript, text/html, application/xml, text/xml, */*");
- }
- });
- jQuery(document).ajaxSend(function(event, request, settings) {
- if (typeof(AUTH_TOKEN) == "undefined") return;
- if (settings.type == 'GET') return;
- // settings.data is a serialized string like "foo=bar&baz=boink" (or null)
- settings.data = settings.data || "";
- settings.data += (settings.data ? "&" : "") + "authenticity_token=" + encodeURIComponent(AUTH_TOKEN);
- });
- jQuery.fn.submitWithAjax = function() {
- this.live('submit', function() {
- $.post(this.action, $(this).serialize(), null, "script");
- return false;
- });
- return this;
- };
- jQuery.fn.ajaxLink = function() {
- this.click(function() {
- $.ajax({
- url: this.href,
- dataType: "script"
- });
- return false;
- });
- };
- jQuery.fn.read_more_modal = function() {
- if (this.length >= 1) {
- var description = $(this).html();
- var string_lenght = 300;
- var description_stripped = description.replace(/(<.*?>)/ig,"").substring(0, string_lenght);
- if (description.length > string_lenght) {
- $(this).html(description_stripped).append("... <a href='#' class='read_more'>Lire plus</a><div class='hidden_description'></div>");
- $('.hidden_description').html(description);
- $('.read_more').click(function() {
- $('.hidden_description').modal({
- opacity:80,
- autoResize: true,
- overlayCss: { backgroundColor:"#666" },
- overlayClose:true
- });
- });
- }
- };
- };
- // FILTERS
- $('.product_filter').live('change', function() {
- window.location.hash = '';
- $(this).closest('form').submit();
- });
- $('.filter_select li label').click(function() {
- window.location.hash = '';
- $(this).siblings('input').click();
- $(this).closest('form').submit();
- });
- $('#product_filter form input[type="submit"]:first').hide();
- $('#brand_filter_form input[type="submit"]:first').hide();
- // TOOLTIP
- $('.tooltip').tipsy({gravity: $.fn.tipsy.autoNS, live: true});
- $('.form_guide').tipsy({trigger: 'focus', gravity: 'w', live: true});
- $('label.sizes').tipsy({delayOut: 1600,html: true, live: true});
- // PRODUCT SHOW
- $('#size_select li input[type="radio"]').click(function() {
- $('#favorite_size_select li input[value="'+ $(this).val() +'"]').attr('checked','checked');
- });
- $('#button_add_to_favorites').button({
- icons: {
- primary: 'ui-icon-heart'
- },
- text: true,
- disabled: false
- });
- $('button.add_to_cart').button({
- icons: {
- primary: 'ui-icon-cart'
- },
- text: true,
- disabled: false
- });
- // DOM READY STUF
- $(document).ready(function(){
- $('#top_link').topLink({
- min: 400,
- fadeSpeed: 500
- });
- //smoothscroll
- $('#top_link').click(function(e) {
- e.preventDefault();
- $.scrollTo(0,300);
- });
- // BACK BUTTONS
- var zoom_options = {
- zoomType: 'standard',
- lens:true,
- preloadImages: false,
- alwaysOn:false,
- showEffect: 'fadein',
- zoomWidth: 308,
- zoomHeight: 568,
- preloadText: 'Chargement',
- position:'right'
- //...MORE OPTIONS
- };
- var quick_zoom_options = {
- zoomType: 'standard',
- lens:true,
- preloadImages: true,
- alwaysOn:false,
- zoomWidth: 410,
- zoomHeight: 390,
- showEffect: 'fadein',
- fadeinSpeed: 'slow',
- xOffset: 15,
- preloadText: 'chargement du zoom',
- position:'right'
- //...MORE OPTIONS
- };
- $(".MagicZoom").jqzoom(zoom_options);
- $('.QuickMagicZoom').jqzoom(quick_zoom_options);
- $('.product_gallery_zoom_link').live('click', function(event) {
- var product_id = $(this).attr("id").match(/[\d]+$/);
- $.ajax({
- url: '/products/'+product_id+'/quick_show',
- type: 'get',
- dataType: 'text',
- cache: true,
- success: function(data) {
- $.modal(data, {
- opacity:80,
- minHeight:421,
- autoResize: true,
- overlayCss: { backgroundColor:"#666" },
- overlayClose:true });
- $('#size_select').sizeSelect();
- $(".no_size_tooltip").tipsy({gravity: "w"});
- $('.QuickMagicZoom').jqzoom(quick_zoom_options);
- $('button.add_to_cart').button({
- icons: {
- primary: 'ui-icon-cart'
- },
- text: true,
- disabled: false
- });
- $('#button_add_to_favorites').button({
- icons: {
- primary: 'ui-icon-heart'
- },
- text: true,
- disabled: false
- });
- $('#size_select').bind('click', function() {
- $(".no_size_tooltip").attr('original-title', '');
- $('#size_select li input[type="radio"]').click(function() {
- $('#favorite_size_select li input[value="'+ $(this).val() +'"]').attr('checked','checked');
- });
- });
- }
- });
- return false;
- });
- $('.size_grid_link').live('click', function(event) {
- $.ajax({
- url: '/help/sizes',
- type: 'get',
- dataType: 'text',
- cache: true,
- success: function(data) {
- $.modal(data, {
- opacity:80,
- minHeight:421,
- autoResize: true,
- overlayCss: { backgroundColor:"#666" },
- overlayClose:true });
- }
- });
- return false;
- });
- $('.back_button.product_page a').click(function(){ _gaq.push(['_trackEvent', 'Buttons', 'Click - Back Button - Product show']); });
- $('.back_button.gallery_page a').click(function(){ _gaq.push(['_trackEvent', 'Buttons', 'Click - Back Button - Gallery']); });
- $('form.remoteForm').submitWithAjax();
- $('a.remote').ajaxLink();
- $('.needs_confirmation').confirmRequired();
- $('form.submitOnce').submitOnce();
- $('form.requireContent').requireContent();
- $('a.selectAll').selectAll();
- $('a.selectNone').selectNone();
- $('#order_new_address_form').hideNewAddressForm();
- $('.product .image').imageRollover();
- $('#brands_slideshow .items .brand').imageRolloverWithFade();
- $('#favorite_size_select').hide();
- $(".short").read_more_modal();
- $('.size_chart').click(function() {
- // Act on the event
- });
- // UI STYLES
- $(".uniform select, input:checkbox, input.radio:radio").uniform();
- // Brand submenu
- $("#left_menu .brands").click(function(){
- $("#brands_submenu").slideToggle("fast");
- $(this).toggleClass('close');
- $(this).parent().toggleClass('current');
- return false;
- });
- $('#brands_submenu .brand').hover(function(){
- $(this).siblings().stop().animate({ opacity: 0.5 }, "fast");
- }, function(){
- $(this).siblings().stop().animate({ opacity: 0.8 }, "slow");
- });
- $('.submenu').hover(function() { $(this).parent('li').toggleClass('hovered'); });
- // External links
- $("a[rel='external']").click(function(){
- window.open($(this).attr("href"));
- return false;
- });
- jQuery('#product_page div.pagination a').live('click', function(e) {
- $.bbq.pushState({'page': $.deparam.querystring(e.target.href).page });
- return false;
- });
- $(window).bind("hashchange.page", function(e) {
- if ($.deparam.fragment().page !== undefined) {
- $("<div id='ajax_overlay' style='display: none;'><img src='/images/icons/ajax-loader.gif' /></div>").insertAfter('#product_filter');
- $('#gallery').fadeOut(1500);
- $.scrollTo(0, 1800);
- $("#ajax_overlay").fadeIn(1400, function() {
- $.ajax({
- url: $.param.querystring(document.location.href, {'page': $.bbq.getState("page")}),
- dataType: 'text',
- cache: false,
- success: function(data) {
- $("#products_page_gallery").html(data);
- $("#ajax_overlay").fadeOut(800);
- $('#gallery').fadeIn('fast');
- $("select#cart_item_inventory_item_id").uniform();
- per_page = $.deparam.querystring(e.target.href).per_page === undefined ? 20 : $.deparam.querystring(e.target.href).per_page;
- from = (($.bbq.getState("page") - 1) * per_page + 1);
- to = ($.bbq.getState("page") * per_page);
- $("#total_pages").html("<b>"+from+" - "+to+"</b>");
- }
- });
- });
- }
- });
- if($.deparam.fragment().page) {
- $(window).trigger("hashchange.page");
- } else {
- $.scrollTo(0, 0);
- }
- $("#top_menu a.login").click(function(){
- $('#login').modal({
- opacity:80,
- minHeight:421,
- autoResize: true,
- overlayCss: { backgroundColor:"#666" },
- overlayClose:true
- });
- return false;
- });
- });
- // Hide campaign banner and set cookie
- if ($('.close_campaign').length !== 0) {
- var campaign_id = "campaign_" + $(".campaign").attr('id');
- var campaign_closed = $.cookie(campaign_id);
- $('.close_campaign').toggle(function(){
- $(".campaign_banner").slideUp();
- $(this).parent().find('h3').addClass('toggled');
- $('.close_campaign').text('Montrer');
- $.cookie(campaign_id, "closed");
- },function(){
- $(".campaign_banner").slideDown();
- $('.close_campaign').text('Fermer');
- $(this).parent().find('h3').removeClass('toggled');
- $.cookie(campaign_id, null);
- });
- if (campaign_closed == 'closed') {
- $(".campaign_banner").hide();
- $('.close_campaign').text('Montrer');
- $('.close_campaign').parent().find('h3').addClass('toggled');
- }
- }
Add Comment
Please, Sign In to add comment