| Autor | Zpráva | ||
|---|---|---|---|
| Fisak Profil |
#1 · Zasláno: 20. 5. 2013, 20:58:12
Dobrý den. Moc neumím s jquery spíše kopíruji a vkládám, ale teď mi jeden jquery kód funguje na localhostu a nebo na serveru když je prázdná stránka ale bohužel mi špatně pracuje s #inventory.. přidává itemy i když s předmětem jen hnu.. (tzn. posílá to getem "inventory" do update-inventory.php). Nevěděl by někdo jak se tohoto vyvarovat?
<script type="text/javascript">
function itemInSpot(drag_item,spot)
{
var oldSpotItem = $(spot).find('img');
if(oldSpotItem.length > 0) {
oldSpotItem.appendTo('#inventory').draggable({ revert: 'invalid' });
}
var item = $('<img />');
drag_item.empty().remove(); // remove the old object
item.attr('src',drag_item.attr('src')).attr('id',drag_item.attr('id')).attr('class',drag_item.attr('class')).appendTo(spot).draggable({ revert: 'invalid' });
update_spots(); // update the DB
}
function update_spots()
{
// Create a list of all the items
var inventory_items = '';
var helmet_spot_item = ($('#helmet_spot img').length > 0) ? $('#helmet_spot img').attr('id') : '';
var right_hand_spot = ($('#right_hand img').length > 0) ? $('#right_hand img').attr('id') : '';
var left_hand_spot = ($('#left_hand img').length > 0) ? $('#left_hand img').attr('id') : '';
$('#inventory img').each(
function(i) {
if($(this).attr('id') != '') {
if(inventory_items.length > 0) inventory_items += ';';
inventory_items += $(this).attr('id');
}
}
);
var uri_inventory = 'game/components/update-inventory.php?helmet_spot='+helmet_spot_item+'&right_hand='+right_hand_spot+'&left_hand='+left_hand_spot+'&inventory='+inventory_items;
$.ajax({
type: "GET",
url: uri_inventory
});
}
$(document).ready(function() {
$(".right_hand,.helmet,.left_hand").draggable({ revert: 'invalid'});
$('#inventory').droppable();
$("#right_hand").droppable({ accept: '.right_hand'})
$("#left_hand").droppable({ accept: '.left_hand,.right_hand'})
$('#helmet_spot').droppable({ accept: '.helmet'});
$('#right_hand,#helmet_spot,#inventory,#left_hand').bind('drop', function(ev,ui) { itemInSpot(ui.draggable,this); });
});
window["_GOOG_TRANS_EXT_VER"] = "1";
</script> |
||
| Fisak Profil |
#2 · Zasláno: 21. 5. 2013, 11:12:06
Nyní jsem zkoušel přejmenovat všechny proměnné ale bohužel je to ještě horší:
<script type="text/javascript">
function itemInSpotInventory(drag_itemInventory,spotInventory)
{
var oldSpotItemInventory = $(spotInventory).find('img');
if(oldSpotItemInventory.length > 0) {
oldSpotItemInventory.appendTo('#inventory').draggable({ revert: 'invalid' });
}
var itemInventory = $('<img />');
drag_itemInventory.empty().remove(); // remove the old object
itemInventory.attr('src',drag_itemInventory.attr('src')).attr('id',drag_itemInventory.attr('id')).attr('class',drag_itemInventory.attr('class')).appendTo(spotInventory).draggable({ revert: 'invalid' });
update_spotsInventory(); // update the DB
}
function update_spotsInventory()
{
// Create a list of all the items
var inventory_items = '';
var helmet_spot_item = ($('#helmet_spot img').length > 0) ? $('#helmet_spot img').attr('id') : '';
var right_hand_spot = ($('#right_hand img').length > 0) ? $('#right_hand img').attr('id') : '';
var left_hand_spot = ($('#left_hand img').length > 0) ? $('#left_hand img').attr('id') : '';
$('#inventory img').each(
function(i) {
if($('#inventory img').attr('id') != '') {
if(inventory_items.length > 0) inventory_items += ';';
inventory_items += $('#inventory img').attr('id');
}
}
);
var uri_inventory = 'game/components/update-inventory.php?helmet_spot='+helmet_spot_item+'&right_hand='+right_hand_spot+'&left_hand='+left_hand_spot+'&inventory='+inventory_items;
$.ajax({
type: "GET",
url: uri_inventory
});
}
$('.ui-droppable').ready(function() {
$(".right_hand,.helmet,.left_hand").draggable({ revert: 'invalid'});
$('#inventory').droppable();
$("#right_hand").droppable({ accept: '.right_hand'})
$("#left_hand").droppable({ accept: '.left_hand,.right_hand'})
$('#helmet_spot').droppable({ accept: '.helmet'});
$('#right_hand,#helmet_spot,#inventory,#left_hand').bind('drop', function(ev,ui) { itemInSpotInventory(ui.draggable,this); });
});
window["_GOOG_TRANS_EXT_VER"] = "1";
</script> |
||
|
Časová prodleva: 13 let
|
|||
0