2010-11-10 13:59:54 -08:00
|
|
|
$.fn.notify = function () {
|
2011-02-10 14:50:47 -08:00
|
|
|
return this.stop(true, true).show('slow').delay(5000).hide('fast');
|
2010-11-24 17:51:01 -08:00
|
|
|
}
|
|
|
|
|
2011-02-10 14:50:47 -08:00
|
|
|
$.fn.startLoading = function () {
|
|
|
|
return this.delay(1000).queue(function (next) {
|
2010-11-24 17:51:01 -08:00
|
|
|
$(this).addClass('loading');
|
|
|
|
next();
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
$.fn.stopLoading = function () {
|
2011-02-10 14:50:47 -08:00
|
|
|
return this.removeClass('loading').clearQueue();
|
2010-11-10 13:59:54 -08:00
|
|
|
}
|
2010-11-08 17:40:03 -08:00
|
|
|
|
2010-10-10 19:18:42 -07:00
|
|
|
var Partial = {}, main_wardrobe,
|
|
|
|
View = Wardrobe.getStandardView({
|
|
|
|
Preview: {
|
|
|
|
swf_url: '/swfs/preview.swf?v=0.12',
|
2011-05-22 13:30:02 -07:00
|
|
|
wrapper: $('#preview-swf'),
|
|
|
|
placeholder: $('#preview-swf-container'),
|
|
|
|
image_container: '#preview-image-container'
|
2010-10-10 19:18:42 -07:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
Partial.ItemSet = function ItemSet(wardrobe, selector) {
|
|
|
|
var item_set = this, ul = $(selector), items = [], setClosetItems,
|
|
|
|
setOutfitItems, setOutfitItemsControls, no_assets_full_message = $('#no-assets-full-message'),
|
2013-01-07 16:55:36 -08:00
|
|
|
container = $('#container'), item_template = $('#item-template');
|
2011-03-28 14:29:03 -07:00
|
|
|
|
2010-10-10 19:18:42 -07:00
|
|
|
Partial.ItemSet.setWardrobe(wardrobe);
|
2011-03-28 14:29:03 -07:00
|
|
|
|
2010-10-10 19:18:42 -07:00
|
|
|
function prepSetSpecificItems(type) {
|
|
|
|
return function (specific_items) {
|
|
|
|
var item, worn, li;
|
|
|
|
for(var i = 0; i < items.length; i++) {
|
|
|
|
item = items[i];
|
|
|
|
in_set = $.inArray(item, specific_items) != -1;
|
|
|
|
li = $('li.object-' + item.id).toggleClass(type, in_set).
|
2013-01-26 09:58:16 -08:00
|
|
|
data('item', item).data(type, in_set);
|
2010-10-10 19:18:42 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2011-03-28 14:29:03 -07:00
|
|
|
|
2010-10-10 19:18:42 -07:00
|
|
|
setClosetItems = prepSetSpecificItems('closeted');
|
2011-03-28 14:29:03 -07:00
|
|
|
|
2010-10-10 19:18:42 -07:00
|
|
|
setOutfitItemsControls = prepSetSpecificItems('worn');
|
|
|
|
setOutfitItems = function (specific_items) {
|
|
|
|
setOutfitItemsControls(specific_items);
|
|
|
|
setHasAssets(specific_items);
|
|
|
|
}
|
2011-03-28 14:29:03 -07:00
|
|
|
|
2010-10-10 19:18:42 -07:00
|
|
|
function setHasAssets(specific_items) {
|
|
|
|
var item, no_assets, li, no_assets_message;
|
|
|
|
for(var i = 0, l = specific_items.length; i < l; i++) {
|
|
|
|
item = specific_items[i];
|
2012-07-26 20:47:22 -07:00
|
|
|
no_assets = item.couldNotLoadAssetsFitting(wardrobe.outfits.getPetType());
|
2010-10-10 19:18:42 -07:00
|
|
|
li = $('li.object-' + item.id).toggleClass('no-assets', no_assets);
|
|
|
|
}
|
|
|
|
}
|
2011-03-28 14:29:03 -07:00
|
|
|
|
2010-10-10 19:18:42 -07:00
|
|
|
this.setItems = function (new_items) {
|
|
|
|
var item, li, controls, info_link;
|
|
|
|
items = new_items;
|
|
|
|
ul.children().remove();
|
|
|
|
for(var i = 0; i < items.length; i++) {
|
|
|
|
item = items[i];
|
2013-01-07 16:55:36 -08:00
|
|
|
li = item_template.tmpl({
|
|
|
|
id: item.id,
|
|
|
|
name: item.name,
|
2013-02-17 08:43:09 -08:00
|
|
|
description: item.description,
|
2013-01-07 16:55:36 -08:00
|
|
|
thumbnail_url: item.thumbnail_url,
|
|
|
|
url: item.getURL(),
|
|
|
|
nc: typeof item.rarity_index != 'undefined' &&
|
|
|
|
(item.rarity_index == 500 || item.rarity_index == 0),
|
|
|
|
owned: item.owned,
|
|
|
|
wanted: item.wanted
|
2010-10-10 19:18:42 -07:00
|
|
|
});
|
2013-01-07 16:55:36 -08:00
|
|
|
li.appendTo(ul);
|
2010-10-10 19:18:42 -07:00
|
|
|
}
|
2012-07-26 20:47:22 -07:00
|
|
|
setClosetItems(wardrobe.outfits.getClosetItems());
|
|
|
|
setOutfitItems(wardrobe.outfits.getWornItems());
|
2010-10-10 19:18:42 -07:00
|
|
|
}
|
2011-03-28 14:29:03 -07:00
|
|
|
|
2010-10-10 19:18:42 -07:00
|
|
|
$('span.no-assets-message').live('mouseover', function () {
|
|
|
|
var el = $(this), o = el.offset();
|
|
|
|
no_assets_full_message.css({
|
|
|
|
left: o.left + (el.width() / 2) - (no_assets_full_message.width() / 2) - container.offset().left,
|
|
|
|
top: o.top + el.height() + 10
|
|
|
|
});
|
|
|
|
}).live('mouseout', function () {
|
|
|
|
no_assets_full_message.removeAttr('style');
|
|
|
|
});
|
2011-03-28 14:29:03 -07:00
|
|
|
|
2012-07-26 20:47:22 -07:00
|
|
|
wardrobe.outfits.bind('updateItemAssets', function () { setHasAssets(wardrobe.outfits.getWornItems()) });
|
|
|
|
wardrobe.outfits.bind('updateWornItems', setOutfitItems);
|
|
|
|
wardrobe.outfits.bind('updateClosetItems', setClosetItems);
|
2010-10-10 19:18:42 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
Partial.ItemSet.CONTROL_SETS = {};
|
|
|
|
|
|
|
|
Partial.ItemSet.setWardrobe = function (wardrobe) {
|
2013-01-26 09:58:16 -08:00
|
|
|
var type, toggle, toggle_fn = {}, toggle_classes = {worn: {}, closeted: {}};
|
|
|
|
|
|
|
|
toggle_classes.worn['false'] = 'wear-item';
|
|
|
|
toggle_classes.worn['true'] = 'unwear-item';
|
|
|
|
toggle_classes.closeted['false'] = 'closet-item';
|
|
|
|
toggle_classes.closeted['true'] = 'uncloset-item';
|
|
|
|
|
|
|
|
for(type in toggle_classes) {
|
|
|
|
for(toggleKey in toggle_classes[type]) {
|
|
|
|
var toggle = (toggleKey == 'true');
|
2010-10-10 19:18:42 -07:00
|
|
|
(function (type, toggle) {
|
2013-01-26 09:58:16 -08:00
|
|
|
$('li.' + toggle_classes[type][toggle] + ' a').live('click', function (e) {
|
2010-10-10 19:18:42 -07:00
|
|
|
e.preventDefault();
|
2013-01-26 09:58:16 -08:00
|
|
|
var item = $(this).closest('.object').data('item');
|
|
|
|
log(this, item, type, toggle, !toggle);
|
|
|
|
toggle_fn[type][!toggle](item);
|
2010-10-10 19:18:42 -07:00
|
|
|
});
|
|
|
|
})(type, toggle);
|
|
|
|
}
|
|
|
|
}
|
2011-03-28 14:29:03 -07:00
|
|
|
|
2010-10-10 19:18:42 -07:00
|
|
|
toggle_fn.closeted = {};
|
2012-07-26 20:47:22 -07:00
|
|
|
toggle_fn.closeted[true] = $.proxy(wardrobe.outfits, 'closetItem');
|
|
|
|
toggle_fn.closeted[false] = $.proxy(wardrobe.outfits, 'unclosetItem');
|
2010-10-10 19:18:42 -07:00
|
|
|
|
|
|
|
toggle_fn.worn = {};
|
2012-07-26 20:47:22 -07:00
|
|
|
toggle_fn.worn[true] = $.proxy(wardrobe.outfits, 'wearItem');
|
|
|
|
toggle_fn.worn[false] = $.proxy(wardrobe.outfits, 'unwearItem');
|
2011-03-28 14:29:03 -07:00
|
|
|
|
2010-10-10 19:18:42 -07:00
|
|
|
Partial.ItemSet.setWardrobe = $.noop;
|
|
|
|
}
|
|
|
|
|
|
|
|
View.Closet = function (wardrobe) {
|
|
|
|
var item_set = new Partial.ItemSet(wardrobe, '#preview-closet ul');
|
2011-03-28 14:29:03 -07:00
|
|
|
|
2012-07-26 20:47:22 -07:00
|
|
|
wardrobe.outfits.bind('updateClosetItems', $.proxy(item_set, 'setItems'));
|
2010-10-10 19:18:42 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
View.Fullscreen = function (wardrobe) {
|
|
|
|
var full = $(document.body).hasClass('fullscreen'), win = $(window),
|
2014-04-02 11:54:27 -07:00
|
|
|
preview_el = $('#preview'), search_el = $('#preview-search'),
|
2010-11-08 17:40:03 -08:00
|
|
|
preview_swf = $('#preview-swf'), sidebar_el = $('#preview-sidebar'),
|
2012-07-25 16:02:23 -07:00
|
|
|
sidebar_content_el = $('#preview-sidebar-content'),
|
|
|
|
sidebar_navbar_el = $('#preview-sidebar-navbar'), footer = $('#footer'),
|
|
|
|
jwindow = $(window), overrideFull = false;
|
2011-03-28 14:29:03 -07:00
|
|
|
|
2010-10-10 19:18:42 -07:00
|
|
|
function fit() {
|
2011-02-06 15:55:04 -08:00
|
|
|
if(!overrideFull) {
|
|
|
|
var newFull = jwindow.height() > 500;
|
|
|
|
if(newFull != full) {
|
|
|
|
full = newFull;
|
|
|
|
$(document.body).toggleClass('fullscreen', full);
|
|
|
|
if(!full) {
|
|
|
|
preview_swf.removeAttr('style').css('visibility', 'visible');
|
|
|
|
preview_el.removeAttr('style');
|
2012-07-27 00:31:30 -07:00
|
|
|
sidebar_content_el.removeAttr('style');
|
2011-02-06 15:55:04 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2011-03-28 14:29:03 -07:00
|
|
|
|
2010-10-10 19:18:42 -07:00
|
|
|
if(full) {
|
|
|
|
preview_swf = $('#preview-swf'); // swf replaced
|
|
|
|
var available = {
|
|
|
|
height: search_el.offset().top - preview_el.offset().top,
|
2010-11-08 17:40:03 -08:00
|
|
|
width: preview_el.innerWidth() - sidebar_el.outerWidth() - 12 // 12px margin
|
2010-10-10 19:18:42 -07:00
|
|
|
}, dim = {}, margin = {}, size = {
|
|
|
|
old: {height: preview_swf.height(), width: preview_swf.width()},
|
|
|
|
next: {}
|
|
|
|
}, offset;
|
|
|
|
if(available.height > available.width) {
|
|
|
|
dim.larger = 'height';
|
|
|
|
dim.smaller = 'width';
|
|
|
|
margin.active = 'marginTop';
|
|
|
|
margin.inactive = 'marginLeft';
|
|
|
|
} else {
|
|
|
|
dim.larger = 'width';
|
|
|
|
dim.smaller = 'height';
|
|
|
|
margin.active = 'marginLeft';
|
|
|
|
margin.inactive = 'marginTop';
|
|
|
|
}
|
|
|
|
size.next[dim.smaller] = available[dim.smaller];
|
|
|
|
size.next[dim.larger] = available[dim.smaller];
|
|
|
|
size.next[margin.active] = (available[dim.larger] - size.next[dim.larger]) / 2;
|
|
|
|
size.next[margin.inactive] = 0;
|
|
|
|
preview_swf.css(size.next);
|
2011-03-28 14:29:03 -07:00
|
|
|
|
2010-10-10 19:18:42 -07:00
|
|
|
preview_el.height(available.height);
|
2014-04-02 09:11:18 -07:00
|
|
|
|
|
|
|
// If the footer goes onto two lines, nudge search up.
|
|
|
|
search_el.css('bottom', $('#footer').height());
|
|
|
|
|
2012-07-25 16:02:23 -07:00
|
|
|
// Now that preview is fit, we fit the sidebar's content element, which
|
|
|
|
// also has to deal with the constraint of its navbar's height.
|
|
|
|
var sidebar_content_height = available.height -
|
|
|
|
sidebar_navbar_el.outerHeight() - 1; // 1px bottom border
|
|
|
|
sidebar_content_el.height(sidebar_content_height);
|
2010-10-10 19:18:42 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
$('#preview').data('fit', fit);
|
2011-03-28 14:29:03 -07:00
|
|
|
|
2010-10-10 19:18:42 -07:00
|
|
|
win.resize(fit).load(fit);
|
2010-11-16 05:50:01 -08:00
|
|
|
// 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);
|
2010-10-10 19:18:42 -07:00
|
|
|
fit();
|
|
|
|
}
|
|
|
|
|
|
|
|
View.Hash = function (wardrobe) {
|
|
|
|
var data = {}, proposed_data = {}, previous_query, parse_in_progress = false, TYPES = {
|
|
|
|
INTEGER: 1,
|
|
|
|
STRING: 2,
|
|
|
|
INTEGER_ARRAY: 3
|
|
|
|
}, KEYS = {
|
2014-02-19 13:58:39 -08:00
|
|
|
biology: TYPES.INTEGER_ARRAY,
|
2010-10-10 19:18:42 -07:00
|
|
|
closet: TYPES.INTEGER_ARRAY,
|
|
|
|
color: TYPES.INTEGER,
|
|
|
|
name: TYPES.STRING,
|
|
|
|
objects: TYPES.INTEGER_ARRAY,
|
2010-11-12 17:58:28 -08:00
|
|
|
outfit: TYPES.INTEGER,
|
2010-10-10 19:18:42 -07:00
|
|
|
search: TYPES.STRING,
|
|
|
|
search_offset: TYPES.INTEGER,
|
|
|
|
species: TYPES.INTEGER,
|
|
|
|
state: TYPES.INTEGER
|
2010-11-10 13:59:54 -08:00
|
|
|
}, links_with_return_to = $('a[href*=return_to]');
|
2011-03-28 14:29:03 -07:00
|
|
|
|
2010-10-10 19:18:42 -07:00
|
|
|
function checkQuery() {
|
|
|
|
var query = (document.location.hash || document.location.search).substr(1);
|
|
|
|
if(query != previous_query) {
|
|
|
|
parseQuery(query);
|
|
|
|
previous_query = query;
|
|
|
|
}
|
|
|
|
}
|
2011-03-28 14:29:03 -07:00
|
|
|
|
2010-10-10 19:18:42 -07:00
|
|
|
function parseQuery(query) {
|
|
|
|
var new_data = {}, pairs = query.split('&');
|
|
|
|
parse_in_progress = true;
|
|
|
|
for(var i = 0; i < pairs.length; i++) {
|
|
|
|
var pair = pairs[i].split('='),
|
|
|
|
key = decodeURIComponent(pair[0]),
|
|
|
|
value = decodeURIComponent(pair[1]);
|
|
|
|
if(value) {
|
|
|
|
if(KEYS[key] == TYPES.INTEGER) {
|
|
|
|
new_data[key] = +value;
|
|
|
|
} else if(KEYS[key] == TYPES.STRING) {
|
|
|
|
new_data[key] = decodeURIComponent(value).replace(/\+/g, ' ');
|
|
|
|
} else if(key.substr(key.length-2) == '[]') {
|
|
|
|
key = key.substr(0, key.length-2);
|
|
|
|
if(KEYS[key] == TYPES.INTEGER_ARRAY) {
|
|
|
|
if(typeof new_data[key] == 'undefined') new_data[key] = [];
|
|
|
|
new_data[key].push(+value);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2011-03-28 14:29:03 -07:00
|
|
|
|
2014-02-19 13:58:39 -08:00
|
|
|
if(new_data.biology) {
|
|
|
|
wardrobe.outfits.setPetStateAssetsByIds(new_data.biology);
|
2013-12-08 20:59:36 -08:00
|
|
|
}
|
2010-10-10 19:18:42 -07:00
|
|
|
if(new_data.color !== data.color || new_data.species !== data.species) {
|
2012-07-26 20:47:22 -07:00
|
|
|
wardrobe.outfits.setPetTypeByColorAndSpecies(new_data.color, new_data.species);
|
2010-10-10 19:18:42 -07:00
|
|
|
}
|
|
|
|
if(new_data.closet) {
|
|
|
|
if(!arraysMatch(new_data.closet, data.closet)) {
|
2012-07-26 20:47:22 -07:00
|
|
|
wardrobe.outfits.setClosetItemsByIds(new_data.closet.slice(0));
|
2010-10-10 19:18:42 -07:00
|
|
|
}
|
2010-11-12 13:14:08 -08:00
|
|
|
} else if(new_data.objects && !arraysMatch(new_data.objects, data.closet)) {
|
2012-07-26 20:47:22 -07:00
|
|
|
wardrobe.outfits.setClosetItemsByIds(new_data.objects.slice(0));
|
2010-11-12 13:14:08 -08:00
|
|
|
} else {
|
2012-07-26 20:47:22 -07:00
|
|
|
wardrobe.outfits.setClosetItemsByIds([]);
|
2010-10-10 19:18:42 -07:00
|
|
|
}
|
2010-11-12 13:14:08 -08:00
|
|
|
if(new_data.objects) {
|
|
|
|
if(!arraysMatch(new_data.objects, data.objects)) {
|
2012-07-26 20:47:22 -07:00
|
|
|
wardrobe.outfits.setWornItemsByIds(new_data.objects.slice(0));
|
2010-11-12 13:14:08 -08:00
|
|
|
}
|
|
|
|
} else {
|
2012-07-26 20:47:22 -07:00
|
|
|
wardrobe.outfits.setWornItemsByIds([]);
|
2010-10-10 19:18:42 -07:00
|
|
|
}
|
|
|
|
if(new_data.name != data.name && new_data.name) {
|
|
|
|
wardrobe.base_pet.setName(new_data.name);
|
|
|
|
}
|
|
|
|
if(new_data.state != data.state) {
|
2012-07-26 20:47:22 -07:00
|
|
|
wardrobe.outfits.setPetStateById(new_data.state);
|
2010-10-10 19:18:42 -07:00
|
|
|
}
|
2010-11-12 17:58:28 -08:00
|
|
|
if(new_data.outfit != data.outfit) {
|
2012-07-26 20:47:22 -07:00
|
|
|
wardrobe.outfits.setId(new_data.outfit);
|
2010-11-12 17:58:28 -08:00
|
|
|
}
|
2010-10-10 19:18:42 -07:00
|
|
|
if(new_data.search != data.search || new_data.search_offset != data.search_offset) {
|
|
|
|
wardrobe.search.setItemsByQuery(new_data.search, {offset: new_data.search_offset});
|
|
|
|
}
|
|
|
|
data = new_data;
|
|
|
|
parse_in_progress = false;
|
2010-11-10 13:59:54 -08:00
|
|
|
updateLinksWithReturnTo();
|
2010-10-10 19:18:42 -07:00
|
|
|
}
|
2011-03-28 14:29:03 -07:00
|
|
|
|
2010-10-10 19:18:42 -07:00
|
|
|
function changeQuery(changes) {
|
|
|
|
var value;
|
|
|
|
if(!parse_in_progress) {
|
|
|
|
for(var key in changes) {
|
|
|
|
if(changes.hasOwnProperty(key)) {
|
|
|
|
value = changes[key];
|
|
|
|
if(value === undefined) {
|
|
|
|
delete data[key];
|
|
|
|
} else {
|
|
|
|
data[key] = changes[key];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
updateQuery();
|
|
|
|
}
|
|
|
|
}
|
2011-03-28 14:29:03 -07:00
|
|
|
|
2010-10-10 19:18:42 -07:00
|
|
|
function updateQuery() {
|
|
|
|
var new_query;
|
|
|
|
new_query = $.param(data).replace(/%5B%5D/g, '[]');
|
|
|
|
previous_query = new_query;
|
|
|
|
document.location.hash = '#' + new_query;
|
2010-11-10 13:59:54 -08:00
|
|
|
updateLinksWithReturnTo();
|
|
|
|
}
|
2011-03-28 14:29:03 -07:00
|
|
|
|
2010-11-10 13:59:54 -08:00
|
|
|
function updateLinksWithReturnTo() {
|
|
|
|
links_with_return_to.each(function () {
|
|
|
|
var new_return_to = 'return_to=' + encodeURIComponent(
|
|
|
|
document.location.pathname +
|
|
|
|
document.location.search +
|
|
|
|
document.location.hash
|
|
|
|
);
|
|
|
|
this.href = this.href.replace(/return_to=[^&]+/, new_return_to);
|
|
|
|
});
|
2010-10-10 19:18:42 -07:00
|
|
|
}
|
2011-03-28 14:29:03 -07:00
|
|
|
|
2010-10-10 19:18:42 -07:00
|
|
|
this.initialize = function () {
|
|
|
|
checkQuery();
|
|
|
|
setInterval(checkQuery, 100);
|
|
|
|
}
|
2011-03-28 14:29:03 -07:00
|
|
|
|
2010-11-12 13:14:08 -08:00
|
|
|
function singleOutfitResponse(event_name, response) {
|
2012-07-26 20:47:22 -07:00
|
|
|
wardrobe.outfits.bind(event_name, function () {
|
|
|
|
if(!wardrobe.outfits.in_transaction) response.apply(this, arguments);
|
2010-11-12 13:14:08 -08:00
|
|
|
});
|
|
|
|
}
|
2011-03-28 14:29:03 -07:00
|
|
|
|
2010-11-12 13:14:08 -08:00
|
|
|
singleOutfitResponse('updateClosetItems', function (items) {
|
2012-03-06 19:18:36 -08:00
|
|
|
var item_ids = items.mapProperty('id');
|
2010-10-10 19:18:42 -07:00
|
|
|
if(!arraysMatch(item_ids, data.closet)) {
|
|
|
|
changeQuery({closet: item_ids});
|
|
|
|
}
|
|
|
|
});
|
2011-03-28 14:29:03 -07:00
|
|
|
|
2010-11-12 13:14:08 -08:00
|
|
|
singleOutfitResponse('updateWornItems', function (items) {
|
2012-03-06 19:18:36 -08:00
|
|
|
var item_ids = items.mapProperty('id'), changes = {};
|
2010-10-10 19:18:42 -07:00
|
|
|
if(!arraysMatch(item_ids, data.objects)) {
|
|
|
|
changes.objects = item_ids;
|
|
|
|
}
|
|
|
|
if(arraysMatch(item_ids, data.closet) || arraysMatch(item_ids, data.objects)) {
|
|
|
|
changes.closet = undefined;
|
|
|
|
} else {
|
2012-07-26 20:47:22 -07:00
|
|
|
changes.closet = wardrobe.outfits.getClosetItems().mapProperty('id');
|
2010-10-10 19:18:42 -07:00
|
|
|
}
|
|
|
|
if(changes.objects || changes.closet) changeQuery(changes);
|
|
|
|
});
|
2011-03-28 14:29:03 -07:00
|
|
|
|
2010-11-12 13:14:08 -08:00
|
|
|
singleOutfitResponse('updatePetType', function (pet_type) {
|
2010-10-10 19:18:42 -07:00
|
|
|
if(pet_type.color_id != data.color || pet_type.species_id != data.species) {
|
|
|
|
changeQuery({
|
|
|
|
color: pet_type.color_id,
|
|
|
|
species: pet_type.species_id,
|
|
|
|
state: undefined
|
|
|
|
});
|
|
|
|
}
|
|
|
|
});
|
2011-03-28 14:29:03 -07:00
|
|
|
|
2010-11-12 13:14:08 -08:00
|
|
|
singleOutfitResponse('petTypeNotFound', function () {
|
2010-10-10 19:18:42 -07:00
|
|
|
window.history.back();
|
|
|
|
});
|
2011-03-28 14:29:03 -07:00
|
|
|
|
2010-11-12 13:14:08 -08:00
|
|
|
singleOutfitResponse('updatePetState', function (pet_state) {
|
2012-07-26 20:47:22 -07:00
|
|
|
var pet_type = wardrobe.outfits.getPetType();
|
2014-03-06 13:22:30 -08:00
|
|
|
if(pet_state.id != data.state && pet_type) {
|
2014-02-19 13:58:39 -08:00
|
|
|
changeQuery({biology: undefined, state: pet_state.id});
|
2010-10-10 19:18:42 -07:00
|
|
|
}
|
|
|
|
});
|
2011-03-28 14:29:03 -07:00
|
|
|
|
2010-11-12 17:58:28 -08:00
|
|
|
singleOutfitResponse('setOutfit', function (outfit) {
|
|
|
|
if(outfit.id != data.outfit) {
|
|
|
|
changeQuery({outfit: outfit.id});
|
|
|
|
}
|
|
|
|
});
|
2011-03-28 14:29:03 -07:00
|
|
|
|
2012-07-26 20:47:22 -07:00
|
|
|
wardrobe.outfits.bind('loadOutfit', function (outfit) {
|
2010-11-12 13:14:08 -08:00
|
|
|
changeQuery({
|
2014-02-19 13:58:39 -08:00
|
|
|
biology: undefined,
|
2010-11-12 13:14:08 -08:00
|
|
|
closet: outfit.getClosetItemIds(),
|
|
|
|
color: outfit.pet_type.color_id,
|
|
|
|
objects: outfit.getWornItemIds(),
|
2010-11-12 17:58:28 -08:00
|
|
|
outfit: outfit.id,
|
2010-11-12 13:14:08 -08:00
|
|
|
species: outfit.pet_type.species_id,
|
|
|
|
state: outfit.pet_state.id
|
|
|
|
});
|
|
|
|
});
|
2011-03-28 14:29:03 -07:00
|
|
|
|
2012-07-26 20:47:22 -07:00
|
|
|
wardrobe.outfits.bind('outfitNotFound', function (outfit) {
|
2010-11-12 17:58:28 -08:00
|
|
|
var new_id = outfit ? outfit.id : undefined;
|
|
|
|
changeQuery({outfit: new_id});
|
|
|
|
});
|
2011-03-28 14:29:03 -07:00
|
|
|
|
2010-10-10 19:18:42 -07:00
|
|
|
wardrobe.search.bind('updateRequest', function (request) {
|
|
|
|
if(request.offset != data.search_offset || request.query != data.search) {
|
|
|
|
changeQuery({
|
|
|
|
search_offset: request.offset,
|
|
|
|
search: request.query
|
|
|
|
});
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2010-11-08 17:40:03 -08:00
|
|
|
View.Outfits = function (wardrobe) {
|
2011-02-09 17:29:43 -08:00
|
|
|
var current_outfit_permalink_el = $('#current-outfit-permalink'),
|
2011-02-09 16:29:31 -08:00
|
|
|
new_outfit_form_el = $('#save-outfit-form'),
|
|
|
|
new_outfit_name_el = $('#save-outfit-name'),
|
2010-11-13 05:50:37 -08:00
|
|
|
outfits_el = $('#preview-outfits'),
|
2010-11-10 13:59:54 -08:00
|
|
|
outfits_list_el = outfits_el.children('ul'),
|
2010-11-12 17:58:28 -08:00
|
|
|
outfit_not_found_el = $('#outfit-not-found'),
|
2010-11-13 05:50:37 -08:00
|
|
|
save_current_outfit_el = $('#save-current-outfit'),
|
|
|
|
save_current_outfit_name_el = save_current_outfit_el.children('span'),
|
|
|
|
save_outfit_wrapper_el = $('#save-outfit-wrapper'),
|
|
|
|
save_success_el = $('#save-success'),
|
|
|
|
save_error_el = $('#save-error'),
|
2010-11-11 10:43:22 -08:00
|
|
|
stars = $('#preview-outfits div.outfit-star'),
|
2010-11-13 05:50:37 -08:00
|
|
|
sidebar_el = $('#preview-sidebar'),
|
2010-11-11 10:43:22 -08:00
|
|
|
signed_in,
|
2012-07-17 13:14:05 -07:00
|
|
|
previously_viewing = '';
|
2011-03-28 14:29:03 -07:00
|
|
|
|
2010-11-24 17:51:01 -08:00
|
|
|
function liForOutfit(outfit) {
|
|
|
|
return $('li.outfit-' + outfit.id);
|
|
|
|
}
|
2011-03-28 14:29:03 -07:00
|
|
|
|
2010-11-10 13:59:54 -08:00
|
|
|
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);
|
|
|
|
}
|
2011-03-28 14:29:03 -07:00
|
|
|
|
2010-11-11 10:43:22 -08:00
|
|
|
/* Show for login */
|
2011-03-28 14:29:03 -07:00
|
|
|
|
2010-11-11 10:43:22 -08:00
|
|
|
signed_in = $('meta[name=user-signed-in]').attr('content') == 'true';
|
2010-11-12 13:36:29 -08:00
|
|
|
if(signed_in) {
|
|
|
|
$(document.body).addClass('user-signed-in');
|
|
|
|
} else {
|
|
|
|
$(document.body).addClass('user-not-signed-in');
|
|
|
|
}
|
2011-03-28 14:29:03 -07:00
|
|
|
|
2010-11-10 13:59:54 -08:00
|
|
|
/* Nav */
|
2011-03-28 14:29:03 -07:00
|
|
|
|
2010-11-10 13:59:54 -08:00
|
|
|
function showCloset() {
|
2012-07-26 20:47:22 -07:00
|
|
|
sharing.onHide();
|
2010-11-10 13:59:54 -08:00
|
|
|
navigateTo('');
|
|
|
|
}
|
2011-03-28 14:29:03 -07:00
|
|
|
|
2010-11-10 13:59:54 -08:00
|
|
|
function showOutfits() {
|
2012-07-26 20:47:22 -07:00
|
|
|
sharing.onHide();
|
|
|
|
wardrobe.outfits.loadOutfits();
|
2010-11-10 13:59:54 -08:00
|
|
|
navigateTo('viewing-outfits');
|
|
|
|
}
|
2012-07-17 09:15:04 -07:00
|
|
|
|
|
|
|
function showSharing() {
|
2012-07-26 20:47:22 -07:00
|
|
|
sharing.onShow();
|
2012-07-17 09:15:04 -07:00
|
|
|
navigateTo('sharing');
|
|
|
|
}
|
2011-03-28 14:29:03 -07:00
|
|
|
|
2011-02-09 16:29:31 -08:00
|
|
|
function showNewOutfitForm() {
|
|
|
|
new_outfit_name_el.val('');
|
|
|
|
new_outfit_form_el.removeClass('starred').stopLoading();
|
|
|
|
save_outfit_wrapper_el.addClass('saving-outfit');
|
2010-11-10 13:59:54 -08:00
|
|
|
new_outfit_name_el.focus();
|
|
|
|
}
|
2011-03-28 14:29:03 -07:00
|
|
|
|
2011-02-09 16:29:31 -08:00
|
|
|
function hideNewOutfitForm() {
|
|
|
|
save_outfit_wrapper_el.removeClass('saving-outfit');
|
|
|
|
}
|
2011-03-28 14:29:03 -07:00
|
|
|
|
2012-07-25 16:02:23 -07:00
|
|
|
$('#preview-sidebar-navbar-closet').click(showCloset);
|
|
|
|
$('#preview-sidebar-navbar-sharing').click(function () {
|
|
|
|
sharing.startLoading();
|
2012-07-26 20:47:22 -07:00
|
|
|
wardrobe.outfits.share();
|
2012-07-25 16:02:23 -07:00
|
|
|
showSharing();
|
|
|
|
});
|
|
|
|
$('#preview-sidebar-navbar-outfits').click(showOutfits);
|
2011-03-28 14:29:03 -07:00
|
|
|
|
2011-02-09 16:29:31 -08:00
|
|
|
$('#save-outfit, #save-outfit-copy').click(showNewOutfitForm);
|
2011-03-28 14:29:03 -07:00
|
|
|
|
2011-02-09 16:29:31 -08:00
|
|
|
$('#save-outfit-cancel').click(hideNewOutfitForm);
|
2011-03-28 14:29:03 -07:00
|
|
|
|
2010-11-12 13:36:29 -08:00
|
|
|
$('#save-outfit-not-signed-in').click(function () {
|
|
|
|
window.location.replace($('#userbar a').attr('href'));
|
2010-11-11 10:43:22 -08:00
|
|
|
});
|
2011-03-28 14:29:03 -07:00
|
|
|
|
2010-11-11 10:43:22 -08:00
|
|
|
/* Outfits list */
|
2012-07-27 00:21:22 -07:00
|
|
|
|
|
|
|
var list_image_subscriptions = {};
|
|
|
|
|
|
|
|
function listSubscribeToImage(outfit) {
|
|
|
|
list_image_subscriptions[outfit.id] = wardrobe.image_subscriptions.subscribe(outfit);
|
|
|
|
}
|
|
|
|
|
|
|
|
function listUnsubscribeFromImage(outfit) {
|
|
|
|
if(outfit.id in list_image_subscriptions) {
|
|
|
|
if(list_image_subscriptions[outfit.id] !== null) {
|
|
|
|
wardrobe.image_subscriptions.unsubscribe(list_image_subscriptions[outfit.id]);
|
|
|
|
}
|
|
|
|
|
|
|
|
delete list_image_subscriptions[outfit.id];
|
|
|
|
}
|
|
|
|
}
|
2011-03-28 14:29:03 -07:00
|
|
|
|
2010-11-11 10:43:22 -08:00
|
|
|
$('#outfit-template').template('outfitTemplate');
|
2011-03-28 14:29:03 -07:00
|
|
|
|
2012-07-26 20:47:22 -07:00
|
|
|
wardrobe.outfits.bind('outfitsLoaded', function (outfits) {
|
2010-11-11 10:43:22 -08:00
|
|
|
var outfit_els = $.tmpl('outfitTemplate', outfits);
|
|
|
|
outfits_list_el.html('').append(outfit_els).addClass('loaded');
|
2010-11-12 17:58:28 -08:00
|
|
|
updateActiveOutfit();
|
2012-07-27 00:21:22 -07:00
|
|
|
|
|
|
|
for(var i = 0; i < outfits.length; i++) {
|
|
|
|
listSubscribeToImage(outfits[i]);
|
|
|
|
}
|
2010-11-11 10:43:22 -08:00
|
|
|
});
|
2011-03-28 14:29:03 -07:00
|
|
|
|
2012-07-26 20:47:22 -07:00
|
|
|
wardrobe.outfits.bind('addOutfit', function (outfit, i) {
|
2010-11-11 10:43:22 -08:00
|
|
|
var next_child = outfits_list_el.children().not('.hiding').eq(i),
|
2012-07-31 08:14:32 -07:00
|
|
|
outfit_el = $.tmpl('outfitTemplate', outfit.clone());
|
2010-11-11 10:43:22 -08:00
|
|
|
if(next_child.length) {
|
|
|
|
outfit_el.insertBefore(next_child);
|
|
|
|
} else {
|
|
|
|
outfit_el.appendTo(outfits_list_el);
|
|
|
|
}
|
2010-11-12 17:58:28 -08:00
|
|
|
updateActiveOutfit();
|
2012-07-27 00:21:22 -07:00
|
|
|
|
2012-07-31 08:14:32 -07:00
|
|
|
var naturalWidth = outfit_el.css('width');
|
|
|
|
log("Natural width is", naturalWidth, outfit_el.width());
|
2012-07-27 00:21:22 -07:00
|
|
|
outfit_el.width(0).animate({width: naturalWidth}, 'normal');
|
|
|
|
listSubscribeToImage(outfit);
|
2010-11-10 13:59:54 -08:00
|
|
|
});
|
2011-03-28 14:29:03 -07:00
|
|
|
|
2012-07-26 20:47:22 -07:00
|
|
|
wardrobe.outfits.bind('removeOutfit', function (outfit, i) {
|
2010-11-11 10:43:22 -08:00
|
|
|
var outfit_el = outfits_list_el.children().not('.hiding').eq(i);
|
2012-07-27 00:21:22 -07:00
|
|
|
outfit_el.addClass('hiding').stop(true).animate({width: 0}, 'normal', function () { outfit_el.remove() });
|
|
|
|
listUnsubscribeFromImage(outfit);
|
2010-11-11 10:43:22 -08:00
|
|
|
});
|
2011-03-28 14:29:03 -07:00
|
|
|
|
2012-07-29 13:07:18 -07:00
|
|
|
$('#preview-outfits li header, #preview-outfits li .outfit-thumbnail-wrapper').live('click', function () {
|
2012-07-26 20:47:22 -07:00
|
|
|
wardrobe.outfits.load($(this).tmplItem().data.id);
|
2010-11-12 13:14:08 -08:00
|
|
|
});
|
2011-03-28 14:29:03 -07:00
|
|
|
|
2010-11-24 17:51:01 -08:00
|
|
|
$('a.outfit-rename-button').live('click', function (e) {
|
|
|
|
e.preventDefault();
|
|
|
|
var li = $(this).closest('li').addClass('renaming'),
|
2012-07-27 00:21:22 -07:00
|
|
|
name = li.find('span.outfit-name').text();
|
2010-11-24 17:51:01 -08:00
|
|
|
li.find('input.outfit-rename-field').val(name).focus();
|
|
|
|
});
|
2011-03-28 14:29:03 -07:00
|
|
|
|
2010-11-24 17:51:01 -08:00
|
|
|
function submitRename() {
|
|
|
|
var el = $(this), outfit = el.tmplItem().data, new_name = el.val(),
|
|
|
|
li = el.closest('li').removeClass('renaming');
|
|
|
|
if(new_name != outfit.name) {
|
2011-02-10 14:50:47 -08:00
|
|
|
li.startLoading();
|
2012-07-26 20:47:22 -07:00
|
|
|
wardrobe.outfits.renameOutfit(outfit, new_name);
|
2010-11-24 17:51:01 -08:00
|
|
|
}
|
|
|
|
}
|
2011-03-28 14:29:03 -07:00
|
|
|
|
2010-11-24 17:51:01 -08:00
|
|
|
$('input.outfit-rename-field').live('blur', submitRename);
|
2011-03-28 14:29:03 -07:00
|
|
|
|
2010-11-24 17:51:01 -08:00
|
|
|
$('form.outfit-rename-form').live('submit', function (e) {
|
|
|
|
e.preventDefault();
|
|
|
|
var input = $(this).find('input');
|
|
|
|
submitRename.apply(input);
|
|
|
|
});
|
2011-03-28 14:29:03 -07:00
|
|
|
|
2010-11-08 17:40:03 -08:00
|
|
|
$('input.outfit-url').live('mouseover', function () {
|
|
|
|
this.focus();
|
|
|
|
}).live('mouseout', function () {
|
|
|
|
this.blur();
|
|
|
|
});
|
2011-03-28 14:29:03 -07:00
|
|
|
|
2012-07-27 00:21:22 -07:00
|
|
|
$('a.outfit-delete').live('click', function (e) {
|
|
|
|
e.stopPropagation();
|
2010-11-08 17:40:03 -08:00
|
|
|
e.preventDefault();
|
|
|
|
$(this).closest('li').addClass('confirming-deletion');
|
|
|
|
});
|
2011-03-28 14:29:03 -07:00
|
|
|
|
2010-11-11 10:43:22 -08:00
|
|
|
$('a.outfit-delete-confirmation-yes').live('click', function (e) {
|
2010-11-12 17:58:28 -08:00
|
|
|
var outfit = $(this).tmplItem().data;
|
2010-11-11 10:43:22 -08:00
|
|
|
e.preventDefault();
|
2012-07-26 20:47:22 -07:00
|
|
|
wardrobe.outfits.destroyOutfit(outfit);
|
|
|
|
if(wardrobe.outfits.getOutfit().id == outfit.id) {
|
|
|
|
wardrobe.outfits.setId(null);
|
2010-11-12 17:58:28 -08:00
|
|
|
}
|
2010-11-11 10:43:22 -08:00
|
|
|
});
|
2011-03-28 14:29:03 -07:00
|
|
|
|
2010-11-08 17:40:03 -08:00
|
|
|
$('a.outfit-delete-confirmation-no').live('click', function (e) {
|
|
|
|
e.preventDefault();
|
|
|
|
$(this).closest('li').removeClass('confirming-deletion');
|
|
|
|
});
|
2011-03-28 14:29:03 -07:00
|
|
|
|
2012-07-27 00:21:22 -07:00
|
|
|
stars.live('click', function (e) {
|
|
|
|
e.stopPropagation();
|
2010-11-11 10:43:22 -08:00
|
|
|
var el = $(this);
|
2011-02-10 14:50:47 -08:00
|
|
|
el.closest('li').startLoading();
|
2012-07-26 20:47:22 -07:00
|
|
|
wardrobe.outfits.toggleOutfitStar(el.tmplItem().data);
|
2010-11-11 10:43:22 -08:00
|
|
|
});
|
2012-07-17 09:15:04 -07:00
|
|
|
|
2012-07-31 08:34:28 -07:00
|
|
|
function absoluteUrl(path_or_url) {
|
|
|
|
if(path_or_url.indexOf('://') == -1) {
|
|
|
|
var host = document.location.protocol + "//" + document.location.host;
|
|
|
|
return host + path_or_url;
|
|
|
|
} else {
|
|
|
|
return path_or_url;
|
|
|
|
}
|
2012-07-17 11:42:31 -07:00
|
|
|
}
|
|
|
|
|
2012-07-17 09:15:04 -07:00
|
|
|
function generateOutfitPermalink(outfit) {
|
2012-07-31 08:34:28 -07:00
|
|
|
return absoluteUrl("/outfits/" + outfit.id);
|
2012-07-17 09:15:04 -07:00
|
|
|
}
|
2011-03-28 14:29:03 -07:00
|
|
|
|
|
|
|
function setOutfitPermalink(outfit, outfit_permalink_el, outfit_url_el) {
|
2012-07-17 09:15:04 -07:00
|
|
|
var url = generateOutfitPermalink(outfit);
|
2011-03-28 14:29:03 -07:00
|
|
|
outfit_permalink_el.attr('href', url);
|
|
|
|
if(outfit_url_el) outfit_url_el.val(url);
|
2011-02-10 14:50:47 -08:00
|
|
|
}
|
2011-03-28 14:29:03 -07:00
|
|
|
|
|
|
|
function setCurrentOutfitPermalink(outfit) {
|
|
|
|
setOutfitPermalink(outfit, current_outfit_permalink_el);
|
|
|
|
}
|
|
|
|
|
2010-11-12 17:58:28 -08:00
|
|
|
function setActiveOutfit(outfit) {
|
|
|
|
outfits_list_el.find('li.active').removeClass('active');
|
|
|
|
if(outfit.id) {
|
2011-03-28 14:29:03 -07:00
|
|
|
setCurrentOutfitPermalink(outfit);
|
2010-11-24 17:51:01 -08:00
|
|
|
liForOutfit(outfit).addClass('active');
|
2010-11-13 05:50:37 -08:00
|
|
|
save_current_outfit_name_el.text(outfit.name);
|
2010-11-12 17:58:28 -08:00
|
|
|
}
|
2010-11-13 05:50:37 -08:00
|
|
|
save_outfit_wrapper_el.toggleClass('active-outfit', outfit.id ? true : false);
|
2010-11-12 17:58:28 -08:00
|
|
|
}
|
2011-03-28 14:29:03 -07:00
|
|
|
|
2010-11-12 17:58:28 -08:00
|
|
|
function updateActiveOutfit() {
|
2012-07-26 20:47:22 -07:00
|
|
|
setActiveOutfit(wardrobe.outfits.getOutfit());
|
2010-11-12 17:58:28 -08:00
|
|
|
}
|
2011-03-28 14:29:03 -07:00
|
|
|
|
2012-07-26 20:47:22 -07:00
|
|
|
wardrobe.outfits.bind('setOutfit', setActiveOutfit);
|
|
|
|
wardrobe.outfits.bind('outfitNotFound', setActiveOutfit);
|
2011-03-28 14:29:03 -07:00
|
|
|
|
2012-07-26 20:47:22 -07:00
|
|
|
wardrobe.outfits.bind('outfitRenamed', function (outfit) {
|
|
|
|
if(outfit.id == wardrobe.outfits.getId()) {
|
2010-11-24 17:51:01 -08:00
|
|
|
save_current_outfit_name_el.text(outfit.name);
|
|
|
|
}
|
|
|
|
});
|
2012-07-17 11:42:31 -07:00
|
|
|
|
2012-07-27 00:21:22 -07:00
|
|
|
function outfitElement(outfit) {
|
|
|
|
return outfits_el.find('li.outfit-' + outfit.id);
|
|
|
|
}
|
|
|
|
|
|
|
|
wardrobe.outfits.bind('saveSuccess', function (outfit) {
|
|
|
|
listSubscribeToImage(outfit);
|
|
|
|
});
|
|
|
|
|
|
|
|
wardrobe.image_subscriptions.bind('imageEnqueued', function (outfit) {
|
|
|
|
if(outfit.id in list_image_subscriptions) {
|
|
|
|
log("List sees imageEnqueued for", outfit);
|
|
|
|
outfitElement(outfit).removeClass('thumbnail-loaded');
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
wardrobe.image_subscriptions.bind('imageReady', function (outfit) {
|
|
|
|
if(outfit.id in list_image_subscriptions) {
|
|
|
|
log("List sees imageReady for", outfit);
|
|
|
|
listUnsubscribeFromImage(outfit);
|
|
|
|
|
|
|
|
var src = outfit.image_versions.small + '?' + (new Date()).getTime();
|
|
|
|
outfitElement(outfit).addClass('thumbnail-loaded').addClass('thumbnail-available').
|
2012-07-29 13:07:18 -07:00
|
|
|
find('img.outfit-thumbnail').attr('src', src);
|
2012-07-27 00:21:22 -07:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2012-07-17 11:42:31 -07:00
|
|
|
/* Sharing */
|
|
|
|
|
2012-07-17 13:14:05 -07:00
|
|
|
var sharing = new function Sharing() {
|
2012-07-25 16:02:23 -07:00
|
|
|
var WRAPPER = $('#preview-sharing');
|
2012-07-17 13:14:05 -07:00
|
|
|
var sharing_url_els = {
|
|
|
|
permalink: $('#preview-sharing-permalink-url'),
|
|
|
|
large_image: $('#preview-sharing-large-image-url'),
|
|
|
|
medium_image: $('#preview-sharing-medium-image-url'),
|
|
|
|
small_image: $('#preview-sharing-small-image-url'),
|
|
|
|
};
|
|
|
|
var format_selector_els = $('#preview-sharing-url-formats li');
|
2012-07-26 20:47:22 -07:00
|
|
|
var thumbnail_el = $('#preview-sharing-thumbnail');
|
2013-01-04 17:48:47 -08:00
|
|
|
var templates = {
|
|
|
|
html: {
|
|
|
|
image: $('#sharing-html-image-template'),
|
|
|
|
text: $('#sharing-html-text-template')
|
|
|
|
},
|
|
|
|
bbcode: {
|
|
|
|
image: $('#sharing-bbcode-image-template'),
|
|
|
|
text: $('#sharing-bbcode-text-template')
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function templateHTML(template, options) {
|
|
|
|
var contents = template.tmpl(options);
|
|
|
|
var contentsHTML = contents.clone().wrap('<div>').parent().html();
|
|
|
|
return contentsHTML;
|
|
|
|
}
|
2012-07-17 11:42:31 -07:00
|
|
|
|
2013-01-04 17:48:47 -08:00
|
|
|
// The HTML and BBCode formats could probably be handled more dynamic-like.
|
2012-07-17 13:14:05 -07:00
|
|
|
var formats = {
|
|
|
|
plain: {
|
2013-01-04 17:48:47 -08:00
|
|
|
image: function (image_url) { return image_url },
|
|
|
|
text: function (permalink) { return permalink }
|
2012-07-17 13:14:05 -07:00
|
|
|
},
|
|
|
|
html: {
|
2013-01-04 17:48:47 -08:00
|
|
|
image: function (image_url, permalink) {
|
|
|
|
return templateHTML(templates.html.image, {
|
|
|
|
image_url: image_url,
|
|
|
|
permalink: permalink
|
|
|
|
});
|
2012-07-17 13:14:05 -07:00
|
|
|
},
|
2013-01-04 17:48:47 -08:00
|
|
|
text: function (permalink) {
|
|
|
|
return templateHTML(templates.html.text, {
|
|
|
|
permalink: permalink
|
|
|
|
});
|
2012-07-17 13:14:05 -07:00
|
|
|
}
|
|
|
|
},
|
|
|
|
bbcode: {
|
2013-01-04 17:48:47 -08:00
|
|
|
image: function (image_url, permalink) {
|
|
|
|
return templateHTML(templates.bbcode.image, {
|
|
|
|
image_url: image_url,
|
|
|
|
permalink: permalink
|
|
|
|
});
|
2012-07-17 13:14:05 -07:00
|
|
|
},
|
2013-01-04 17:48:47 -08:00
|
|
|
text: function (permalink) {
|
|
|
|
return templateHTML(templates.bbcode.text, {
|
|
|
|
permalink: permalink
|
|
|
|
});
|
2012-07-17 13:14:05 -07:00
|
|
|
}
|
2012-07-17 11:42:31 -07:00
|
|
|
}
|
2012-07-17 13:14:05 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
var format = formats.plain;
|
|
|
|
var urls = {permalink: null, small_image: null, medium_image: null,
|
|
|
|
large_image: null};
|
|
|
|
|
|
|
|
format_selector_els.click(function () {
|
|
|
|
var selector_el = $(this);
|
|
|
|
format_selector_els.removeClass('active');
|
|
|
|
selector_el.addClass('active');
|
|
|
|
log("Setting sharing URL format:", selector_el.attr('data-format'));
|
|
|
|
format = formats[selector_el.attr('data-format')];
|
|
|
|
formatUrls();
|
|
|
|
});
|
2012-07-17 11:42:31 -07:00
|
|
|
|
2012-07-26 20:47:22 -07:00
|
|
|
var image_subscription = null;
|
|
|
|
function unsubscribeFromImage() {
|
2012-07-27 00:21:22 -07:00
|
|
|
wardrobe.image_subscriptions.unsubscribe(image_subscription);
|
|
|
|
image_subscription = null;
|
2012-07-26 20:47:22 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
function subscribeToImage(outfit) {
|
|
|
|
image_subscription = wardrobe.image_subscriptions.subscribe(outfit);
|
|
|
|
}
|
|
|
|
|
2012-07-27 00:21:22 -07:00
|
|
|
function subscribeToImageIfVisible(outfit) {
|
|
|
|
if(outfit && sidebar_el.hasClass('sharing')) {
|
|
|
|
subscribeToImage(outfit);
|
2012-07-26 20:47:22 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
var current_shared_outfit = {id: null};
|
2012-07-17 13:14:05 -07:00
|
|
|
this.setOutfit = function (outfit) {
|
2012-07-26 20:47:22 -07:00
|
|
|
// If outfit has no ID but we're already on the Sharing tab (e.g. user is
|
|
|
|
// on Sharing but goes back in history to a no-ID outfit), we can't
|
|
|
|
// exactly do anything with it but submit it for sharing.
|
|
|
|
if(!outfit.id) {
|
|
|
|
sharing.startLoading();
|
|
|
|
wardrobe.outfits.share(outfit);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// But if the outfit does have a valid ID, we're good to go. If it's the
|
|
|
|
// same as the currently shared outfit ID, then don't even change
|
|
|
|
// anything. If it's new, then change everything.
|
|
|
|
if(outfit.id != current_shared_outfit.id) {
|
|
|
|
// The current shared outfit needs to be a clone, or else modifications
|
|
|
|
// to the active outfit will show up here, too, and then our comparison
|
|
|
|
// to discover if this is a new outfit ID or not fails.
|
|
|
|
current_shared_outfit = outfit.clone();
|
|
|
|
urls.permalink = generateOutfitPermalink(outfit);
|
2012-07-31 08:34:28 -07:00
|
|
|
urls.small_image = absoluteUrl(outfit.image_versions.small);
|
|
|
|
urls.medium_image = absoluteUrl(outfit.image_versions.medium);
|
|
|
|
urls.large_image = absoluteUrl(outfit.image_versions.large);
|
2012-07-26 20:47:22 -07:00
|
|
|
formatUrls();
|
|
|
|
WRAPPER.removeClass('thumbnail-available');
|
2012-07-27 00:21:22 -07:00
|
|
|
subscribeToImageIfVisible(current_shared_outfit);
|
2012-07-26 20:47:22 -07:00
|
|
|
}
|
2012-07-25 16:02:23 -07:00
|
|
|
WRAPPER.addClass('urls-loaded');
|
|
|
|
}
|
|
|
|
|
|
|
|
this.startLoading = function () {
|
|
|
|
WRAPPER.removeClass('urls-loaded');
|
2012-07-17 11:42:31 -07:00
|
|
|
}
|
|
|
|
|
2012-07-26 20:47:22 -07:00
|
|
|
this.onHide = function () {
|
|
|
|
unsubscribeFromImage();
|
|
|
|
}
|
|
|
|
|
|
|
|
this.onShow = function () {
|
2012-07-27 00:21:22 -07:00
|
|
|
subscribeToImageIfVisible(wardrobe.outfits.getOutfit());
|
2012-07-26 20:47:22 -07:00
|
|
|
}
|
|
|
|
|
2012-07-17 13:14:05 -07:00
|
|
|
function formatUrls() {
|
|
|
|
formatImageUrl('small_image');
|
|
|
|
formatImageUrl('medium_image');
|
|
|
|
formatImageUrl('large_image');
|
|
|
|
formatTextUrl('permalink');
|
2012-07-17 11:42:31 -07:00
|
|
|
}
|
|
|
|
|
2012-07-17 13:14:05 -07:00
|
|
|
function formatTextUrl(key) {
|
|
|
|
formatUrl(key, format.text(urls[key]));
|
2012-07-17 11:42:31 -07:00
|
|
|
}
|
|
|
|
|
2012-07-17 13:14:05 -07:00
|
|
|
function formatImageUrl(key) {
|
|
|
|
formatUrl(key, format.image(urls[key], urls.permalink));
|
2012-07-17 11:42:31 -07:00
|
|
|
}
|
|
|
|
|
2012-07-17 13:14:05 -07:00
|
|
|
function formatUrl(key, url) {
|
|
|
|
sharing_url_els[key].val(url);
|
|
|
|
}
|
2012-07-26 20:47:22 -07:00
|
|
|
|
|
|
|
wardrobe.image_subscriptions.bind('imageEnqueued', function (outfit) {
|
2012-07-27 00:21:22 -07:00
|
|
|
if(outfit.id == current_shared_outfit.id) {
|
|
|
|
log("Sharing thumbnail enqueued for outfit", outfit);
|
|
|
|
WRAPPER.removeClass('thumbnail-loaded');
|
|
|
|
}
|
2012-07-26 20:47:22 -07:00
|
|
|
});
|
|
|
|
|
|
|
|
wardrobe.image_subscriptions.bind('imageReady', function (outfit) {
|
2012-07-27 00:21:22 -07:00
|
|
|
if(outfit.id == current_shared_outfit.id) {
|
|
|
|
log("Sharing thumbnail ready for outfit", outfit);
|
|
|
|
var src = outfit.image_versions.small + '?' + outfit.image_layers_hash;
|
|
|
|
thumbnail_el.attr('src', src);
|
|
|
|
WRAPPER.addClass('thumbnail-loaded');
|
|
|
|
WRAPPER.addClass('thumbnail-available');
|
|
|
|
unsubscribeFromImage(outfit);
|
|
|
|
}
|
2012-07-26 20:47:22 -07:00
|
|
|
});
|
|
|
|
|
|
|
|
wardrobe.outfits.bind('updateSuccess', function (outfit) {
|
|
|
|
if(sidebar_el.hasClass('sharing')) {
|
|
|
|
subscribeToImage(outfit);
|
2012-07-17 11:42:31 -07:00
|
|
|
}
|
2012-07-26 20:47:22 -07:00
|
|
|
});
|
|
|
|
|
|
|
|
wardrobe.outfits.bind('setOutfit', function (outfit) {
|
|
|
|
log("Sharing sees the setOutfit signal, and will set", outfit);
|
|
|
|
sharing.setOutfit(outfit);
|
|
|
|
});
|
2012-07-17 11:42:31 -07:00
|
|
|
}
|
2011-03-28 14:29:03 -07:00
|
|
|
|
2010-11-10 13:59:54 -08:00
|
|
|
/* Saving */
|
2011-03-28 14:29:03 -07:00
|
|
|
|
2010-11-13 05:50:37 -08:00
|
|
|
save_current_outfit_el.click(function () {
|
2012-07-26 20:47:22 -07:00
|
|
|
wardrobe.outfits.update();
|
2010-11-13 05:50:37 -08:00
|
|
|
});
|
2011-03-28 14:29:03 -07:00
|
|
|
|
2010-11-10 13:59:54 -08:00
|
|
|
new_outfit_form_el.submit(function (e) {
|
2010-11-08 17:40:03 -08:00
|
|
|
e.preventDefault();
|
2011-02-10 14:50:47 -08:00
|
|
|
new_outfit_form_el.startLoading();
|
2012-07-26 20:47:22 -07:00
|
|
|
wardrobe.outfits.create({starred: new_outfit_form_el.hasClass('starred'), name: new_outfit_name_el.val()});
|
2010-11-10 13:59:54 -08:00
|
|
|
});
|
2011-03-28 14:29:03 -07:00
|
|
|
|
2011-02-09 16:29:31 -08:00
|
|
|
new_outfit_form_el.find('div.outfit-star').click(function () {
|
|
|
|
new_outfit_form_el.toggleClass('starred');
|
2010-11-11 10:43:22 -08:00
|
|
|
});
|
2011-03-28 14:29:03 -07:00
|
|
|
|
2010-11-10 13:59:54 -08:00
|
|
|
function saveErrorMessage(text) {
|
|
|
|
save_error_el.text(text).notify();
|
|
|
|
}
|
2011-03-28 14:29:03 -07:00
|
|
|
|
2012-07-26 20:47:22 -07:00
|
|
|
wardrobe.outfits.bind('saveSuccess', function (outfit) {
|
2010-11-10 13:59:54 -08:00
|
|
|
save_success_el.notify();
|
2010-11-13 05:50:37 -08:00
|
|
|
});
|
2011-03-28 14:29:03 -07:00
|
|
|
|
2012-07-26 20:47:22 -07:00
|
|
|
wardrobe.outfits.bind('createSuccess', function (outfit) {
|
2010-11-10 13:59:54 -08:00
|
|
|
showOutfits();
|
2011-02-09 16:29:31 -08:00
|
|
|
hideNewOutfitForm();
|
2010-11-10 13:59:54 -08:00
|
|
|
});
|
2012-07-17 09:15:04 -07:00
|
|
|
|
|
|
|
function shareComplete(outfit) {
|
2011-02-10 14:50:47 -08:00
|
|
|
save_outfit_wrapper_el.stopLoading().addClass('shared-outfit');
|
2012-07-17 13:14:05 -07:00
|
|
|
sharing.setOutfit(outfit);
|
2012-07-17 09:15:04 -07:00
|
|
|
showSharing();
|
|
|
|
}
|
|
|
|
|
2012-07-26 20:47:22 -07:00
|
|
|
wardrobe.outfits.bind('shareSuccess', shareComplete);
|
|
|
|
wardrobe.outfits.bind('shareSkipped', shareComplete);
|
2011-03-28 14:29:03 -07:00
|
|
|
|
2011-02-10 14:50:47 -08:00
|
|
|
function clearSharedOutfit() {
|
|
|
|
save_outfit_wrapper_el.removeClass('shared-outfit');
|
|
|
|
}
|
2011-03-28 14:29:03 -07:00
|
|
|
|
2012-07-26 20:47:22 -07:00
|
|
|
wardrobe.outfits.bind('updateClosetItems', clearSharedOutfit);
|
|
|
|
wardrobe.outfits.bind('updateWornItems', clearSharedOutfit);
|
|
|
|
wardrobe.outfits.bind('updatePetState', clearSharedOutfit);
|
2011-03-28 14:29:03 -07:00
|
|
|
|
2010-11-24 17:51:01 -08:00
|
|
|
function saveFailure(outfit, response) {
|
2013-01-04 18:08:41 -08:00
|
|
|
if(typeof response.full_error_messages !== 'undefined') {
|
|
|
|
saveErrorMessage(response.full_error_messages.join(', '));
|
2010-11-10 13:59:54 -08:00
|
|
|
} else {
|
2013-01-04 18:08:41 -08:00
|
|
|
saveErrorMessage("Could not save outfit. Please try again.");
|
2010-11-10 13:59:54 -08:00
|
|
|
}
|
2011-02-09 17:29:43 -08:00
|
|
|
new_outfit_form_el.stopLoading();
|
2010-11-24 17:51:01 -08:00
|
|
|
liForOutfit(outfit).stopLoading();
|
|
|
|
}
|
2011-03-28 14:29:03 -07:00
|
|
|
|
2012-07-26 20:47:22 -07:00
|
|
|
wardrobe.outfits.bind('saveFailure', saveFailure);
|
|
|
|
wardrobe.outfits.bind('saveFailure', saveFailure)
|
|
|
|
wardrobe.outfits.bind('shareFailure', function (outfit, response) {
|
2011-02-10 14:50:47 -08:00
|
|
|
save_outfit_wrapper_el.stopLoading();
|
|
|
|
saveFailure(outfit, response);
|
|
|
|
});
|
2011-03-28 14:29:03 -07:00
|
|
|
|
2010-11-12 17:58:28 -08:00
|
|
|
/* Error */
|
2011-03-28 14:29:03 -07:00
|
|
|
|
2012-07-26 20:47:22 -07:00
|
|
|
wardrobe.outfits.bind('outfitNotFound', function () {
|
2010-11-12 17:58:28 -08:00
|
|
|
outfit_not_found_el.notify();
|
|
|
|
});
|
2010-11-08 17:40:03 -08:00
|
|
|
}
|
|
|
|
|
2010-10-10 19:18:42 -07:00
|
|
|
View.PetStateForm = function (wardrobe) {
|
|
|
|
var INPUT_NAME = 'pet_state_id', form_query = '#pet-state-form',
|
|
|
|
form = $(form_query),
|
2013-01-31 17:46:34 -08:00
|
|
|
select = form.children('select');
|
|
|
|
|
|
|
|
select.change(function (e) {
|
|
|
|
var id = parseInt(select.children(':selected').val(), 10);
|
|
|
|
wardrobe.outfits.setPetStateById(id);
|
2010-10-10 19:18:42 -07:00
|
|
|
});
|
2011-03-28 14:29:03 -07:00
|
|
|
|
2010-10-10 19:18:42 -07:00
|
|
|
function updatePetState(pet_state) {
|
|
|
|
if(pet_state) {
|
2013-01-31 17:46:34 -08:00
|
|
|
select.val(pet_state.id);
|
2010-10-10 19:18:42 -07:00
|
|
|
}
|
|
|
|
}
|
2011-03-28 14:29:03 -07:00
|
|
|
|
2012-07-26 20:47:22 -07:00
|
|
|
wardrobe.outfits.bind('petTypeLoaded', function (pet_type) {
|
2013-01-31 17:46:34 -08:00
|
|
|
var pet_states = pet_type.pet_states, i, id, option;
|
|
|
|
select.children().remove();
|
|
|
|
if(pet_states.length == 1) {
|
2010-11-10 13:59:54 -08:00
|
|
|
form.addClass('hidden');
|
2010-10-10 19:18:42 -07:00
|
|
|
} else {
|
2010-11-10 13:59:54 -08:00
|
|
|
form.removeClass('hidden');
|
2013-01-31 17:46:34 -08:00
|
|
|
for(var i = 0; i < pet_states.length; i++) {
|
2011-02-07 05:46:15 -08:00
|
|
|
id = 'pet-state-button-' + i;
|
2013-01-31 17:46:34 -08:00
|
|
|
option = $('<option/>', {
|
|
|
|
value: pet_states[i].id,
|
|
|
|
text: pet_states[i].gender_mood_description
|
2010-10-10 19:18:42 -07:00
|
|
|
});
|
2013-01-31 17:46:34 -08:00
|
|
|
option.appendTo(select);
|
2010-10-10 19:18:42 -07:00
|
|
|
}
|
2012-07-26 20:47:22 -07:00
|
|
|
updatePetState(wardrobe.outfits.getPetState());
|
2010-10-10 19:18:42 -07:00
|
|
|
}
|
|
|
|
});
|
2011-03-28 14:29:03 -07:00
|
|
|
|
2012-07-26 20:47:22 -07:00
|
|
|
wardrobe.outfits.bind('updatePetState', updatePetState);
|
2010-10-10 19:18:42 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
View.PetTypeForm = function (wardrobe) {
|
|
|
|
var form = $('#pet-type-form'), dropdowns = {}, loaded = false;
|
|
|
|
form.submit(function (e) {
|
|
|
|
e.preventDefault();
|
2012-07-26 20:47:22 -07:00
|
|
|
wardrobe.outfits.setPetTypeByColorAndSpecies(
|
2010-10-10 19:18:42 -07:00
|
|
|
+dropdowns.color.val(), +dropdowns.species.val()
|
|
|
|
);
|
|
|
|
}).children('select').each(function () {
|
|
|
|
dropdowns[this.name] = $(this);
|
|
|
|
});
|
2011-03-28 14:29:03 -07:00
|
|
|
|
2010-10-10 19:18:42 -07:00
|
|
|
this.initialize = function () {
|
|
|
|
wardrobe.pet_attributes.load();
|
|
|
|
}
|
2011-03-28 14:29:03 -07:00
|
|
|
|
2010-10-10 19:18:42 -07:00
|
|
|
function updatePetType(pet_type) {
|
|
|
|
if(loaded && pet_type) {
|
|
|
|
$.each(dropdowns, function (name) {
|
|
|
|
dropdowns[name].val(pet_type[name + '_id']);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
2011-03-28 14:29:03 -07:00
|
|
|
|
2010-10-10 19:18:42 -07:00
|
|
|
wardrobe.pet_attributes.bind('update', function (attributes) {
|
|
|
|
$.each(attributes, function (type) {
|
|
|
|
var dropdown = dropdowns[type];
|
|
|
|
$.each(this, function () {
|
|
|
|
var option = $('<option/>', {
|
|
|
|
text: this.name,
|
|
|
|
value: this.id
|
|
|
|
});
|
|
|
|
option.appendTo(dropdown);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
loaded = true;
|
2012-07-26 20:47:22 -07:00
|
|
|
updatePetType(wardrobe.outfits.getPetType());
|
2010-10-10 19:18:42 -07:00
|
|
|
});
|
2011-03-28 14:29:03 -07:00
|
|
|
|
2012-07-26 20:47:22 -07:00
|
|
|
wardrobe.outfits.bind('updatePetType', updatePetType);
|
2011-03-28 14:29:03 -07:00
|
|
|
|
2012-07-26 20:47:22 -07:00
|
|
|
wardrobe.outfits.bind('petTypeNotFound', function () {
|
2010-10-10 19:18:42 -07:00
|
|
|
$('#pet-type-not-found').show('normal').delay(3000).hide('fast');
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2011-05-22 13:30:02 -07:00
|
|
|
View.PreviewAdapterForm = function (wardrobe) {
|
|
|
|
var preview = wardrobe.views.Preview;
|
|
|
|
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 () {
|
|
|
|
preview.toggleAdapter();
|
|
|
|
}
|
|
|
|
konami.load();
|
2011-06-27 12:33:34 -07:00
|
|
|
|
|
|
|
var modeWrapper = $('#preview-mode').addClass('flash-active');
|
|
|
|
var modeOptions = $('#preview-mode-toggle li');
|
|
|
|
function activate(el, modeOn, modeOff) {
|
|
|
|
modeWrapper.removeClass(modeOff + '-active').addClass(modeOn + '-active');
|
|
|
|
$(el).addClass('active');
|
|
|
|
}
|
|
|
|
|
2011-08-07 17:13:39 -07:00
|
|
|
var flashToggle = $('#preview-mode-flash').click(function () {
|
2011-06-27 12:33:34 -07:00
|
|
|
activate(this, 'flash', 'image');
|
|
|
|
preview.useSWFAdapter();
|
|
|
|
});
|
|
|
|
|
2011-08-07 17:13:39 -07:00
|
|
|
var imageToggle = $('#preview-mode-image').click(function () {
|
2011-06-27 12:33:34 -07:00
|
|
|
activate(this, 'image', 'flash');
|
|
|
|
preview.useImageAdapter();
|
|
|
|
});
|
|
|
|
|
2011-08-07 17:13:39 -07:00
|
|
|
if(preview.usingImageAdapter()) {
|
|
|
|
activate(imageToggle, 'image', 'flash');
|
|
|
|
}
|
2011-05-22 13:30:02 -07:00
|
|
|
}
|
|
|
|
|
2011-08-07 14:24:54 -07:00
|
|
|
View.ReportBrokenImage = function (wardrobe) {
|
|
|
|
var link = $('#report-broken-image');
|
|
|
|
var baseURL = link.attr('data-base-url');
|
|
|
|
|
|
|
|
function updateLink() {
|
2012-07-26 20:47:22 -07:00
|
|
|
var assets = wardrobe.outfits.getVisibleAssets();
|
2011-08-07 14:24:54 -07:00
|
|
|
var url = baseURL + "?";
|
|
|
|
|
|
|
|
for(var i = 0; i < assets.length; i++) {
|
|
|
|
if(i > 0) url += "&";
|
2011-08-07 15:23:44 -07:00
|
|
|
url += "asset_ids[" + assets[i].type + "][]=" + assets[i].id;
|
2011-08-07 14:24:54 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
link.attr('href', url);
|
|
|
|
}
|
|
|
|
|
2012-07-26 20:47:22 -07:00
|
|
|
wardrobe.outfits.bind('updateWornItems', updateLink);
|
|
|
|
wardrobe.outfits.bind('updateItemAssets', updateLink);
|
|
|
|
wardrobe.outfits.bind('updatePetState', updateLink);
|
2011-08-07 14:24:54 -07:00
|
|
|
}
|
|
|
|
|
2010-10-10 19:18:42 -07:00
|
|
|
View.Search = function (wardrobe) {
|
2014-04-02 11:54:27 -07:00
|
|
|
var form_selector = '#preview-search-basic', form = $(form_selector),
|
2010-10-10 19:18:42 -07:00
|
|
|
item_set = new Partial.ItemSet(wardrobe, form_selector + ' ul'),
|
|
|
|
input_el = form.find('input[name=query]'),
|
|
|
|
clear_el = $('#preview-search-form-clear'),
|
|
|
|
error_el = $('#preview-search-form-error'),
|
|
|
|
help_el = $('#preview-search-form-help'),
|
|
|
|
loading_el = $('#preview-search-form-loading'),
|
|
|
|
no_results_el = $('#preview-search-form-no-results'),
|
|
|
|
no_results_span = no_results_el.children('span'),
|
2011-07-22 14:06:21 -07:00
|
|
|
your_items_links = $('.preview-search-form-your-items'),
|
2014-04-02 11:54:27 -07:00
|
|
|
wrapper = $('#preview-search'),
|
2010-10-10 19:18:42 -07:00
|
|
|
PAGINATION = {
|
|
|
|
INNER_WINDOW: 4,
|
|
|
|
OUTER_WINDOW: 1,
|
|
|
|
EL_ID: '#preview-search-form-pagination',
|
2013-01-10 16:58:56 -08:00
|
|
|
PER_PAGE: 21,
|
|
|
|
TEMPLATE: $('#pagination-template')
|
2010-10-10 19:18:42 -07:00
|
|
|
}, object_width = 112, last_request;
|
2011-03-28 14:29:03 -07:00
|
|
|
|
2010-10-10 19:18:42 -07:00
|
|
|
PAGINATION.EL = $(PAGINATION.EL_ID);
|
2011-03-28 14:29:03 -07:00
|
|
|
|
2010-10-10 19:18:42 -07:00
|
|
|
$(PAGINATION.EL_ID + ' a').live('click', function (e) {
|
|
|
|
e.preventDefault();
|
|
|
|
loadPage($(this).data('page'));
|
|
|
|
});
|
2011-03-28 14:29:03 -07:00
|
|
|
|
2010-10-10 19:18:42 -07:00
|
|
|
this.initialize = $.proxy(wardrobe.item_zone_sets, 'load');
|
2011-03-28 14:29:03 -07:00
|
|
|
|
2010-10-10 19:18:42 -07:00
|
|
|
wardrobe.search.setPerPage(PAGINATION.PER_PAGE);
|
2011-03-28 14:29:03 -07:00
|
|
|
|
2010-10-10 19:18:42 -07:00
|
|
|
function updatePerPage() {
|
|
|
|
var new_per_page = Math.floor(form.width() / object_width),
|
|
|
|
offset, new_page;
|
2011-02-06 15:55:04 -08:00
|
|
|
if(!$(document.body).hasClass('fullscreen')) new_per_page *= 4;
|
2010-10-10 19:18:42 -07:00
|
|
|
if(new_per_page != PAGINATION.PER_PAGE) {
|
|
|
|
PAGINATION.PER_PAGE = new_per_page;
|
|
|
|
wardrobe.search.setPerPage(PAGINATION.PER_PAGE);
|
|
|
|
if(last_request) {
|
|
|
|
loadOffset(last_request.offset);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
$(window).resize(updatePerPage).load(updatePerPage);
|
|
|
|
updatePerPage();
|
2011-03-28 14:29:03 -07:00
|
|
|
|
2010-10-10 19:18:42 -07:00
|
|
|
function loadOffset(offset) {
|
|
|
|
wardrobe.search.setItemsByQuery(input_el.val(), {offset: offset});
|
|
|
|
}
|
2011-03-28 14:29:03 -07:00
|
|
|
|
2010-10-10 19:18:42 -07:00
|
|
|
function loadPage(page) {
|
|
|
|
wardrobe.search.setItemsByQuery(input_el.val(), {page: page});
|
|
|
|
}
|
2011-03-28 14:29:03 -07:00
|
|
|
|
2010-10-10 19:18:42 -07:00
|
|
|
function stopLoading() {
|
|
|
|
loading_el.stop(true, true).hide();
|
|
|
|
}
|
2011-03-28 14:29:03 -07:00
|
|
|
|
2010-10-10 19:18:42 -07:00
|
|
|
form.submit(function (e) {
|
|
|
|
e.preventDefault();
|
|
|
|
loadPage(1);
|
|
|
|
});
|
2011-03-28 14:29:03 -07:00
|
|
|
|
2010-10-10 19:18:42 -07:00
|
|
|
clear_el.click(function (e) {
|
|
|
|
e.preventDefault();
|
|
|
|
input_el.val('');
|
|
|
|
form.submit();
|
|
|
|
});
|
2011-03-28 14:29:03 -07:00
|
|
|
|
2011-07-22 14:06:21 -07:00
|
|
|
your_items_links.click(function (e) {
|
2011-07-17 14:52:40 -07:00
|
|
|
e.preventDefault();
|
2011-07-22 14:06:21 -07:00
|
|
|
input_el.val('user:' + this.getAttribute('data-search-value'));
|
2011-07-17 14:52:40 -07:00
|
|
|
form.submit();
|
|
|
|
});
|
|
|
|
|
2010-10-10 19:18:42 -07:00
|
|
|
wardrobe.search.bind('startRequest', function () {
|
|
|
|
loading_el.delay(1000).show('slow');
|
|
|
|
});
|
2011-03-28 14:29:03 -07:00
|
|
|
|
2010-10-10 19:18:42 -07:00
|
|
|
wardrobe.search.bind('updateItems', function (items) {
|
|
|
|
var fit = $('#preview').data('fit') || $.noop;
|
|
|
|
stopLoading();
|
|
|
|
item_set.setItems(items);
|
|
|
|
if(wardrobe.search.request.query) {
|
|
|
|
if(!items.length) {
|
|
|
|
no_results_el.show();
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
help_el.show();
|
|
|
|
}
|
|
|
|
form.toggleClass('has-results', items.length > 0);
|
|
|
|
fit();
|
|
|
|
});
|
2011-03-28 14:29:03 -07:00
|
|
|
|
2010-10-10 19:18:42 -07:00
|
|
|
wardrobe.search.bind('updateRequest', function (request) {
|
|
|
|
last_request = request;
|
|
|
|
error_el.hide('fast');
|
|
|
|
help_el.hide();
|
|
|
|
no_results_el.hide();
|
|
|
|
input_el.val(request.query || '');
|
|
|
|
no_results_span.text(request.query);
|
|
|
|
clear_el.toggle(!!request.query);
|
|
|
|
});
|
2011-03-28 14:29:03 -07:00
|
|
|
|
2010-10-10 19:18:42 -07:00
|
|
|
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;
|
2011-03-28 14:29:03 -07:00
|
|
|
|
2010-10-10 19:18:42 -07:00
|
|
|
if(window_to > total_pages) {
|
|
|
|
window_from -= window_to - total_pages;
|
|
|
|
window_to = total_pages;
|
|
|
|
}
|
2011-03-28 14:29:03 -07:00
|
|
|
|
2010-10-10 19:18:42 -07:00
|
|
|
if(window_from < 1) {
|
|
|
|
window_to += 1 - window_from;
|
|
|
|
window_from = 1;
|
|
|
|
if(window_to > total_pages) window_to = total_pages;
|
|
|
|
}
|
2011-03-28 14:29:03 -07:00
|
|
|
|
2010-10-10 19:18:42 -07:00
|
|
|
left_gap = [2 + PAGINATION.OUTER_WINDOW, window_from];
|
|
|
|
right_gap = [window_to + 1, total_pages - PAGINATION.OUTER_WINDOW];
|
2011-03-28 14:29:03 -07:00
|
|
|
|
2010-10-10 19:18:42 -07:00
|
|
|
subtract_left = (left_gap[1] - left_gap[0]) > 1;
|
|
|
|
subtract_right = (right_gap[1] - right_gap[0]) > 1;
|
2013-01-10 16:58:56 -08:00
|
|
|
|
|
|
|
var pages = [];
|
2011-03-28 14:29:03 -07:00
|
|
|
|
2010-10-10 19:18:42 -07:00
|
|
|
while(i <= total_pages) {
|
|
|
|
if(subtract_left && i >= left_gap[0] && i < left_gap[1]) {
|
2013-01-10 16:58:56 -08:00
|
|
|
pages.push('gap');
|
2010-10-10 19:18:42 -07:00
|
|
|
i = left_gap[1];
|
|
|
|
} else if(subtract_right && i >= right_gap[0] && i < right_gap[1]) {
|
2013-01-10 16:58:56 -08:00
|
|
|
pages.push('gap');
|
2010-10-10 19:18:42 -07:00
|
|
|
i = right_gap[1];
|
|
|
|
} else {
|
2013-01-10 16:58:56 -08:00
|
|
|
pages.push(i);
|
2010-10-10 19:18:42 -07:00
|
|
|
i++;
|
|
|
|
}
|
|
|
|
}
|
2013-01-10 16:58:56 -08:00
|
|
|
|
|
|
|
PAGINATION.EL.empty();
|
|
|
|
PAGINATION.TEMPLATE.tmpl({
|
|
|
|
current_page: current_page,
|
|
|
|
total_pages: total_pages,
|
|
|
|
pages: pages
|
|
|
|
}).appendTo(PAGINATION.EL);
|
2010-10-10 19:18:42 -07:00
|
|
|
});
|
2011-03-28 14:29:03 -07:00
|
|
|
|
2010-10-10 19:18:42 -07:00
|
|
|
wardrobe.search.bind('error', function (error) {
|
|
|
|
stopLoading();
|
|
|
|
error_el.text(error).show('normal');
|
|
|
|
});
|
2014-04-02 11:54:27 -07:00
|
|
|
|
|
|
|
$('#preview-search-advanced-link, #preview-search-basic-link').click(function() {
|
|
|
|
var fit = $('#preview').data('fit') || $.noop;
|
|
|
|
wrapper.toggleClass('advanced');
|
|
|
|
fit();
|
|
|
|
});
|
2010-10-10 19:18:42 -07:00
|
|
|
}
|
|
|
|
|
2014-03-30 20:37:33 -07:00
|
|
|
View.PrankColorMessage = function(wardrobe) {
|
|
|
|
var el = $('#prank-color-message');
|
|
|
|
var nameEls = el.find('.prank-color-message-name');
|
2014-03-31 19:05:28 -07:00
|
|
|
var artistEls = el.find('.prank-color-message-artist');
|
2014-03-30 20:37:33 -07:00
|
|
|
var colorsById = null;
|
|
|
|
var petType = null;
|
2014-03-31 19:05:28 -07:00
|
|
|
var petState = null;
|
2014-03-30 20:37:33 -07:00
|
|
|
|
|
|
|
function updateMessage() {
|
2014-03-31 19:05:28 -07:00
|
|
|
if (colorsById !== null && petType !== null && petState !== null) {
|
2014-03-30 20:37:33 -07:00
|
|
|
var color = colorsById[petType.color_id];
|
|
|
|
if (color.prank) {
|
|
|
|
nameEls.text(color.unfunny_name);
|
2014-03-31 19:05:28 -07:00
|
|
|
artistEls.text(petState.artistName);
|
|
|
|
if (petState.artistUrl === null) {
|
|
|
|
artistEls.removeAttr('href');
|
|
|
|
} else {
|
|
|
|
artistEls.attr('href', petState.artistUrl);
|
|
|
|
}
|
2014-03-30 20:37:33 -07:00
|
|
|
el.show();
|
|
|
|
} else {
|
|
|
|
el.hide();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
wardrobe.pet_attributes.bind('update', function(attributes) {
|
|
|
|
colorsById = {};
|
|
|
|
attributes.color.forEach(function(color) {
|
|
|
|
colorsById[color.id] = color;
|
|
|
|
});
|
|
|
|
updateMessage();
|
|
|
|
});
|
|
|
|
|
|
|
|
wardrobe.outfits.bind('updatePetType', function(newPetType) {
|
|
|
|
petType = newPetType;
|
|
|
|
updateMessage();
|
|
|
|
});
|
2014-03-31 19:05:28 -07:00
|
|
|
|
|
|
|
wardrobe.outfits.bind('updatePetState', function(newPetState) {
|
|
|
|
petState = newPetState;
|
|
|
|
updateMessage();
|
|
|
|
});
|
2014-03-30 20:37:33 -07:00
|
|
|
}
|
|
|
|
|
2013-01-04 18:08:41 -08:00
|
|
|
var userbar_sessions_link = $('#userbar a:last');
|
|
|
|
var userbar_message_el = $('#userbar-session-message').prependTo('#userbar');
|
2010-11-10 13:59:54 -08:00
|
|
|
|
|
|
|
userbar_sessions_link.hover(function () {
|
|
|
|
userbar_message_el.stop().fadeTo('normal', .5);
|
|
|
|
}, function () {
|
|
|
|
userbar_message_el.stop().fadeOut('fast');
|
|
|
|
});
|
|
|
|
|
2013-01-26 10:02:06 -08:00
|
|
|
var localeForm = $('#locale-form');
|
|
|
|
localeForm.submit(function (e) {
|
|
|
|
var fullPath = document.location.pathname + document.location.search +
|
|
|
|
document.location.hash;
|
|
|
|
localeForm.find('input[name=return_to]').val(fullPath);
|
|
|
|
});
|
|
|
|
|
2010-10-10 19:18:42 -07:00
|
|
|
$.ajaxSetup({
|
|
|
|
error: function (xhr) {
|
|
|
|
$.jGrowl("There was an error loading that last resource. Oops. Please try again!");
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
main_wardrobe = new Wardrobe();
|
|
|
|
main_wardrobe.registerViews(View);
|
|
|
|
main_wardrobe.initialize();
|
2011-03-28 14:29:03 -07:00
|
|
|
|
2011-07-05 08:19:49 -07:00
|
|
|
var TIME_TO_DONATION_REQUEST_IN_MINUTES = 10;
|
|
|
|
var donationRequestEl = $('#preview-sidebar-donation-request');
|
|
|
|
|
|
|
|
donationRequestEl.find('a').click(function(e) {
|
|
|
|
donationRequestEl.slideUp(250);
|
|
|
|
var response = this.id == 'preview-sidebar-donation-request-no-thanks' ? 0 : 1;
|
|
|
|
if(!response) { // href is #
|
|
|
|
e.preventDefault();
|
|
|
|
}
|
|
|
|
var expiryDate = new Date();
|
|
|
|
expiryDate.setTime(expiryDate.getTime() + 7*24*60*60*1000); // one week from now
|
|
|
|
document.cookie = "previewSidebarDonationResponse=" + response + "; expires=" + expiryDate.toGMTString();
|
|
|
|
});
|
|
|
|
|
|
|
|
if(document.cookie.indexOf('previewSidebarDonationResponse') == -1) {
|
|
|
|
setTimeout(function () {
|
|
|
|
donationRequestEl.slideDown(1000);
|
|
|
|
}, TIME_TO_DONATION_REQUEST_IN_MINUTES * 60 * 1000);
|
|
|
|
}
|
|
|
|
|