diff --git a/app/models/outfit.rb b/app/models/outfit.rb index fa5bb346..7b314f08 100644 --- a/app/models/outfit.rb +++ b/app/models/outfit.rb @@ -73,7 +73,8 @@ class Outfit < ActiveRecord::Base Outfit.new.tap do |outfit| name = params.delete(:name) starred = params.delete(:starred) - if user + anonymous = params.delete(:anonymous) == "true" + if user && !anonymous outfit.user = user outfit.name = name outfit.starred = starred diff --git a/app/stylesheets/outfits/_edit.sass b/app/stylesheets/outfits/_edit.sass index 574be200..a6d2a537 100644 --- a/app/stylesheets/outfits/_edit.sass +++ b/app/stylesheets/outfits/_edit.sass @@ -130,20 +130,22 @@ body.outfits-edit float: right button display: none + #share-outfit + display: inline-block &.loading background: image: image-url("loading.gif") position: left center repeat: no-repeat padding-left: 20px - #save-outfit, #share-outfit, #save-outfit-not-signed-in, #save-current-outfit, #save-outfit-copy, #save-outfit-finish + #save-outfit, #save-outfit-not-signed-in, #save-current-outfit, #save-outfit-copy, #save-outfit-finish +loud-awesome-button-color - #current-outfit-permalink + #current-outfit-permalink, #shared-outfit-permalink display: none margin-right: .25em img +icon - #current-outfit-url + #shared-outfit-url display: none width: 15em #preview @@ -474,13 +476,16 @@ body.outfits-edit &.saving-outfit #save-outfit-form display: block - #save-outfit, #save-current-outfit, #save-outfit-copy, #current-outfit-permalink + #save-outfit, #save-current-outfit, #save-outfit-copy, #current-outfit-permalink, #shared-outfit-permalink, #share-outfit, #shared-outfit-url display: none &.user-not-signed-in - #share-outfit, #save-outfit-not-signed-in + #save-outfit-not-signed-in display: inline-block - #save-outfit-wrapper.shared-outfit - #current-outfit-permalink, #current-outfit-url - display: inline-block + + #save-outfit-wrapper.shared-outfit + #shared-outfit-permalink, #shared-outfit-url + display: inline-block + #current-outfit-permalink + display: none !important diff --git a/app/views/outfits/edit.html.haml b/app/views/outfits/edit.html.haml index b98d3573..8132190e 100644 --- a/app/views/outfits/edit.html.haml +++ b/app/views/outfits/edit.html.haml @@ -16,10 +16,12 @@ %ul #save-outfit-wrapper %a#current-outfit-permalink{:target => '_blank'} - = image_tag 'link_go.png', :alt => 'Permalink', :title => 'Permalink' - %input#current-outfit-url.outfit-url{:type => 'text'} - %button#save-outfit Save outfit + = image_tag 'link_go.png', :alt => 'Permalink', :title => 'Permalink to current outfit' + %a#shared-outfit-permalink{:target => '_blank'} + = image_tag 'link_go.png', :alt => 'Permalink', :title => 'Permalink to shared outfit' + %input#shared-outfit-url.outfit-url{:type => 'text'} %button#share-outfit Share outfit + %button#save-outfit Save outfit %button#save-outfit-not-signed-in Log in to save %button#save-current-outfit Save "current outfit" %button#save-outfit-copy Save a copy @@ -118,3 +120,4 @@ - content_for :javascripts do = include_javascript_libraries :jquery, :swfobject, :jquery_tmpl = include_javascripts :edit_outfit_package + diff --git a/public/javascripts/outfits/edit.js b/public/javascripts/outfits/edit.js index 05f940c1..f64ea206 100644 --- a/public/javascripts/outfits/edit.js +++ b/public/javascripts/outfits/edit.js @@ -34,9 +34,9 @@ Partial.ItemSet = function ItemSet(wardrobe, selector) { var item_set = this, ul = $(selector), items = [], setClosetItems, setOutfitItems, setOutfitItemsControls, no_assets_full_message = $('#no-assets-full-message'), container = $('#container'); - + Partial.ItemSet.setWardrobe(wardrobe); - + function prepSetSpecificItems(type) { return function (specific_items) { var item, worn, li; @@ -51,15 +51,15 @@ Partial.ItemSet = function ItemSet(wardrobe, selector) { } } } - + setClosetItems = prepSetSpecificItems('closeted'); - + setOutfitItemsControls = prepSetSpecificItems('worn'); setOutfitItems = function (specific_items) { setOutfitItemsControls(specific_items); setHasAssets(specific_items); } - + function setHasAssets(specific_items) { var item, no_assets, li, no_assets_message; for(var i = 0, l = specific_items.length; i < l; i++) { @@ -75,7 +75,7 @@ Partial.ItemSet = function ItemSet(wardrobe, selector) { })(li); } } - + this.setItems = function (new_items) { var item, li, controls, info_link; items = new_items; @@ -106,7 +106,7 @@ Partial.ItemSet = function ItemSet(wardrobe, selector) { setClosetItems(wardrobe.outfit.getClosetItems()); setOutfitItems(wardrobe.outfit.getWornItems()); } - + $('span.no-assets-message').live('mouseover', function () { var el = $(this), o = el.offset(); no_assets_full_message.css({ @@ -116,7 +116,7 @@ Partial.ItemSet = function ItemSet(wardrobe, selector) { }).live('mouseout', function () { no_assets_full_message.removeAttr('style'); }); - + wardrobe.outfit.bind('updateItemAssets', function () { setHasAssets(wardrobe.outfit.getWornItems()) }); wardrobe.outfit.bind('updateWornItems', setOutfitItems); wardrobe.outfit.bind('updateClosetItems', setClosetItems); @@ -139,7 +139,7 @@ Partial.ItemSet.setWardrobe = function (wardrobe) { href: '#', text: verb_set[toggle ? 0 : 1] }).wrap('
  • ').parent().attr('class', full_class); - + (function (type, toggle) { $('li.' + live_class + ' a').live('click', function (e) { var el = $(this), item = el.closest('.object').data('item'); @@ -149,7 +149,7 @@ Partial.ItemSet.setWardrobe = function (wardrobe) { })(type, toggle); } } - + toggle_fn.closeted = {}; toggle_fn.closeted[true] = $.proxy(wardrobe.outfit, 'closetItem'); toggle_fn.closeted[false] = $.proxy(wardrobe.outfit, 'unclosetItem'); @@ -157,13 +157,13 @@ Partial.ItemSet.setWardrobe = function (wardrobe) { toggle_fn.worn = {}; toggle_fn.worn[true] = $.proxy(wardrobe.outfit, 'wearItem'); toggle_fn.worn[false] = $.proxy(wardrobe.outfit, 'unwearItem'); - + Partial.ItemSet.setWardrobe = $.noop; } View.Closet = function (wardrobe) { var item_set = new Partial.ItemSet(wardrobe, '#preview-closet ul'); - + wardrobe.outfit.bind('updateClosetItems', $.proxy(item_set, 'setItems')); } @@ -172,7 +172,7 @@ View.Fullscreen = function (wardrobe) { preview_el = $('#preview'), search_el = $('#preview-search-form'), preview_swf = $('#preview-swf'), sidebar_el = $('#preview-sidebar'), footer = $('#footer'), jwindow = $(window), overrideFull = false; - + function fit() { if(!overrideFull) { var newFull = jwindow.height() > 500; @@ -185,7 +185,7 @@ View.Fullscreen = function (wardrobe) { } } } - + if(full) { preview_swf = $('#preview-swf'); // swf replaced var available = { @@ -211,19 +211,19 @@ View.Fullscreen = function (wardrobe) { size.next[margin.active] = (available[dim.larger] - size.next[dim.larger]) / 2; size.next[margin.inactive] = 0; preview_swf.css(size.next); - + preview_el.height(available.height); } } $('#preview').data('fit', fit); - + win.resize(fit).load(fit); // run fit after search updates select fields function fitSoon() { setTimeout(fit, 0) } wardrobe.item_zone_sets.bind('update', fitSoon); wardrobe.pet_attributes.bind('update', fitSoon); fit(); - + var Konami=function(){var a={addEvent:function(b,c,d,e){if(b.addEventListener)b.addEventListener(c,d,false);else if(b.attachEvent){b["e"+c+d]=d;b[c+d]=function(){b["e"+c+d](window.event,e)};b.attachEvent("on"+c,b[c+d])}},input:"",pattern:"3838404037393739666513",load:function(b){this.addEvent(document,"keydown",function(c,d){if(d)a=d;a.input+=c?c.keyCode:event.keyCode;if(a.input.indexOf(a.pattern)!=-1){a.code(b);a.input=""}},this);this.iphone.load(b)},code:function(b){window.location=b},iphone:{start_x:0,start_y:0,stop_x:0,stop_y:0,tap:false,capture:false,keys:["UP","UP","DOWN","DOWN","LEFT","RIGHT","LEFT","RIGHT","TAP","TAP","TAP"],code:function(b){a.code(b)},load:function(b){a.addEvent(document,"touchmove",function(c){if(c.touches.length==1&&a.iphone.capture==true){c=c.touches[0];a.iphone.stop_x=c.pageX;a.iphone.stop_y=c.pageY;a.iphone.tap=false;a.iphone.capture=false;a.iphone.check_direction()}});a.addEvent(document,"touchend",function(){a.iphone.tap==true&&a.iphone.check_direction(b)},false);a.addEvent(document,"touchstart",function(c){a.iphone.start_x=c.changedTouches[0].pageX;a.iphone.start_y=c.changedTouches[0].pageY;a.iphone.tap=true;a.iphone.capture=true})},check_direction:function(b){x_magnitude=Math.abs(this.start_x-this.stop_x);y_magnitude=Math.abs(this.start_y-this.stop_y);x=this.start_x-this.stop_x<0?"RIGHT":"LEFT";y=this.start_y-this.stop_y<0?"DOWN":"UP";result=x_magnitude>y_magnitude?x:y;result=this.tap==true?"TAP":result;if(result==this.keys[0])this.keys=this.keys.slice(1,this.keys.length);this.keys.length==0&&this.code(b)}}};return a}; konami = new Konami(); konami.code = function () { @@ -253,7 +253,7 @@ View.Hash = function (wardrobe) { species: TYPES.INTEGER, state: TYPES.INTEGER }, links_with_return_to = $('a[href*=return_to]'); - + function checkQuery() { var query = (document.location.hash || document.location.search).substr(1); if(query != previous_query) { @@ -261,7 +261,7 @@ View.Hash = function (wardrobe) { previous_query = query; } } - + function parseQuery(query) { var new_data = {}, pairs = query.split('&'); parse_in_progress = true; @@ -283,7 +283,7 @@ View.Hash = function (wardrobe) { } } } - + if(new_data.color !== data.color || new_data.species !== data.species) { wardrobe.outfit.setPetTypeByColorAndSpecies(new_data.color, new_data.species); } @@ -319,7 +319,7 @@ View.Hash = function (wardrobe) { parse_in_progress = false; updateLinksWithReturnTo(); } - + function changeQuery(changes) { var value; if(!parse_in_progress) { @@ -336,7 +336,7 @@ View.Hash = function (wardrobe) { updateQuery(); } } - + function updateQuery() { var new_query; new_query = $.param(data).replace(/%5B%5D/g, '[]'); @@ -344,7 +344,7 @@ View.Hash = function (wardrobe) { document.location.hash = '#' + new_query; updateLinksWithReturnTo(); } - + function updateLinksWithReturnTo() { links_with_return_to.each(function () { var new_return_to = 'return_to=' + encodeURIComponent( @@ -355,25 +355,25 @@ View.Hash = function (wardrobe) { this.href = this.href.replace(/return_to=[^&]+/, new_return_to); }); } - + this.initialize = function () { checkQuery(); setInterval(checkQuery, 100); } - + function singleOutfitResponse(event_name, response) { wardrobe.outfit.bind(event_name, function () { if(!wardrobe.outfit.in_transaction) response.apply(this, arguments); }); } - + singleOutfitResponse('updateClosetItems', function (items) { var item_ids = items.map('id'); if(!arraysMatch(item_ids, data.closet)) { changeQuery({closet: item_ids}); } }); - + singleOutfitResponse('updateWornItems', function (items) { var item_ids = items.map('id'), changes = {}; if(!arraysMatch(item_ids, data.objects)) { @@ -386,7 +386,7 @@ View.Hash = function (wardrobe) { } if(changes.objects || changes.closet) changeQuery(changes); }); - + singleOutfitResponse('updatePetType', function (pet_type) { if(pet_type.color_id != data.color || pet_type.species_id != data.species) { changeQuery({ @@ -396,24 +396,24 @@ View.Hash = function (wardrobe) { }); } }); - + singleOutfitResponse('petTypeNotFound', function () { window.history.back(); }); - + singleOutfitResponse('updatePetState', function (pet_state) { var pet_type = wardrobe.outfit.getPetType(); if(pet_state.id != data.state && pet_type && (data.state || pet_state.id != pet_type.pet_state_ids[0])) { changeQuery({state: pet_state.id}); } }); - + singleOutfitResponse('setOutfit', function (outfit) { if(outfit.id != data.outfit) { changeQuery({outfit: outfit.id}); } }); - + wardrobe.outfit.bind('loadOutfit', function (outfit) { changeQuery({ closet: outfit.getClosetItemIds(), @@ -424,12 +424,12 @@ View.Hash = function (wardrobe) { state: outfit.pet_state.id }); }); - + wardrobe.outfit.bind('outfitNotFound', function (outfit) { var new_id = outfit ? outfit.id : undefined; changeQuery({outfit: new_id}); }); - + wardrobe.search.bind('updateRequest', function (request) { if(request.offset != data.search_offset || request.query != data.search) { changeQuery({ @@ -442,7 +442,8 @@ View.Hash = function (wardrobe) { View.Outfits = function (wardrobe) { var current_outfit_permalink_el = $('#current-outfit-permalink'), - current_outfit_url_el = $('#current-outfit-url'), + shared_outfit_permalink_el = $('#shared-outfit-permalink'), + shared_outfit_url_el = $('#shared-outfit-url'), new_outfit_form_el = $('#save-outfit-form'), new_outfit_name_el = $('#save-outfit-name'), outfits_el = $('#preview-outfits'), @@ -457,77 +458,77 @@ View.Outfits = function (wardrobe) { sidebar_el = $('#preview-sidebar'), signed_in, previously_viewing = ''; - + function liForOutfit(outfit) { return $('li.outfit-' + outfit.id); } - + function navLinkTo(callback) { return function (e) { e.preventDefault(); callback(); } } - + function navigateTo(will_be_viewing) { var currently_viewing = sidebar_el.attr('class'); if(currently_viewing != will_be_viewing) previously_viewing = currently_viewing; sidebar_el.attr('class', will_be_viewing); } - + /* Show for login */ - + signed_in = $('meta[name=user-signed-in]').attr('content') == 'true'; if(signed_in) { $(document.body).addClass('user-signed-in'); } else { $(document.body).addClass('user-not-signed-in'); } - + /* Nav */ - + function showCloset() { navigateTo(''); } - + function showOutfits() { wardrobe.user.loadOutfits(); navigateTo('viewing-outfits'); } - + function showNewOutfitForm() { new_outfit_name_el.val(''); new_outfit_form_el.removeClass('starred').stopLoading(); save_outfit_wrapper_el.addClass('saving-outfit'); new_outfit_name_el.focus(); } - + function hideNewOutfitForm() { save_outfit_wrapper_el.removeClass('saving-outfit'); } - + $('#preview-sidebar-nav-outfits').click(navLinkTo(showOutfits)); - + $('#preview-sidebar-nav-closet').click(navLinkTo(showCloset)); - + $('#save-outfit, #save-outfit-copy').click(showNewOutfitForm); - + $('#save-outfit-cancel').click(hideNewOutfitForm); - + $('#save-outfit-not-signed-in').click(function () { window.location.replace($('#userbar a').attr('href')); }); - + /* Outfits list */ - + $('#outfit-template').template('outfitTemplate'); - + wardrobe.user.bind('outfitsLoaded', function (outfits) { var outfit_els = $.tmpl('outfitTemplate', outfits); outfits_list_el.html('').append(outfit_els).addClass('loaded'); updateActiveOutfit(); }); - + wardrobe.user.bind('addOutfit', function (outfit, i) { var next_child = outfits_list_el.children().not('.hiding').eq(i), outfit_el = $.tmpl('outfitTemplate', outfit); @@ -539,23 +540,23 @@ View.Outfits = function (wardrobe) { updateActiveOutfit(); outfit_el.hide().show('normal'); }); - + wardrobe.user.bind('removeOutfit', function (outfit, i) { var outfit_el = outfits_list_el.children().not('.hiding').eq(i); outfit_el.addClass('hiding').stop(true).hide('normal', function () { outfit_el.remove() }); }); - + $('#preview-outfits h4').live('click', function () { wardrobe.outfit.load($(this).tmplItem().data.id); }); - + $('a.outfit-rename-button').live('click', function (e) { e.preventDefault(); var li = $(this).closest('li').addClass('renaming'), name = li.find('h4').text(); li.find('input.outfit-rename-field').val(name).focus(); }); - + function submitRename() { var el = $(this), outfit = el.tmplItem().data, new_name = el.val(), li = el.closest('li').removeClass('renaming'); @@ -564,26 +565,26 @@ View.Outfits = function (wardrobe) { wardrobe.user.renameOutfit(outfit, new_name); } } - + $('input.outfit-rename-field').live('blur', submitRename); - + $('form.outfit-rename-form').live('submit', function (e) { e.preventDefault(); var input = $(this).find('input'); submitRename.apply(input); }); - + $('input.outfit-url').live('mouseover', function () { this.focus(); }).live('mouseout', function () { this.blur(); }); - + $('button.outfit-delete').live('click', function (e) { e.preventDefault(); $(this).closest('li').addClass('confirming-deletion'); }); - + $('a.outfit-delete-confirmation-yes').live('click', function (e) { var outfit = $(this).tmplItem().data; e.preventDefault(); @@ -592,108 +593,116 @@ View.Outfits = function (wardrobe) { wardrobe.outfit.setId(null); } }); - + $('a.outfit-delete-confirmation-no').live('click', function (e) { e.preventDefault(); $(this).closest('li').removeClass('confirming-deletion'); }); - + stars.live('click', function () { var el = $(this); el.closest('li').startLoading(); wardrobe.user.toggleOutfitStar(el.tmplItem().data); }); - - function setOutfitPermalink(outfit) { + + function setOutfitPermalink(outfit, outfit_permalink_el, outfit_url_el) { var url = document.location.protocol + "//" + document.location.host; if(document.location.port) url += ":" + document.location.port; url += "/outfits/" + outfit.id; - current_outfit_permalink_el.attr('href', url); - current_outfit_url_el.val(url); + outfit_permalink_el.attr('href', url); + if(outfit_url_el) outfit_url_el.val(url); } - + + function setCurrentOutfitPermalink(outfit) { + setOutfitPermalink(outfit, current_outfit_permalink_el); + } + + function setSharedOutfitPermalink(outfit) { + setOutfitPermalink(outfit, shared_outfit_permalink_el, shared_outfit_url_el); + } + function setActiveOutfit(outfit) { outfits_list_el.find('li.active').removeClass('active'); if(outfit.id) { - setOutfitPermalink(outfit); + setCurrentOutfitPermalink(outfit); liForOutfit(outfit).addClass('active'); save_current_outfit_name_el.text(outfit.name); } save_outfit_wrapper_el.toggleClass('active-outfit', outfit.id ? true : false); } - + function updateActiveOutfit() { setActiveOutfit(wardrobe.outfit.getOutfit()); } - + wardrobe.outfit.bind('setOutfit', setActiveOutfit); wardrobe.outfit.bind('outfitNotFound', setActiveOutfit); - + wardrobe.user.bind('outfitRenamed', function (outfit) { if(outfit.id == wardrobe.outfit.getId()) { save_current_outfit_name_el.text(outfit.name); } }); - + /* Saving */ - + save_current_outfit_el.click(function () { wardrobe.outfit.update(); }); - + new_outfit_form_el.submit(function (e) { e.preventDefault(); new_outfit_form_el.startLoading(); wardrobe.outfit.create({starred: new_outfit_form_el.hasClass('starred'), name: new_outfit_name_el.val()}); }); - + $('#share-outfit').click(function () { save_outfit_wrapper_el.startLoading(); wardrobe.outfit.share(); }); - + new_outfit_form_el.find('div.outfit-star').click(function () { new_outfit_form_el.toggleClass('starred'); }); - + var SAVE_ERRORS = { 'item_outfit_relationships': "Item not found. How odd. Pull some items out of your closet and try again.", 'pet_state': "Pet state not found. How odd. Try picking a new Gender/Emotion.", 'name': true, 'user': "You must be logged in to save outfits" }; - + function saveErrorMessage(text) { save_error_el.text(text).notify(); } - + wardrobe.outfit.bind('saveSuccess', function (outfit) { save_success_el.notify(); }); - + wardrobe.outfit.bind('createSuccess', function (outfit) { wardrobe.user.addOutfit(outfit); showOutfits(); hideNewOutfitForm(); }); - + wardrobe.outfit.bind('updateSuccess', function (outfit) { wardrobe.user.updateOutfit(outfit); }); - + wardrobe.outfit.bind('shareSuccess', function (outfit) { save_outfit_wrapper_el.stopLoading().addClass('shared-outfit'); - setOutfitPermalink(outfit); + setSharedOutfitPermalink(outfit); }); - + function clearSharedOutfit() { save_outfit_wrapper_el.removeClass('shared-outfit'); } - + wardrobe.outfit.bind('updateClosetItems', clearSharedOutfit); wardrobe.outfit.bind('updateWornItems', clearSharedOutfit); wardrobe.outfit.bind('updatePetState', clearSharedOutfit); - + function saveFailure(outfit, response) { var errors = response.errors; if(typeof errors == 'undefined') { @@ -714,16 +723,16 @@ View.Outfits = function (wardrobe) { new_outfit_form_el.stopLoading(); liForOutfit(outfit).stopLoading(); } - + wardrobe.outfit.bind('saveFailure', saveFailure); wardrobe.user.bind('saveFailure', saveFailure) wardrobe.outfit.bind('shareFailure', function (outfit, response) { save_outfit_wrapper_el.stopLoading(); saveFailure(outfit, response); }); - + /* Error */ - + wardrobe.outfit.bind('outfitNotFound', function () { outfit_not_found_el.notify(); }); @@ -738,14 +747,14 @@ View.PetStateForm = function (wardrobe) { e.preventDefault(); wardrobe.outfit.setPetStateById(+$(this).data('value')); }); - + function updatePetState(pet_state) { if(pet_state) { ul.children('li.selected').removeClass('selected'); $(button_query + '[data-value=' + pet_state.id + ']').parent().addClass('selected'); } } - + wardrobe.outfit.bind('petTypeLoaded', function (pet_type) { var ids = pet_type.pet_state_ids, i, id, li, button, label; ul.children().remove(); @@ -767,7 +776,7 @@ View.PetStateForm = function (wardrobe) { updatePetState(wardrobe.outfit.getPetState()); } }); - + wardrobe.outfit.bind('updatePetState', updatePetState); } @@ -781,11 +790,11 @@ View.PetTypeForm = function (wardrobe) { }).children('select').each(function () { dropdowns[this.name] = $(this); }); - + this.initialize = function () { wardrobe.pet_attributes.load(); } - + function updatePetType(pet_type) { if(loaded && pet_type) { $.each(dropdowns, function (name) { @@ -793,7 +802,7 @@ View.PetTypeForm = function (wardrobe) { }); } } - + wardrobe.pet_attributes.bind('update', function (attributes) { $.each(attributes, function (type) { var dropdown = dropdowns[type]; @@ -808,9 +817,9 @@ View.PetTypeForm = function (wardrobe) { loaded = true; updatePetType(wardrobe.outfit.getPetType()); }); - + wardrobe.outfit.bind('updatePetType', updatePetType); - + wardrobe.outfit.bind('petTypeNotFound', function () { $('#pet-type-not-found').show('normal').delay(3000).hide('fast'); }); @@ -837,21 +846,21 @@ View.Search = function (wardrobe) { EL_ID: '#preview-search-form-pagination', PER_PAGE: 21 }, object_width = 112, last_request; - + PAGINATION.EL = $(PAGINATION.EL_ID); PAGINATION.GAP_EL = $('', {'class': 'gap', html: PAGINATION.GAP_TEXT}) PAGINATION.PREV_EL = $('', {href: '#', rel: 'prev', html: PAGINATION.PREV_TEXT}); PAGINATION.NEXT_EL = $('', {href: '#', rel: 'next', html: PAGINATION.NEXT_TEXT}); - + $(PAGINATION.EL_ID + ' a').live('click', function (e) { e.preventDefault(); loadPage($(this).data('page')); }); - + this.initialize = $.proxy(wardrobe.item_zone_sets, 'load'); - + wardrobe.search.setPerPage(PAGINATION.PER_PAGE); - + function updatePerPage() { var new_per_page = Math.floor(form.width() / object_width), offset, new_page; @@ -866,34 +875,34 @@ View.Search = function (wardrobe) { } $(window).resize(updatePerPage).load(updatePerPage); updatePerPage(); - + function loadOffset(offset) { wardrobe.search.setItemsByQuery(input_el.val(), {offset: offset}); } - + function loadPage(page) { wardrobe.search.setItemsByQuery(input_el.val(), {page: page}); } - + function stopLoading() { loading_el.stop(true, true).hide(); } - + form.submit(function (e) { e.preventDefault(); loadPage(1); }); - + clear_el.click(function (e) { e.preventDefault(); input_el.val(''); form.submit(); }); - + wardrobe.search.bind('startRequest', function () { loading_el.delay(1000).show('slow'); }); - + wardrobe.search.bind('updateItems', function (items) { var fit = $('#preview').data('fit') || $.noop; stopLoading(); @@ -908,7 +917,7 @@ View.Search = function (wardrobe) { form.toggleClass('has-results', items.length > 0); fit(); }); - + wardrobe.search.bind('updateRequest', function (request) { last_request = request; error_el.hide('fast'); @@ -918,37 +927,37 @@ View.Search = function (wardrobe) { no_results_span.text(request.query); clear_el.toggle(!!request.query); }); - + wardrobe.search.bind('updatePagination', function (current_page, total_pages) { // ported from http://github.com/mislav/will_paginate/blob/master/lib/will_paginate/view_helpers.rb#L274 var window_from = current_page - PAGINATION.INNER_WINDOW, window_to = current_page + PAGINATION.INNER_WINDOW, visible = [], left_gap, right_gap, subtract_left, subtract_right, i = 1; - + if(window_to > total_pages) { window_from -= window_to - total_pages; window_to = total_pages; } - + if(window_from < 1) { window_to += 1 - window_from; window_from = 1; if(window_to > total_pages) window_to = total_pages; } - + left_gap = [2 + PAGINATION.OUTER_WINDOW, window_from]; right_gap = [window_to + 1, total_pages - PAGINATION.OUTER_WINDOW]; - + subtract_left = (left_gap[1] - left_gap[0]) > 1; subtract_right = (right_gap[1] - right_gap[0]) > 1; - + PAGINATION.EL.children().remove(); - + if(current_page > 1) { PAGINATION.PREV_EL.clone().data('page', current_page - 1).appendTo(PAGINATION.EL); } - + while(i <= total_pages) { if(subtract_left && i >= left_gap[0] && i < left_gap[1]) { PAGINATION.GAP_EL.clone().appendTo(PAGINATION.EL); @@ -965,17 +974,17 @@ View.Search = function (wardrobe) { i++; } } - + if(current_page < total_pages) { PAGINATION.NEXT_EL.clone().data('page', current_page + 1).appendTo(PAGINATION.EL); } }); - + wardrobe.search.bind('error', function (error) { stopLoading(); error_el.text(error).show('normal'); }); - + help_el.find('dt').each(function () { var el = $(this); if(!el.children().length) { @@ -985,7 +994,7 @@ View.Search = function (wardrobe) { var el = $(this); el.replaceWith($('', {href: '#', text: el.text()})); }); - + help_el.find('dt a').live('click', function (e) { var el = $(this), siblings = el.parent().children(), query; e.preventDefault(); @@ -1000,12 +1009,12 @@ View.Search = function (wardrobe) { input_el.val(query); form.submit(); }); - + $('select.search-helper').live('change', function () { var el = $(this), filter = el.attr('data-search-filter'); $('select.search-helper[data-search-filter=' + filter + ']').val(el.val()); }); - + function prepBuildHelper(type, getSet) { return function (objs) { var select = $('