/**
 * @param {Object} $ - Global jQuery object
 * @param {Object} bolt - The Bolt module
 */
(function ($, bolt) {
    'use strict';

    /**
     * BUIC stack widget.
     *
     * @license http://opensource.org/licenses/mit-license.php MIT License
     * @author rarila
     *
     * @class buicStack
     * @memberOf jQuery.widget.bolt
     */
    $.widget('bolt.buicStack', /** @lends jQuery.widget.bolt.buicStack.prototype */ {
        /**
         * The constructor of the stack widget.
         *
         * @private
         */
        _create: function () {
            bolt.uploads.bindStack(this.element);
        },

        /**
         * Add a file to the stack.
         *
         * @param {string} path - Path to add to the stack
         */
        add: function (path) {
            bolt.stack.addToStack(path);
        },

        /**
         * Add a file item to the stack display.
         *
         * @param {string} path - Path to add to the stack
         */
        prepend: function (path) {
            var stack = $('#stackholder div.stackitem'),
                i,
                ii,
                item,
                html,
                ext = path.substr(path.lastIndexOf('.') + 1).toLowerCase(),
                type;

            if (ext === 'jpg' || ext === 'jpeg' || ext === 'png' || ext === 'gif') {
                type = 'image';
            } else {
                type = 'other';
            }

            // Move all current items one down, and remove the last one.
            for (i = stack.length; i >= 1; i--) {
                ii = i + 1;
                item = $('#stackholder div.stackitem.item-' + i);
                item.addClass('item-' + ii).removeClass('item-' + i);
            }
            if ($('#stackholder div.stackitem.item-8').is('*')) {
                $('#stackholder div.stackitem.item-8').remove();
            }

            // Insert new item at the front.
            if (type === 'image') {
                html = $('#protostack div.image').clone();
                $(html).find('img').attr('src', bolt.conf('paths.bolt') + '../thumbs/100x100c/' +
                    encodeURI(path));
            } else {
                html = $('#protostack div.other').clone();
                $(html).find('strong').html(ext.toUpperCase());
                $(html).find('small').html(path);
            }
            $('#stackholder').prepend(html);

            // If the "empty stack" notice was showing, remove it.
            $('.nostackitems').remove();
        }
    });
})(jQuery, Bolt);

@@ -1092,357 +1092,130 @@
     
-i,%0A                ii,%0A                item,%0A                html,%0A                ext = path.substr(path.lastIndexOf('.') + 1).toLowerCase(),%0A                type;%0A%0A            if (ext === 'jpg' %7C%7C ext === 'jpeg' %7C%7C ext === 'png' %7C%7C ext === 'gif') %7B%0A                type = 'image';%0A            %7D else %7B%0A                type = 'other';%0A            %7D
+ext = path.substr(path.lastIndexOf('.') + 1).toLowerCase(),%0A                item,%0A                html,%0A                i;
 %0A%0A  
@@ -1339,36 +1339,8 @@
 ) %7B%0A
-                ii = i + 1;%0A
     
@@ -1445,10 +1445,15 @@
 ' + 
-ii
+(i + 1)
 ).re
@@ -1701,23 +1701,72 @@
 if (
-type === 'image
+ext === 'jpg' %7C%7C ext === 'jpeg' %7C%7C ext === 'png' %7C%7C ext === 'gif
 ') %7B
@@ -1926,28 +1926,8 @@
 /' +
-%0A                   
  enc

Refactor prepend method