Skip to content

Commit

Permalink
Merge pull request #641 from massiveart/feature/toolbar-preselect
Browse files Browse the repository at this point in the history
Added preselect callback for toolbar button
  • Loading branch information
chirimoya committed Apr 29, 2016
2 parents 388a4d1 + d421e83 commit 2c31bfe
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 5 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

* dev-develop
* BUGFIX #644 Fixed scrollable tabs
* FEATURE #641 Added preselect callback for toolbar button
* BUGFIX #633 Removed bound effect respectively additional scrollbar

* 0.19.1 (2016-04-26)
Expand Down
21 changes: 19 additions & 2 deletions dist/husky.js
Original file line number Diff line number Diff line change
Expand Up @@ -36881,7 +36881,15 @@ define('__component__$toolbar@husky',[],function() {
this.items[button].dropdownItems = items;
createDropdownMenu.call(this, this.items[button].$el, this.items[button]);
if (!!itemId) {
this.sandbox.emit(ITEM_CHANGE.call(this), this.items[button].id, itemId);
changeButton.call(this, this.items[button].id, itemId).then(function(item) {
if (!this.items[button].dropdownOptions
|| typeof this.items[button].dropdownOptions.preSelectedCallback !== 'function'
) {
return;
}

this.items[button].dropdownOptions.preSelectedCallback(item);
}.bind(this));
}
} else {
deleteDropdown.call(this, this.items[button]);
Expand All @@ -36904,19 +36912,28 @@ define('__component__$toolbar@husky',[],function() {
return;
}

var button = this.items[buttonId];
var button = this.items[buttonId],
deferred = $.Deferred();

button.initialized.then(function() {
// update icon
var index = getItemIndexById.call(this, itemId, button);
if (index === true) {
index = 0;
}

changeMainListItem.call(this, button.$el, button.dropdownItems[index]);
this.sandbox.emit(ITEM_MARK.call(this), button.dropdownItems[index].id);
if (executeCallback === true || !!button.dropdownItems[index].callback
&& typeof button.dropdownItems[index].callback === 'function'
) {
button.dropdownItems[index].callback();
}

deferred.resolve(button.dropdownItems[index]);
}.bind(this));

return deferred.promise();
},

/**
Expand Down
2 changes: 1 addition & 1 deletion dist/husky.min.js

Large diffs are not rendered by default.

21 changes: 19 additions & 2 deletions husky_components/toolbar/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -354,7 +354,15 @@ define(function() {
this.items[button].dropdownItems = items;
createDropdownMenu.call(this, this.items[button].$el, this.items[button]);
if (!!itemId) {
this.sandbox.emit(ITEM_CHANGE.call(this), this.items[button].id, itemId);
changeButton.call(this, this.items[button].id, itemId).then(function(item) {
if (!this.items[button].dropdownOptions
|| typeof this.items[button].dropdownOptions.preSelectedCallback !== 'function'
) {
return;
}

this.items[button].dropdownOptions.preSelectedCallback(item);
}.bind(this));
}
} else {
deleteDropdown.call(this, this.items[button]);
Expand All @@ -377,19 +385,28 @@ define(function() {
return;
}

var button = this.items[buttonId];
var button = this.items[buttonId],
deferred = $.Deferred();

button.initialized.then(function() {
// update icon
var index = getItemIndexById.call(this, itemId, button);
if (index === true) {
index = 0;
}

changeMainListItem.call(this, button.$el, button.dropdownItems[index]);
this.sandbox.emit(ITEM_MARK.call(this), button.dropdownItems[index].id);
if (executeCallback === true || !!button.dropdownItems[index].callback
&& typeof button.dropdownItems[index].callback === 'function'
) {
button.dropdownItems[index].callback();
}

deferred.resolve(button.dropdownItems[index]);
}.bind(this));

return deferred.promise();
},

/**
Expand Down

0 comments on commit 2c31bfe

Please sign in to comment.