Skip to content

Commit

Permalink
Store data in collection element
Browse files Browse the repository at this point in the history
  • Loading branch information
MisatoTremor authored Jan 22, 2019
1 parent 00696d9 commit 589ef9f
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions Resources/public/js/mopabootstrap-collection.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,7 @@
/* Collection PUBLIC CLASS DEFINITION
* ============================== */

var Collection = function (element, options) {
this.$element = $(element);
var Collection = function (options) {
this.options = $.extend({}, $.fn.collection.defaults, options);

// This must work with "collections" inside "collections", and should
Expand All @@ -43,6 +42,9 @@
};
Collection.prototype = {
constructor: Collection,
setElement: function (element) {
this.$element = $(element);
},
add: function () {
if (typeof this.options.max == 'number' && this.getItems().length >= this.options.max) {
return;
Expand Down Expand Up @@ -148,7 +150,7 @@
return this.each(function () {
var $this = $(this),
collection_id = $this.data('collection-add-btn'),
data = $this.data('collection'),
data,
options = typeof option == 'object' ? option : {};

if (collection_id) {
Expand All @@ -162,9 +164,11 @@
throw new Error('Could not load collection id');
}
}
data = $(options.collection_id).data('collection');
if (!data) {
$this.data('collection', (data = new Collection(this, options)));
$(options.collection_id).data('collection', (data = new Collection(options)));
}
data.setElement(this);
if (coll_args.length > 1) {
var arg1 = coll_args[1];
var returnval;
Expand Down

0 comments on commit 589ef9f

Please sign in to comment.