ruạṛ
/** * fire it up */ $(window).load(function() { //slideshow $('.slider').orbit({ animation: 'horizontal-slide', // fade, horizontal-slide, vertical-slide, horizontal-push animationSpeed: 800, // how fast animtions are timer: true, // true or false to have the timer advanceSpeed: 4000, // if timer is enabled, time between transitions pauseOnHover: false, // if you hover pauses the slider startClockOnMouseOut: false, // if clock should start on MouseOut startClockOnMouseOutAfter: 1000, // how long after MouseOut should the timer start again directionalNav: false, // manual advancing directional navs captions: false, // do you want captions? captionAnimation: 'fade', // fade, slideOpen, none captionAnimationSpeed: 800, // if so how quickly should they animate in bullets: true, // true or false to activate the bullet navigation bulletThumbs: false, // thumbnails for the bullets bulletThumbLocation: '', // location from this file where thumbs will be afterSlideChange: function(){} // empty function }); }); // */ $(document).ready(function(){ /* * dynamic template alterations * uncomment the ones needed in a particular site */ detect_ie(); tablet_navigation(); menu_width_a('.main-navigation > ul'); //use this for equally-spaced items //menu_width_li('.main-navigation', '.main-navigation > ul > li'); // use this for equal-width items //match_heights(0); //even up content area and sidebar //wings(980); // make outlying elements fill the area between window-edge and content // fill form text and textareas with default content which disappears on focus // needs to run -before- form refill-on-fail script/s form_default('',false); //jquery selector string (all forms by default; optionally hide labels after getting default text // galleries $("a[rel=gallery]").colorbox(); //form validation replace_captcha(); $("form").each(function() { $(this).validate(); }); $(".popup").click(function() { $.colorbox( { href: $(this).attr("href") + "?popup=true", maxWidth: 1000 }); return false; }); $(".stockists .maplink a").colorbox(); $(".fader").hide(); $(".activator").click(function() { $(".fader:not(" + $(this).attr("href") + ")").slideUp(200); $($(this).attr("href")).slideDown(200); return false; }); $('body').click(function(event) { $(".about-popup").fadeOut(); }); $('.about-popup').click(function(){ event.stopPropagation(); }); $('#lew').load('/about-us/lew-austin/?popup=true'); $('#greg').load('/about-us/greg-neill/?popup=true'); $('#lew-click').click(function (event) { event.preventDefault(); event.stopPropagation(); $('#lew').fadeToggle(); $('#greg').hide(); }); $('#greg-click').click(function (event) { event.preventDefault(); event.stopPropagation(); $('#greg').fadeToggle(); $('#lew').hide(); }); }); //end ready /* */ // Run this as well as the $(document).ready() version if you're using web-fonts in the menu. Otherwise there's a chance that the web-fonts will be loaded after the page is ready and the menu will gain the wrong dimensions. $(window).load(function() { //menu_width_a('.main-navigation > ul'); //use this for equally-spaced items }); /** * Activate Design functions */ /* * making menu tablet friendly */ function tablet_navigation(){ // detect touch $('#menu a').on({ touchstart: function(e) { $t = $(this).parent(); $t.siblings('.tap').removeClass('tap'); //put away other menus $t.toggleClass('tap'); // toggle display via tap style if($t.hasClass('tap')) //first tap { return false; } //else second tap go to link window.location.assign($(this).attr('href')); return false; //or else sub-menu pops up briefly when the new page loads for some reason } }); } /** * detect IE and add extra structural elements if necessary */ function detect_ie(){ if(!$.support.htmlSerialize && !$.support.opacity) // IE feature detection { //identify as IE8 or earlier $('body').addClass('ie8'); //add structural elements (usually for rounded corners) /* only run through (uncomment) this if we need it struct = '<span class="ie-tl"></span><span class="ie-tr"></span><span class="ie-br"></span><span class="ie-bl"></span>'; //could put everything in one selector but list for clarity // eg //$('#menu li:first-child, #menu li:last-child').append(struct); //$('#footer').append(struct); // */ //compensate for irregular first-child/last-child support $('li:first-child').addClass('ie-first'); $('li:last-child').addClass('ie-last'); } //end IE detection //flag IE9+ if(!$.support.optSelected && $.support.opacity) { /* if ("onpropertychange" in document && !!window.matchMedia) { $('body').addClass('ie10'); } */ if (Function('/*@cc_on return document.documentMode===10.0@*/')()){ $('body').addClass('ie10'); } else { $('body').addClass('ie9'); } } return; } /** * distribute top menu items to fit page width */ function menu_width_li(menuElementSelector, menuItemsSelector){ //identical width items cont_width = $(menuElementSelector).innerWidth(); menu_items = $(menuItemsSelector); num = menu_items.length; extra = cont_width%num; each = (cont_width-extra)/num; $(menu_items).css('width',each+'px').last().css('width',(each+extra)+'px'); return; } /** * Evenly distributes padding to all the menu items * @param string menuListSelector The selector for the ul tag that wraps around the menu items */ function menu_width_a(menuListSelector) { var menuList = $(menuListSelector).eq(0); if(menuList.is(":visible")) { var width = menuList.width(); var items = menuList.children(); var anchors = items.children("a"); var itemNumber = items.length; var totalUsedWidth = 0; /** * Gets all the width that's been used */ items.each(function() { totalUsedWidth += $(this).outerWidth(true); totalUsedWidth += 1; }); var remainingWidth = width - totalUsedWidth; var extraPadding = remainingWidth % itemNumber; var perPadding = (remainingWidth - extraPadding) / itemNumber; var leftPadding = Math.floor(perPadding / 2); var rightPadding = Math.ceil(perPadding / 2); var remainingExtraPadding = extraPadding; /** * Evenly distributes the extra padding to each menu item */ anchors.each(function() { var thisLeftPadding = leftPadding; if(remainingExtraPadding > 0) { thisLeftPadding += 1; remainingExtraPadding -= 1; $(this).addClass("hasExtraPadding"); } $(this).css( { paddingLeft: "+=" + thisLeftPadding + "px", paddingRight: "+=" + rightPadding + "px" }); }); var i = width; while(items.first().offset().left >= items.last().offset().left && i > 0) { var mores = menuList.find(".hasExtraPadding"); if(mores.length === 0) { anchors.addClass("hasExtraPadding"); mores = anchors; } var removePaddingClass = mores.last(); if(removePaddingClass.css("paddingLeft") > removePaddingClass.css("paddingRight")) { removePaddingClass.css("paddingLeft", "-=1px"); } else { removePaddingClass.css("paddingRight", "-=1px"); } removePaddingClass.removeClass("hasExtraPadding"); i -= 1; } anchors.removeClass("hasExtraPadding"); } } /** * subroutines to expand sections for matching-height display element purposes * eg the sidebar background always reaches the bottom of the content area or vice versa * rewrite as needed * @todo pass list of elements as a parameter */ function match_heights(offset) { //set content area border below upper background. /* n = $('.content-wrapper').innerHeight(); if(n>0){ $(".lower_page_borders").height(n); } // */ //match sidebar height to content, or vice versa //add any further columns or stacked sections as necessary h = Math.max($('.sidebar').height(),$('.content').height())+offset; $('.sidebar').height(h); $('.content').height(h); } /** * expand or shrink design elements outside the content area to match the remaining width of the screen * can do height / offset etc as well if needed */ function wings(contentWidth){ if(contentWidth == undefined) { contentWidth= 980; } w = $('body').width()-contentWidth; //console.log(w); if(w>0) { w = Math.floor(w/2); //h = $('.midsection').height(); //console.log(w,h); //$('.leftwing').css({'width':w,'left':-w,'height':h}); //$('.rightwing').css({'width':w,'right':-w,'height':h}); $('.leftwing').css({'width':w}); $('.rightwing').css({'width':w}); } return; } /** * set up arbitrary form field default text and clearing * default text is taken from * - label if availble then label is hidden * - existing content * replaces search_default_text() * @param string ids wrapper element selector, defaults to checking all forms * @param bool hideLabels toggle secondary functionality */ function form_default(ids,hideLabels) { // san check parameters if(ids == undefined || ids=='') { ids = 'form'; //check all } if(hideLabels == undefined) { hideLabels = false; //check all } // console.log(ids); //test for browser placeholder support placeholderSupport = ("placeholder" in document.createElement("input")); $(ids).find('[placeholder]').each(function(){ $t = $(this); if(!placeholderSupport) { init = $t.attr('placeholder'); //console.log(init);//debugging if(init != '') { $t.val(init).focus(function(){ if($(this).val()==$(this).attr('placeholder')){ $(this).val(''); } }).blur(function(){ if($(this).val()==''){ $(this).val($(this).attr('placeholder')); } }); } } if(hideLabels) { $("label[for=" + $t.attr('id') + "]").hide(); } }); return true; } /** * replace captcha image with hidden field * this function determines when to call the replace and what to call it on * @param string id the id of the input element associated with the captcha; default security_code * @param string wrapper html tag wrapping all captcha related fields (label, image, input) to replace; default p */ function replace_captcha(id,wrapper) { if(id == undefined || id=='') { id = 'security_code'; //check all } if(wrapper == undefined || wrapper=='') { wrapper = 'p'; //check all } $s = $('#'+id); if($s.length > 0) { $p = $s.closest(wrapper); $p.hide(); if($('body')[0].className.match(/ie(8|9)/) !== null) { //$(document).ready(function(){ //we are in ready() replace_c($s,$p); //}); } else { $s.prev('img').load(function(){ replace_c($s,$p) }); } } } /* * replace captcha image with hidden field * this function does the replace */ function replace_c($s,$p){ /* * append Math.random() to make sure it doesn't pull the image from cache (happens on back button) * in which case x-http-request is not detected and raw image code is pushed into field */ $.get('/resources/captcha/CaptchaSecurityImages.php?r='+Math.random(),function(txt){ $h = $('<input type="hidden" name="auth" value="'+txt+'" />'); $p.replaceWith($h); // note IE developer tools don't seem to show up the change to the DOM, but the form works /* * debugging */ //console.log(txt); //$d = $('<input type="text" name="auth" value="" />');// for outputting debugging code from script //$d.val(txt); //$h.after($d); }); } /** * output a formatted price, used in shopping carts * calculate_shipping function declared in page to include db-generated values * @todo replace with money.js */ function currencyFormat(id,val) { val=parseFloat(val); if(val<=0 || isNaN(val)) { $('#'+id).html(''); } else { val = Math.floor(val*100+0.50000000001); cents = val%100; if(cents<10) { cents = "0" + cents; } val = Math.floor(val/100).toString(); //add thousands separator for (var i = 0; i < Math.floor((val.length-(1+i))/3); i++) { val = val.substring(0,val.length-(4*i+3))+','+ val.substring(val.length-(4*i+3)); } $('#'+id).html('$'+val+'.'+cents); } return; } /** * recover form details if server-side validation fails * details are passed back in json format via cookie * @todo jQuery objectify functionality */ function refillFormAdv(x) { //get form fields fields = document.forms[x].elements; //get cookie j = $.cookie(x+'formJson'); if(!j) { //console.log('no J'); //debugging return; } // extract values (code copied from jquery.cookie) //v = eval("("+URLDecode(j)+")"); var pluses = /\+/g; //v = decodeURIComponent(j.replace(pluses, ' ')); v = $.parseJSON(j); for(i in fields) { f = fields[i]; id = f.id; t = f.type; if(id) { //names are often submitted with '-', ids use '_' id = id.replace(/-/g,'_'); } else { //@todo perform a check on name as a fallback continue; } if(t=='radio') { z=eval('v.' + f.name); //radio buttons } else { z=eval('v.' + id); } //console.log(z); // if there is a value for this field in the cookie if(z) { switch(t) { case "text": case 'textarea': case 'select-one': //f.value = z; $(f).val(z); break; case 'radio': case 'select-multiple': //f.checked = true; $(f).val([z]); break; case 'checkbox': if(f.value == z) { f.checked = true; } break; /* case: 'select-one': for(o in f.options) { if(f.options[o] && f.options[o].value == z) { f.options[o].selected=true; } } if(f.onchange) { f.onchange({target : f}); } break; */ // add other element types later if needed default: break; } } } $.removeCookie(x+'formJson'); } /** * helper for refillFormAdv * @todo jQuery objectify functionality */ function URLDecode(v) { return decodeURIComponent(v.replace(/\+/g, ' ')); }
cải xoăn