Skip to content

Commit

Permalink
Merge pull request ngageoint#585 in WV/opensphere from ~ROYALG/opensp…
Browse files Browse the repository at this point in the history
…here:THIN-12559 to master

* commit 'd5322dd24c94ba4d9eff16b59b2eb5438bd4c159':
  fix(punyparent): fixed glitchyness
  fix(punyparent): fixed puny parent to debounce on change
  • Loading branch information
gregroyal committed Jan 2, 2019
2 parents 5796f0a + d5322dd commit cc4c838
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 21 deletions.
2 changes: 1 addition & 1 deletion src/os/ui/help/help.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ os.ui.help.helpDirective = function() {
scope: true,
controller: os.ui.help.HelpCtrl,
controllerAs: 'ctrl',
template: '<button class="btn btn-info dropdown-toggle" title="Support"' +
template: '<button class="btn btn-info" ng-class="{\'dropdown-toggle\': !puny}" title="Support"' +
' ng-click="ctrl.openMenu()" ng-right-click="ctrl.openMenu()" ng-class="{active: menu}">' +
'<i class="fa fa-question-circle" ng-class="{\'fa-fw\': puny}"></i> ' +
'<span ng-class="{\'d-none\': puny}">Support</span>' +
Expand Down
62 changes: 42 additions & 20 deletions src/os/ui/util/punyparent.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
goog.provide('os.ui.util.PunyParentCtrl');
goog.provide('os.ui.util.punyParentDirective');
goog.require('goog.Throttle');
goog.require('os.ui.Module');


Expand Down Expand Up @@ -42,6 +43,13 @@ os.ui.util.PunyParentCtrl = function($scope, $element) {
*/
this.element_ = $element;

/**
* Used to delay searching until we are done typing
* @type {goog.Throttle}
* @private
*/
this.throttle_ = new goog.Throttle(this.onThrottleResize_, 200, this);

/**
* @type {Function}
* @private
Expand All @@ -65,6 +73,10 @@ os.ui.util.PunyParentCtrl = function($scope, $element) {
*/
os.ui.util.PunyParentCtrl.prototype.destroy_ = function() {
this.element_.removeResize(this.resizeFn_);
if (this.throttle_) {
this.throttle_.dispose();
this.throttle_ = null;
}
this.scope_ = null;
this.element_ = null;
};
Expand All @@ -74,27 +86,37 @@ os.ui.util.PunyParentCtrl.prototype.destroy_ = function() {
* @private
*/
os.ui.util.PunyParentCtrl.prototype.onResize_ = function() {
var children = this.element_.children().toArray();
var childrenWidth = 0;
children.forEach(function(child) {
var c = $(child);
// ignore the resize trigger since thats the parent size
if (!c.hasClass('resize-triggers')) {
childrenWidth += c.outerWidth(true);
}
});
this.throttle_.fire();
};

if (childrenWidth > this.fullSize) {
this.fullSize = childrenWidth;
}

// Set the puny state on the child scope
children.forEach(function(child) {
var c = $(child);
var cscope = c.scope();
if (!c.hasClass('resize-triggers') && cscope) {
cscope['puny'] = this.element_.outerWidth(true) < this.fullSize;
/**
* @private
*/
os.ui.util.PunyParentCtrl.prototype.onThrottleResize_ = function() {
if (this.element_) {
var children = this.element_.children().toArray();
var childrenWidth = 0;
children.forEach(function(child) {
var c = $(child);
// ignore the resize trigger since thats the parent size
if (!c.hasClass('resize-triggers')) {
childrenWidth += c.outerWidth(true);
}
});

if (childrenWidth > this.fullSize) {
this.fullSize = childrenWidth;
}
}.bind(this));
os.ui.apply(this.scope_);

// Set the puny state on the child scope
children.forEach(function(child) {
var c = $(child);
var cscope = c.scope();
if (!c.hasClass('resize-triggers') && cscope) {
cscope['puny'] = this.element_.outerWidth(true) < this.fullSize;
}
}.bind(this));
os.ui.apply(this.scope_);
}
};

0 comments on commit cc4c838

Please sign in to comment.