Post by Texas on Nov 13, 2013 13:25:59 GMT -8
So, I'm re-writing a lot (well, all of it actually) of the Gold Shop plugin I wrote a while back. And to make a long story short I ran into a problem.
The items that are bought are displayed on the users profile. When the items (images) have title properties so that there names, id's, descriptions etc. will be displayed when the item is hovered over. Now, a lot of people like to write extremely long descriptions, sometimes so long that you can't even see the whole tooltip. So, I made it so that only the first 100 characters would show up, then, when the user clicked on the item, the name and description would come up in a proboards.alert. So, this worked in the old code.
But the new version which is basically identical does not work.
When you click on the item, it alerts with the wrong description and name (namely the name and description of the LAST item in the shop). I'm stumped.
And since these are virtually identical the only thing I can surmise is that somewhere in one of the new functions I did something weird. But I can't find it and it's to large to post here
The items that are bought are displayed on the users profile. When the items (images) have title properties so that there names, id's, descriptions etc. will be displayed when the item is hovered over. Now, a lot of people like to write extremely long descriptions, sometimes so long that you can't even see the whole tooltip. So, I made it so that only the first 100 characters would show up, then, when the user clicked on the item, the name and description would come up in a proboards.alert. So, this worked in the old code.
for( i=0; i<display_items.length; i++){ // loop through users items
for( x=0; x<items.length; x++){ // loop through shop items
var sliced = '';
var description = items[x].description;
if( description.length > 100 ){
// slice off nearest space after 100 characters are removed
sliced = description.slice(0 , 100);
sliced = sliced.slice(0 , sliced.lastIndexOf(' ') ) + '... (Right click to view more)';
}
if( display_items[i]['#'] == items[x].item_id ){
// check to make sure the item to be displayed and the item in the shop are the same
// ---V Add the item with the sliced description in the title
$('#display').append('<img title="' + ( ( sliced == "" )? description : sliced ) + '" style="max-height: 100px; max-width: 100px" class="' + items[x].item_id + '" src=' + items[x].image_of_item + '></img>');
var id = items[x].item_id;
var name = ( items[x].item_name != 'undefined' )? items[x].item_name : '';
$('.' + items[x].item_id).rightClick(function(){ // alert on right click
proboards.alert( 'Name: ' + name + '<br /><br />' + 'Description: ' + description + '<br /><br />' + 'ID: ' + id );
});
}
}
}
But the new version which is basically identical does not work.
for ( i = 0; i < data.b.length; i++ ) {
for ( x = 0; x < items.length; x++ ) {
var description = items[x].description;
var sliced = "";
if( description.length > 20 ){
sliced = description.slice(0 , 100);
sliced = sliced.slice(0 , sliced.lastIndexOf(' ') ) + '... (Click to view more)';
}
if ( data.b[i] == items[x].item_id ) {
$( '#shelf' ).append( '<img style="max-width: 70px; max-hieght: 70px;" class="' + data.b[i] + '" src="' + items[x].image_of_item + '"></img>' )
var name = items[x].item_name;
$( '.' + items[x].item_id ).click(function (){
proboards.alert( 'Name: ' + name + '<br /><br />Description: ' + description );
} );
$('.' + items[x].item_id + ':last').attr('title', "Name: " + items[x].item_name + '\n' + "Description: " + ( ( sliced != "" )? sliced: description ) + "\n" + "Amount: " + $('.' + items[x].item_id).length + "\n" + "Bought: " + vitals.shop.find_amount( data.b , items[x].item_id ).length + "\n" + "Given: " + vitals.shop.find_amount( data.r , items[x].item_id ).length + "\n" + "ID: " + items[x].item_id );
}
}
}
When you click on the item, it alerts with the wrong description and name (namely the name and description of the LAST item in the shop). I'm stumped.
And since these are virtually identical the only thing I can surmise is that somewhere in one of the new functions I did something weird. But I can't find it and it's to large to post here