Created
February 19, 2018 05:42
-
-
Save ChapelR/24f475c2eda70cd8ca3fd8887a040a58 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function descrList (loc, action) { // construct the list elements to keep the macro call clean-ish | |
if (!loc || !(loc instanceof setup.simpleInv.inventory)) { | |
loc = false; // if no loc, then no transferring | |
} | |
// set up vars | |
var list = this.toArray(); | |
var inv = this; | |
var $wrapper = $(document.createElement('span')); | |
// if inventory is empty, append message and return element | |
if (!list || !list.length) { | |
$wrapper.wiki(setup.simpleInv.options.defaultStrings.empty); | |
return $wrapper; | |
} | |
// construct the link list | |
list.forEach(function (item, idx, arr) { | |
var $listing = $(document.createElement('span')), | |
$link = $(document.createElement('a')), | |
drop = (action) ? action : setup.simpleInv.options.defaultStrings.drop, // the action name or default | |
UID = setup.simpleInv.inventory.getUID(item, idx), // create a unique element ID | |
$item; | |
$link // create the drop link | |
.wiki(drop) | |
.addClass('simple-inv drop-link'); | |
// add click event handler | |
$link.ariaClick(function () { | |
if (loc) { | |
inv.transfer(loc, item); | |
} else { | |
inv.drop(item); | |
} | |
$('#' + UID).empty(); // empty the listing by its UID | |
}); | |
if (Story.has(item)) { | |
$item = $(document.createElement('a')) | |
.addClass('simple-inv descr-link') | |
.wiki(item) | |
.ariaClick({ label : 'Description' }, function () { | |
Dialog.setup(item); | |
Dialog.wiki(Story.get(item).text) | |
Dialog.open(); | |
}); | |
} else { | |
$item = $(document.createElement('span')) | |
.addClass('simple-inv item-name') | |
.wiki(item); | |
} | |
// set up the listing element, which contains the name and the link | |
$listing | |
.attr('id', UID) | |
.addClass('simple-inv link-listing') | |
.append($item) | |
.wiki(' ') | |
.append($link); | |
// add newline via <br> for listings that aren't last | |
// this also allows the newline to disappear with its associated listing when dropped | |
if (idx < arr.length - 1) { | |
$listing.wiki('<br />'); | |
} | |
// attach to the return element | |
$wrapper.append($listing); | |
}); | |
// return the whole element | |
return $wrapper; | |
} | |
setup.simpleInv.inventory.prototype.linkedList = descrList; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
<<linkedinventory "Drop" "$inventory">>