/******************************************* * Copyright (c) Peter Maggio * * (protex.boards.net) * * 2013 all rights reserved * * Not to be redistributed * * http://support.proboards.com/user/173855 * ********************************************/ var vitals = vitals || {}; var start = setInterval(function() { if (!$.isReady) return; clearInterval(start); vitals.shop.setup(); }, 100); vitals.shop = (function(){ return{ plugin: proboards.plugin._plugins.gold_shop, key: proboards.plugin.keys.data.gold_shop, settings: { // user user_is_admin: false, user_is_item_creator: false, user_is_disabled: false, user_can_submit_items: false, user_can_approve_items: false, user_has_data: false, // Shop shop_name: "The Shop", shop_welcome_message: "Welcome to the Shop!", shop_user_submissions_open: false, shop_logo: '', shop_items: {}, shop_categories: {} }, setup: function () { var items = {}, categories = []; // Setup variables this.settings.user_is_admin = ( yootil.user.id() === 1 )? true: false; this.settings.user_is_item_creator = false; this.settings.user_is_disabled = false; this.settings.user_can_submit_items = false; this.settings.user_can_approve_items = false; this.settings.user_has_data = false; this.settings.shop_name = ( this.plugin.settings.shopName.length > 0 )? this.plugin.settings.shopName: this.settings.shop_name; this.settings.shop_welcome_message = ( this.plugin.settings.welcome_message )? this.plugin.settings.welcome_message: this.settings.shop_name; this.settings.user_submissions_open = false; this.settings.shop_logo = this.plugin.images.ShopLarge; this.settings.shop_items = this.plugin.settings.items; this.settings.shop_categories = this.plugin.settings.categories; // Create item and category hash for ( var i in this.settings.shop_items ) { items[this.settings.shop_items[i].item_id] = this.settings.shop_items[i]; } this.settings.shop_items = items; for ( var i in this.settings.shop_categories ) { categories.push(this.settings.shop_categories[i].categoryName); } this.settings.shop_categories = categories; // Create Pages if( location.search.match(/^\?shop$/) ) { this.createShop(); } if( location.search.match(/^\?shop\/info\&id=(.+?)$/) ) { vitals.shop.infoPage.init(); } }, createShop: function () { // Add the basics var welcomehtml = '', shopHTML = '', catHTML = ''; yootil.create.page(/\/\?shop/); yootil.create.nav_branch('/?shop', this.settings.shop_name); welcomehtml += '
'; welcomehtml += ''; welcomehtml += '

' + this.settings.shop_welcome_message + '

'; welcomehtml += '
'; welcomehtml += 'Help'; welcomehtml += '
'; welcomehtml += '
'; welcomehtml += '
'; yootil.create.container(this.settings.shop_name + '(' + pixeldepth.monetary.settings.text.wallet + ': ' + pixeldepth.monetary.get(true) + ')', welcomehtml).appendTo('#content'); // Add the icon view shopHTML += '
'; shopHTML += '
'; shopHTML += '
'; // Add the detailed view shopHTML += '
'; shopHTML += '
'; shopHTML += '
'; yootil.create.container("Items", shopHTML).attr('id', 'shop-item-container').appendTo('#content'); $('#shop-item-container > .content.pad-all').removeClass('pad-all'); // Create cat bars catHTML += '
'; catHTML += ''; catHTML += ''; catHTML += ''; catHTML += ''; for ( var i in this.settings.shop_categories ) { var cClass = this.settings.shop_categories[i].replace(/\s|'|"|&|\./g, ''); catHTML += ''; } catHTML += ''; catHTML += ''; catHTML += ''; 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 += '
'; html += '

' + item.name + '

'; 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; }
All' + this.settings.shop_categories[i] + '