2011-07-15 19:52:53 -07:00
|
|
|
(function () {
|
2011-07-30 10:40:41 -07:00
|
|
|
var hangersInitCallbacks = [];
|
|
|
|
|
|
|
|
function onHangersInit(callback) {
|
|
|
|
hangersInitCallbacks[hangersInitCallbacks.length] = callback;
|
|
|
|
}
|
|
|
|
|
|
|
|
function hangersInit() {
|
|
|
|
for(var i = 0; i < hangersInitCallbacks.length; i++) {
|
|
|
|
hangersInitCallbacks[i]();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-07-25 11:06:07 -07:00
|
|
|
/*
|
|
|
|
|
|
|
|
Hanger groups
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
var hangerGroups = [];
|
|
|
|
|
|
|
|
$('div.closet-hangers-group').each(function () {
|
|
|
|
var el = $(this);
|
2011-07-29 08:25:17 -07:00
|
|
|
var lists = [];
|
|
|
|
|
|
|
|
el.find('div.closet-list').each(function () {
|
|
|
|
var el = $(this);
|
|
|
|
var id = el.attr('data-id');
|
|
|
|
if(id) {
|
|
|
|
lists[lists.length] = {
|
|
|
|
id: parseInt(id, 10),
|
|
|
|
label: el.find('h4').text()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2011-07-25 11:06:07 -07:00
|
|
|
hangerGroups[hangerGroups.length] = {
|
2011-07-29 08:25:17 -07:00
|
|
|
label: el.find('h3').text(),
|
|
|
|
lists: lists,
|
2011-07-25 11:06:07 -07:00
|
|
|
owned: (el.attr('data-owned') == 'true')
|
|
|
|
};
|
2011-07-29 07:52:04 -07:00
|
|
|
});
|
|
|
|
|
|
|
|
$('div.closet-hangers-group span.toggle').live('click', function () {
|
|
|
|
$(this).closest('.closet-hangers-group').toggleClass('hidden');
|
2011-07-25 11:06:07 -07:00
|
|
|
});
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
|
|
|
Hanger forms
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
2011-07-30 10:40:41 -07:00
|
|
|
$.fn.liveDraggable = function (opts) {
|
|
|
|
this.live("mouseover", function() {
|
|
|
|
if (!$(this).data("init")) {
|
|
|
|
$(this).data("init", true).draggable(opts);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
2011-07-22 11:02:04 -07:00
|
|
|
var body = $(document.body).addClass("js");
|
|
|
|
if(!body.hasClass("current-user")) return false;
|
|
|
|
|
|
|
|
var hangersElQuery = '#closet-hangers';
|
2011-07-15 22:09:04 -07:00
|
|
|
var hangersEl = $(hangersElQuery);
|
2011-07-15 19:52:53 -07:00
|
|
|
|
2011-07-15 20:39:19 -07:00
|
|
|
$.fn.disableForms = function () {
|
|
|
|
return this.data("formsDisabled", true).find("input").attr("disabled", "disabled").end();
|
|
|
|
}
|
|
|
|
|
|
|
|
$.fn.enableForms = function () {
|
|
|
|
return this.data("formsDisabled", false).find("input").removeAttr("disabled").end();
|
|
|
|
}
|
|
|
|
|
2011-07-15 19:52:53 -07:00
|
|
|
$.fn.hasChanged = function () {
|
2011-07-30 10:40:41 -07:00
|
|
|
return this.attr('data-previous-value') != this.val();
|
2011-07-15 19:52:53 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
$.fn.revertValue = function () {
|
2011-07-15 22:09:04 -07:00
|
|
|
return this.each(function () {
|
2011-07-15 19:52:53 -07:00
|
|
|
var el = $(this);
|
2011-07-30 10:40:41 -07:00
|
|
|
el.val(el.attr('data-previous-value'));
|
2011-07-15 19:52:53 -07:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
$.fn.storeValue = function () {
|
2011-07-15 22:09:04 -07:00
|
|
|
return this.each(function () {
|
2011-07-15 19:52:53 -07:00
|
|
|
var el = $(this);
|
2011-07-30 10:40:41 -07:00
|
|
|
el.attr('data-previous-value', el.val());
|
2011-07-15 19:52:53 -07:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2011-07-30 10:40:41 -07:00
|
|
|
$.fn.insertIntoSortedList = function (list, compare) {
|
|
|
|
var newChild = this, inserted = false;
|
|
|
|
list.children().each(function () {
|
|
|
|
if(compare(newChild, $(this)) < 1) {
|
|
|
|
newChild.insertBefore(this);
|
|
|
|
inserted = true;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
if(!inserted) newChild.appendTo(list);
|
|
|
|
return this;
|
|
|
|
}
|
|
|
|
|
2011-07-22 11:02:04 -07:00
|
|
|
function handleSaveError(xhr, action) {
|
2011-07-15 22:09:04 -07:00
|
|
|
try {
|
|
|
|
var data = $.parseJSON(xhr.responseText);
|
|
|
|
} catch(e) {
|
|
|
|
var data = {};
|
|
|
|
}
|
|
|
|
|
|
|
|
if(typeof data.errors != 'undefined') {
|
|
|
|
$.jGrowl("Error " + action + ": " + data.errors.join(", "));
|
|
|
|
} else {
|
|
|
|
$.jGrowl("We had trouble " + action + " just now. Try again?");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function objectRemoved(objectWrapper) {
|
2011-07-30 20:05:55 -07:00
|
|
|
objectWrapper.hide(250, $.proxy(objectWrapper, 'remove'));
|
2011-07-15 22:09:04 -07:00
|
|
|
}
|
|
|
|
|
2011-07-30 10:40:41 -07:00
|
|
|
function compareItemsByName(a, b) {
|
|
|
|
return a.find('span.name').text().localeCompare(b.find('span.name').text());
|
|
|
|
}
|
|
|
|
|
2011-07-30 16:47:04 -07:00
|
|
|
function findList(id, item) {
|
|
|
|
if(id) {
|
|
|
|
return $('#closet-list-' + id);
|
2011-07-30 10:40:41 -07:00
|
|
|
} else {
|
2011-07-30 16:47:04 -07:00
|
|
|
return item.closest('.closet-hangers-group').find('div.closet-list.unlisted');
|
2011-07-30 10:40:41 -07:00
|
|
|
}
|
2011-07-30 16:47:04 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
function updateListHangersCount(el) {
|
|
|
|
el.attr('data-hangers-count', el.find('div.object').length);
|
|
|
|
}
|
|
|
|
|
|
|
|
function moveItemToList(item, listId) {
|
|
|
|
var newList = findList(listId, item);
|
|
|
|
var oldList = item.closest('div.closet-list');
|
|
|
|
var hangersWrapper = newList.find('div.closet-list-hangers');
|
2011-07-30 10:40:41 -07:00
|
|
|
item.insertIntoSortedList(hangersWrapper, compareItemsByName);
|
2011-07-30 16:47:04 -07:00
|
|
|
updateListHangersCount(oldList);
|
|
|
|
updateListHangersCount(newList);
|
2011-07-30 10:40:41 -07:00
|
|
|
}
|
|
|
|
|
2011-07-15 20:39:19 -07:00
|
|
|
function submitUpdateForm(form) {
|
2011-07-15 19:52:53 -07:00
|
|
|
if(form.data('loading')) return false;
|
2011-07-30 10:40:41 -07:00
|
|
|
var quantityEl = form.children("input[name=closet_hanger\[quantity\]]");
|
|
|
|
var listEl = form.children("input[name=closet_hanger\[list_id\]]");
|
|
|
|
var listChanged = listEl.hasChanged();
|
|
|
|
if(listChanged || quantityEl.hasChanged()) {
|
2011-07-15 19:52:53 -07:00
|
|
|
var objectWrapper = form.closest(".object").addClass("loading");
|
2011-07-30 10:40:41 -07:00
|
|
|
var newQuantity = quantityEl.val();
|
|
|
|
var quantitySpan = objectWrapper.find(".quantity span").text(newQuantity);
|
2011-07-30 20:03:43 -07:00
|
|
|
objectWrapper.attr('data-quantity', newQuantity);
|
2011-07-15 20:39:19 -07:00
|
|
|
var data = form.serialize(); // get data before disabling inputs
|
|
|
|
objectWrapper.disableForms();
|
2011-07-15 19:52:53 -07:00
|
|
|
form.data('loading', true);
|
2011-07-30 10:40:41 -07:00
|
|
|
if(listChanged) moveItemToList(objectWrapper, listEl.val());
|
2011-07-15 19:52:53 -07:00
|
|
|
$.ajax({
|
|
|
|
url: form.attr("action") + ".json",
|
|
|
|
type: "post",
|
2011-07-15 20:39:19 -07:00
|
|
|
data: data,
|
2011-07-15 19:52:53 -07:00
|
|
|
dataType: "json",
|
|
|
|
complete: function (data) {
|
2011-07-30 10:40:41 -07:00
|
|
|
if(quantityEl.val() == 0) {
|
2011-07-15 22:09:04 -07:00
|
|
|
objectRemoved(objectWrapper);
|
|
|
|
} else {
|
|
|
|
objectWrapper.removeClass("loading").enableForms();
|
|
|
|
}
|
2011-07-15 19:52:53 -07:00
|
|
|
form.data('loading', false);
|
|
|
|
},
|
|
|
|
success: function () {
|
2011-07-30 10:40:41 -07:00
|
|
|
quantityEl.storeValue();
|
|
|
|
listEl.storeValue();
|
2011-07-15 19:52:53 -07:00
|
|
|
},
|
|
|
|
error: function (xhr) {
|
2011-07-30 10:40:41 -07:00
|
|
|
quantityEl.revertValue();
|
|
|
|
listEl.revertValue();
|
|
|
|
if(listChanged) moveItemToList(objectWrapper, listEl.val());
|
|
|
|
quantitySpan.text(quantityEl.val());
|
2011-07-15 22:09:04 -07:00
|
|
|
|
2011-07-22 11:02:04 -07:00
|
|
|
handleSaveError(xhr, "updating the quantity");
|
2011-07-15 19:52:53 -07:00
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-07-15 22:09:04 -07:00
|
|
|
$(hangersElQuery + ' form.closet-hanger-update').live('submit', function (e) {
|
2011-07-15 19:52:53 -07:00
|
|
|
e.preventDefault();
|
2011-07-15 20:39:19 -07:00
|
|
|
submitUpdateForm($(this));
|
2011-07-15 19:52:53 -07:00
|
|
|
});
|
|
|
|
|
2011-07-30 10:40:41 -07:00
|
|
|
function editableInputs() { return $(hangersElQuery).find('input[name=closet_hanger\[quantity\]], input[name=closet_hanger\[list_id\]]') }
|
2011-07-15 22:09:04 -07:00
|
|
|
|
2011-07-30 10:40:41 -07:00
|
|
|
$(hangersElQuery + 'input[name=closet_hanger\[quantity\]]').live('change', function () {
|
2011-07-15 20:39:19 -07:00
|
|
|
submitUpdateForm($(this).parent());
|
2011-07-15 19:52:53 -07:00
|
|
|
}).storeValue();
|
|
|
|
|
2011-07-30 10:40:41 -07:00
|
|
|
onHangersInit(function () {
|
|
|
|
editableInputs().storeValue();
|
|
|
|
});
|
|
|
|
|
2011-07-15 22:09:04 -07:00
|
|
|
$(hangersElQuery + ' div.object').live('mouseleave', function () {
|
2011-07-15 20:39:19 -07:00
|
|
|
submitUpdateForm($(this).find('form.closet-hanger-update'));
|
2011-07-30 10:40:41 -07:00
|
|
|
}).liveDraggable({
|
|
|
|
appendTo: '#closet-hangers',
|
|
|
|
distance: 20,
|
|
|
|
helper: "clone",
|
|
|
|
revert: "invalid"
|
2011-07-15 20:39:19 -07:00
|
|
|
});
|
|
|
|
|
2011-07-15 22:09:04 -07:00
|
|
|
$(hangersElQuery + " form.closet-hanger-destroy").live("submit", function (e) {
|
2011-07-15 20:39:19 -07:00
|
|
|
e.preventDefault();
|
|
|
|
var form = $(this);
|
2011-07-22 14:55:05 -07:00
|
|
|
var button = form.children("input[type=submit]").val("Removing…");
|
2011-07-15 20:39:19 -07:00
|
|
|
var objectWrapper = form.closest(".object").addClass("loading");
|
|
|
|
var data = form.serialize(); // get data before disabling inputs
|
|
|
|
objectWrapper.addClass("loading").disableForms();
|
|
|
|
$.ajax({
|
|
|
|
url: form.attr("action") + ".json",
|
|
|
|
type: "post",
|
|
|
|
data: data,
|
|
|
|
dataType: "json",
|
|
|
|
complete: function () {
|
|
|
|
button.val("Remove");
|
|
|
|
},
|
|
|
|
success: function () {
|
2011-07-15 22:09:04 -07:00
|
|
|
objectRemoved(objectWrapper);
|
2011-07-15 20:39:19 -07:00
|
|
|
},
|
|
|
|
error: function () {
|
|
|
|
objectWrapper.removeClass("loading").enableForms();
|
|
|
|
$.jGrowl("Error removing item. Try again?");
|
|
|
|
}
|
|
|
|
});
|
2011-07-15 19:52:53 -07:00
|
|
|
});
|
2011-07-15 22:09:04 -07:00
|
|
|
|
2011-07-25 11:06:07 -07:00
|
|
|
/*
|
|
|
|
|
|
|
|
Search, autocomplete
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
2011-07-15 22:09:04 -07:00
|
|
|
$('input, textarea').placeholder();
|
|
|
|
|
|
|
|
var itemsSearchForm = $("#closet-hangers-items-search[data-current-user-id]");
|
2011-07-25 11:06:07 -07:00
|
|
|
var itemsSearchField = itemsSearchForm.children("input[name=q]");
|
2011-07-15 22:09:04 -07:00
|
|
|
|
|
|
|
itemsSearchField.autocomplete({
|
|
|
|
select: function (e, ui) {
|
2011-07-25 11:06:07 -07:00
|
|
|
if(ui.item.is_item) {
|
|
|
|
// Let the autocompleter finish up this search before starting a new one
|
|
|
|
setTimeout(function () { itemsSearchField.autocomplete("search", ui.item) }, 0);
|
|
|
|
} else {
|
|
|
|
var item = ui.item.item;
|
|
|
|
var group = ui.item.group;
|
2011-07-15 22:09:04 -07:00
|
|
|
|
2011-07-25 11:06:07 -07:00
|
|
|
itemsSearchField.addClass("loading");
|
|
|
|
|
|
|
|
var closetHanger = {
|
2011-07-29 08:25:17 -07:00
|
|
|
owned: group.owned,
|
|
|
|
list_id: ui.item.list ? ui.item.list.id : ''
|
2011-07-25 11:06:07 -07:00
|
|
|
};
|
|
|
|
|
2011-07-29 20:26:48 -07:00
|
|
|
if(!item.hangerInGroup) closetHanger.quantity = 1;
|
|
|
|
|
2011-07-25 11:06:07 -07:00
|
|
|
$.ajax({
|
|
|
|
url: "/user/" + itemsSearchForm.data("current-user-id") + "/items/" + item.id + "/closet_hanger",
|
|
|
|
type: "post",
|
|
|
|
data: {closet_hanger: closetHanger, return_to: window.location.pathname + window.location.search},
|
|
|
|
complete: function () {
|
|
|
|
itemsSearchField.removeClass("loading");
|
|
|
|
},
|
|
|
|
success: function (html) {
|
|
|
|
var doc = $(html);
|
|
|
|
hangersEl.html( doc.find('#closet-hangers').html() );
|
2011-07-30 10:40:41 -07:00
|
|
|
hangersInit();
|
2011-07-25 11:06:07 -07:00
|
|
|
doc.find('.flash').hide().insertBefore(hangersEl).show(500).delay(5000).hide(250);
|
|
|
|
itemsSearchField.val("");
|
|
|
|
},
|
|
|
|
error: function (xhr) {
|
|
|
|
handleSaveError(xhr, "adding the item");
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
2011-07-15 22:09:04 -07:00
|
|
|
},
|
|
|
|
source: function (input, callback) {
|
2011-07-25 11:06:07 -07:00
|
|
|
if(typeof input.term == 'string') { // user-typed query
|
|
|
|
$.getJSON("/items.json?q=" + input.term, function (data) {
|
|
|
|
var output = [];
|
|
|
|
var items = data.items;
|
|
|
|
for(var i in items) {
|
|
|
|
items[i].label = items[i].name;
|
|
|
|
items[i].is_item = true;
|
|
|
|
output[output.length] = items[i];
|
|
|
|
}
|
|
|
|
callback(output);
|
|
|
|
});
|
|
|
|
} else { // item was chosen, now choose a group to insert
|
2011-07-29 08:25:17 -07:00
|
|
|
var groupInserts = [], group;
|
2011-07-29 20:26:48 -07:00
|
|
|
var item = input.term, itemEl, hangerInGroup, currentListId;
|
2011-07-25 11:06:07 -07:00
|
|
|
for(var i in hangerGroups) {
|
2011-07-29 08:25:17 -07:00
|
|
|
group = hangerGroups[i];
|
2011-07-29 20:26:48 -07:00
|
|
|
itemEl = $('div.closet-hangers-group[data-owned=' + group.owned + '] div.object[data-item-id=' + item.id + ']');
|
|
|
|
hangerInGroup = itemEl.length > 0;
|
|
|
|
currentListId = itemEl.closest('.closet-list').attr('data-id');
|
2011-07-29 08:25:17 -07:00
|
|
|
|
2011-07-25 11:06:07 -07:00
|
|
|
groupInserts[groupInserts.length] = {
|
2011-07-29 08:25:17 -07:00
|
|
|
group: group,
|
2011-07-29 20:26:48 -07:00
|
|
|
item: item,
|
|
|
|
label: item.label,
|
|
|
|
hangerInGroup: hangerInGroup,
|
|
|
|
hangerInList: !!currentListId
|
2011-07-25 11:06:07 -07:00
|
|
|
}
|
2011-07-29 08:25:17 -07:00
|
|
|
|
|
|
|
for(var i = 0; i < group.lists.length; i++) {
|
|
|
|
groupInserts[groupInserts.length] = {
|
|
|
|
group: group,
|
2011-07-29 20:26:48 -07:00
|
|
|
item: item,
|
|
|
|
label: item.label,
|
|
|
|
list: group.lists[i],
|
|
|
|
hangerInGroup: hangerInGroup,
|
|
|
|
currentListId: currentListId
|
2011-07-29 08:25:17 -07:00
|
|
|
}
|
|
|
|
}
|
2011-07-15 22:09:04 -07:00
|
|
|
}
|
2011-07-25 11:06:07 -07:00
|
|
|
callback(groupInserts);
|
|
|
|
}
|
2011-07-15 22:09:04 -07:00
|
|
|
}
|
2011-07-25 11:06:07 -07:00
|
|
|
});
|
|
|
|
|
|
|
|
var autocompleter = itemsSearchField.data("autocomplete");
|
|
|
|
|
|
|
|
autocompleter._renderItem = function( ul, item ) {
|
|
|
|
var li = $("<li></li>").data("item.autocomplete", item);
|
|
|
|
if(item.is_item) { // these are items from the server
|
|
|
|
li.append("<a>Add <strong>" + item.label + "</strong>");
|
2011-07-29 08:25:17 -07:00
|
|
|
} else if(item.list) { // these are list inserts
|
2011-07-29 20:26:48 -07:00
|
|
|
if(item.hangerInGroup) {
|
|
|
|
if(item.currentListId == item.list.id) {
|
|
|
|
li.append("<span>It's in <strong>" + item.list.label + "</strong> now");
|
|
|
|
} else {
|
|
|
|
li.append("<a>Move to <strong>" + item.list.label + "</strong>");
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
li.append("<a>Add to <strong>" + item.list.label + "</strong>");
|
|
|
|
}
|
|
|
|
li.addClass("closet-list-autocomplete-item");
|
2011-07-25 11:06:07 -07:00
|
|
|
} else { // these are group inserts
|
2011-07-29 20:26:48 -07:00
|
|
|
if(item.hangerInGroup) {
|
|
|
|
var groupName = item.group.label;
|
|
|
|
if(item.hangerInList) {
|
|
|
|
li.append("<a>Move to <strong>" + groupName.replace(/\s+$/, '') + "</strong>, no list");
|
|
|
|
} else {
|
|
|
|
li.append("<span>It's in <strong>" + groupName + "</strong> now");
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
li.append("<a>Add to <strong>" + item.group.label + "</strong>");
|
|
|
|
}
|
|
|
|
li.addClass('closet-hangers-group-autocomplete-item');
|
2011-07-25 11:06:07 -07:00
|
|
|
}
|
|
|
|
return li.appendTo(ul);
|
2011-07-15 22:09:04 -07:00
|
|
|
}
|
2011-07-22 11:02:04 -07:00
|
|
|
|
2011-07-25 11:06:07 -07:00
|
|
|
/*
|
|
|
|
|
|
|
|
Contact Neopets username form
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
2011-07-22 11:02:04 -07:00
|
|
|
var contactEl = $('#closet-hangers-contact');
|
2011-07-26 15:41:15 -07:00
|
|
|
var editContactLink = $('.edit-contact-link');
|
2011-07-22 11:02:04 -07:00
|
|
|
var contactForm = contactEl.children('form');
|
|
|
|
var cancelContactLink = $('#cancel-contact-link');
|
|
|
|
var contactFormUsername = contactForm.children('input[type=text]');
|
|
|
|
var editContactLinkUsername = $('#contact-link-has-value span');
|
|
|
|
|
|
|
|
function closeContactForm() {
|
|
|
|
contactEl.removeClass('editing');
|
|
|
|
}
|
|
|
|
|
|
|
|
editContactLink.click(function () {
|
|
|
|
contactEl.addClass('editing');
|
|
|
|
contactFormUsername.focus();
|
|
|
|
});
|
|
|
|
|
|
|
|
cancelContactLink.click(closeContactForm);
|
|
|
|
|
|
|
|
contactForm.submit(function (e) {
|
|
|
|
var data = contactForm.serialize();
|
|
|
|
contactForm.disableForms();
|
|
|
|
$.ajax({
|
|
|
|
url: contactForm.attr('action') + '.json',
|
|
|
|
type: 'post',
|
|
|
|
data: data,
|
|
|
|
dataType: 'json',
|
|
|
|
complete: function () {
|
|
|
|
contactForm.enableForms();
|
|
|
|
},
|
|
|
|
success: function () {
|
|
|
|
var newName = contactFormUsername.val();
|
|
|
|
if(newName.length > 0) {
|
|
|
|
editContactLink.addClass('has-value');
|
|
|
|
editContactLinkUsername.text(newName);
|
|
|
|
} else {
|
|
|
|
editContactLink.removeClass('has-value');
|
|
|
|
}
|
|
|
|
closeContactForm();
|
|
|
|
},
|
|
|
|
error: function (xhr) {
|
|
|
|
handleSaveError(xhr, 'saving Neopets username');
|
|
|
|
}
|
|
|
|
});
|
|
|
|
e.preventDefault();
|
|
|
|
});
|
2011-07-29 07:52:04 -07:00
|
|
|
|
|
|
|
/*
|
|
|
|
|
|
|
|
Hanger list controls
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
$('input[type=submit][data-confirm]').live('click', function (e) {
|
|
|
|
if(!confirm(this.getAttribute('data-confirm'))) e.preventDefault();
|
|
|
|
});
|
2011-07-30 10:40:41 -07:00
|
|
|
|
|
|
|
/*
|
2011-07-30 19:08:38 -07:00
|
|
|
|
2011-07-30 10:40:41 -07:00
|
|
|
Closet list droppable
|
2011-07-30 19:08:38 -07:00
|
|
|
|
2011-07-30 10:40:41 -07:00
|
|
|
*/
|
|
|
|
|
|
|
|
onHangersInit(function () {
|
|
|
|
$('.closet-hangers-group').each(function () {
|
|
|
|
var group = $(this);
|
|
|
|
group.find('div.closet-list').droppable({
|
|
|
|
accept: '#' + group.attr('id') + ' div.object',
|
|
|
|
activate: function () {
|
2011-07-30 16:47:04 -07:00
|
|
|
$(this).find('.closet-list-content').animate({opacity: 0, height: 100}, 250);
|
2011-07-30 10:40:41 -07:00
|
|
|
},
|
|
|
|
activeClass: 'droppable-active',
|
|
|
|
deactivate: function () {
|
2011-07-30 16:47:04 -07:00
|
|
|
$(this).find('.closet-list-content').css('height', 'auto').animate({opacity: 1}, 250);
|
2011-07-30 10:40:41 -07:00
|
|
|
},
|
|
|
|
drop: function (e, ui) {
|
|
|
|
var form = ui.draggable.find('form.closet-hanger-update');
|
|
|
|
form.find('input[name=closet_hanger\[list_id\]]').val(this.getAttribute('data-id'));
|
|
|
|
submitUpdateForm(form);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
/*
|
2011-07-30 19:08:38 -07:00
|
|
|
|
|
|
|
Visibility Descriptions
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
function updateVisibilityDescription() {
|
|
|
|
var descriptions = $(this).closest('.visibility-form').
|
|
|
|
find('ul.visibility-descriptions');
|
|
|
|
|
|
|
|
descriptions.children('li.current').removeClass('current');
|
|
|
|
descriptions.children('li[data-id=' + $(this).val() + ']').addClass('current');
|
|
|
|
}
|
|
|
|
|
|
|
|
function visibilitySelects() { return $('form.visibility-form select') }
|
|
|
|
|
|
|
|
visibilitySelects().live('change', updateVisibilityDescription);
|
|
|
|
|
|
|
|
onHangersInit(function () {
|
|
|
|
visibilitySelects().each(updateVisibilityDescription);
|
|
|
|
});
|
|
|
|
|
2011-07-31 16:04:21 -07:00
|
|
|
/*
|
|
|
|
|
|
|
|
Help
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
$('#toggle-help').click(function () {
|
|
|
|
$('#closet-hangers-help').toggleClass('hidden');
|
|
|
|
});
|
|
|
|
|
2011-07-31 16:24:06 -07:00
|
|
|
/*
|
|
|
|
|
|
|
|
Share URL
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
$('#closet-hangers-share-box').mouseover(function () {
|
|
|
|
$(this).focus();
|
|
|
|
}).mouseout(function () {
|
|
|
|
$(this).blur();
|
|
|
|
});
|
|
|
|
|
2011-07-30 19:08:38 -07:00
|
|
|
/*
|
|
|
|
|
2011-07-30 10:40:41 -07:00
|
|
|
Initialize
|
2011-07-30 19:08:38 -07:00
|
|
|
|
2011-07-30 10:40:41 -07:00
|
|
|
*/
|
|
|
|
|
|
|
|
hangersInit();
|
2011-07-15 19:52:53 -07:00
|
|
|
})();
|
|
|
|
|