';
catHTML += '
';
catHTML += '';
catHTML += '';
catHTML += 'All | ';
for ( var i in this.settings.shop_categories ) {
var cClass = this.settings.shop_categories[i].replace(/\s|'|"|&|\./g, '');
catHTML += '' + this.settings.shop_categories[i] + ' | ';
}
catHTML += '
';
catHTML += '';
catHTML += '
';
$('#shop-shelf-icon').before(catHTML);
// Item constructor
function item_constructor(item_data) {
this.amount = item_data.amount;
this.cost = item_data.cost_of_item;
this.description = item_data.description;
this.is_givable = item_data.givable;
this.image = item_data.image_of_item;
this.category = item_data.item_category;
this.id = item_data.item_id;
this.name = item_data.item_name;
this.is_returnable = item_data.returnable;
}
// Icon constructor
item_constructor.prototype.icon = function () {
var item = this,
cClass = this.category.replace(/\s|'|"|&|\./g, ''),
html = '';
html += '
';
html += '
';
html += '
';
html += item.name;
html += '
';
html += '
';
html += '
';
html += 'Cost: ' + pixeldepth.monetary.settings.money_symbol + yootil.number_format(parseFloat(item.cost));
html += '
';
html += 'In Stock: ∞';
html += '
';
html += '
';
html += '
';
html += '
';
html += '
';
html += '
';
html += '
';
return $(html);
}
// Details constructor
item_constructor.prototype.detailed = function () {
var item = this;
cClass = this.category.replace(/\s|'|&|\./g, '');
html = '';
html += '
';
html += '
';
html += '
';
html += '
';
html += '
';
html += '
';
html += '
';
html += '
';
html += '
∞ in stock
';
html += '
';
html += '
' + item.description + '
';
html += '
';
html += '' + this.category + '';
html += '' + ((this.is_givable == "true")? "Givable": "Non-Givable") + '';
html += '' + ((this.is_returnable == "true")? "Returnable": "Non-Returnable") + '';
html += '' + this.id + '';
html += '
';
html += '
';
html += '
';
return $(html);
}
// Add icon items
for ( var i in vitals.shop.settings.shop_items ) {
var x = new item_constructor(vitals.shop.settings.shop_items[i]);
var y = x.icon();
y.appendTo('#shop-shelf-icon > .item-shelf');
}
// Add detailed items
for ( var i in vitals.shop.settings.shop_items ) {
var x = new item_constructor(vitals.shop.settings.shop_items[i]);
var y = x.detailed();
y.appendTo('#shop-shelf-details > .item-shelf');
}
},
}
})();
vitals.shop.infoPage = (function(){
var goldShop = pb.plugin.get( 'gold_shop');
return {
name: 'infoPage',
init: function () {
this.createPage();
this.addItemInfo();
this.addCss();
},
data: {
currentItem: '',
styles: {
itemImage: {
"float": "left",
"border-width": goldShop.settings.item_border_width + 'px',
"border-style": goldShop.settings.item_border_style,
"border-color": goldShop.settings.item_border_color,
"border-top-left-radius": goldShop.settings.item_border_top_left_radius,
"border-top-right-radius": goldShop.settings.item_border_top_right_radius,
"border-bottom-right-radius": goldShop.settings.item_border_bottom_left_radius,
"border-bottom-left-radius": goldShop.settings.item_border_bottom_right_radius,
"padding": "5px",
},
dollarImage: {
"float": "right",
},
itemInfo: {
"float": "left",
"margin-top": "auto",
"margin-bottom": "auto",
"margin-left": "15px",
},
nameHolder: {
"font-weight": "bold",
},
itemAttr: {
"font-style": "italic",
},
},
},
createPage: function () {
var itemId = getURLParams().id,
item = vitals.shop.settings.shop_items[itemId];
this.data.currentItem = itemId;
yootil.create.page( /\/\?shop\/info/ );
yootil.create.nav_branch( "/?shop", vitals.shop.settings.shop_name );
yootil.create.nav_branch( "/?shop/info&id=" + itemId, "Info: " + item.item_name );
$( 'title' ).text( vitals.shop.settings.shop_name + " | Info" );
$( '#content' ).append( '
' );
yootil.create.container( 'Info Item: ' + item.item_name + '
(' + pixeldepth.monetary.settings.text.wallet + ': ' + pixeldepth.monetary.get( true ) + ')' ).attr( 'id', 'info-container' ).appendTo( '#shop-container' );
},
addItemInfo: function () {
var itemData = vitals.shop.settings.shop_items[this.data.currentItem],
html = '';
html += '';
html += '';
html += '';
html += 'Item: ' + itemData.item_name + '';
html += '
';
html += '
';
html += 'Description: ' + ( ( itemData.description.length >= 50 ) ? "(Click to view description)" : itemData.description ) + '';
html += '
';
html += '
';
html += 'Cost: ' + pixeldepth.monetary.settings.money_symbol + yootil.number_format( parseFloat( itemData.cost_of_item ) ) + '';
html += '
';
html += '
';
html += 'In Stock: ∞';
html += '
';
html += '
';
html += 'Category: ' + itemData.item_category + '';
html += '
';
html += '
';
html += 'Returnable: ' + ( ( itemData.returnable == "true" )? "Yes": "No" ) + '';
html += '
';
html += '
';
html += 'Giveable: ' + ( ( itemData.givable == "true" )? "Yes": "No" ) + '';
html += '
';
html += '
';
html += 'ID: ' + itemData.item_id + '';
html += '
';
$( html ).appendTo( '#info-container > .content' );
},
alertInfo: function () {
var itemData = vitals.shop.settings.shop_items[this.data.currentItem],
description = itemData.description;
pb.window.alert( description );
},
addCss: function () {
$( '#info-container .item-image' ).css( this.data.styles.itemImage );
$( '#info-container .money-image' ).css( this.data.styles.dollarImage );
$( '#info-container .item-info' ).css( this.data.styles.itemInfo );
$( '.item-info > .nameholder' ).css( this.data.styles.nameHolder );
$( '.item-info > .item-attr' ).css( this.data.styles.itemAttr );
},
}
} )();
vitals.shop.data = (function(){
function data(){
var data = proboards.plugin.keys.data['gold_shop'];
this.data = data;
this.shop = data['shop'];
this.pBey = data['pBey'];
this.get = {
shop: {
all: function () {
return this.shop;
},
user: function (user) {
if ( user === null || user === undefined )
user = yootil.user.id();
if ( this.shop.users[user] !== undefined )
return this.shop.users[user];
},
item: function (item) {
if ( item === null || item === undefined )
return this.shop.i;
else if ( this.shop.i[item] !== undefined )
return this.shop.i[item];
},
submit: function (submitted) {
if ( submitted === null || submitted === undefined )
return this.shop.si;
else if ( this.shop.si[submitted] !== undefined )
return this.shop.si[submitted]
}
},
pBey: function () {
return this.pBey;
},
}
}
return data;
})();
//* This method is copied from http://stackoverflow.com/questions/9229645/remove-duplicates-from-javascript-array
removeArrDuples = function(ary, key) {
var seen = {};
return ary.filter(function(elem) {
var k = key(elem);
return (seen[k] === 1) ? 0 : seen[k] = 1;
});
};
//* Copied from http://stackoverflow.com/questions/13037762/how-to-get-url-variable-using-jquery-javascript
function getURLParams() {
var vars = {};
var parts = window.location.href.replace(/[?&]+([^=&]+)=([^&]*)/gi, function(m, key, value) {
vars[decodeURIComponent(key)] = decodeURIComponent(value);
});
return vars;
}