Skip to content
This repository has been archived by the owner on Dec 1, 2022. It is now read-only.

fix a bug + allow dynamic resize #9

Merged
merged 3 commits into from May 1, 2017
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 2 additions & 2 deletions index.html
@@ -1,6 +1,6 @@
<!DOCTYPE html>

<html lang="en" style="height:100%">
<html lang="en">
<head>
<meta charset="utf-8" />
<!-- VSS Framework -->
Expand All @@ -10,7 +10,7 @@
<link rel="stylesheet" href="styles/style.css" type="text/css"/>
</head>

<body style="height:100%">
<body>
<script>
VSS.init({
explicitNotifyLoaded: true,
Expand Down
36 changes: 32 additions & 4 deletions scripts/control.ts
Expand Up @@ -8,19 +8,40 @@ import { InputParser } from "./InputParser";
import { Model } from "./model";
import { colorControl } from "./view";
import { ErrorView } from "./errorView";
import * as VSSUtilsCore from "VSS/Utils/Core";
import * as Q from "q";

export class Controller {

private _fieldName: string = "";

private _inputs: IDictionaryStringTo<string>;

private _model: Model;

private _view: colorControl;

constructor() {
/**
* Store the last recorded window width to know
* when we have been shrunk and should resize
*/
private _windowWidth: number;
private _minWindowWidthDelta: number = 10; // Minum change in window width to react to
private _windowResizeThrottleDelegate: Function;
private _bodyElement: HTMLBodyElement;

constructor() {
this._bodyElement = <HTMLBodyElement>document.getElementsByTagName("body").item(0);

this._windowResizeThrottleDelegate = VSSUtilsCore.throttledDelegate(this, 50, () => {
this._windowWidth = window.innerWidth;
this.resize();
});

this._windowWidth = window.innerWidth;
$(window).resize(() => {
if(Math.abs(this._windowWidth - window.innerWidth) > this._minWindowWidthDelta) {
this._windowResizeThrottleDelegate.call(this);
}
});

this._initialize();
}

Expand Down Expand Up @@ -50,6 +71,8 @@ export class Controller {
this._model.selectPreviousOption();
this._updateInternal(this._model.getSelectedValue());
});

this.resize();
}, this._handleError
).then(null, this._handleError);
},
Expand Down Expand Up @@ -84,4 +107,9 @@ export class Controller {
public getFieldName(): string {
return this._fieldName;
}

protected resize() {
// Cast as any until declarations are updated
(VSS as any).resize(null, this._bodyElement.offsetHeight);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The cast is not needed anymore

}
}
2 changes: 1 addition & 1 deletion scripts/view.ts
Expand Up @@ -149,7 +149,7 @@ export class colorControl {

private _click(evt: JQueryMouseEventObject): void {
let itemClicked = $(evt.target).closest(".row").data("value");
if (!!itemClicked && !!this.onItemClicked) {
if (itemClicked != null && $.isFunction(this.onItemClicked)) {
this.onItemClicked(itemClicked);
}
}
Expand Down
2 changes: 1 addition & 1 deletion vss-extension.json
@@ -1,7 +1,7 @@
{
"manifestVersion": 1,
"id": "color-form-control",
"version": "1.0.2",
"version": "1.0.3",
"name": "Color picklist control",
"description": "Add custom colors and labels for picklist fields.",
"publisher": "ms-devlabs",
Expand Down