feat(angular-ui): add angular-ui-sortable definition

This commit is contained in:
Thodoris Greasidis
2015-03-08 20:30:37 +02:00
parent fa20411dd5
commit 91438ca0a1
2 changed files with 353 additions and 0 deletions

View File

@@ -0,0 +1,143 @@
/// <reference path="../angularjs/angular.d.ts" />
/// <reference path="angular-ui-sortable.d.ts" />
var myApp = angular.module('testModule');
interface MySortableControllerScope extends ng.IScope {
items: SortableModelInfo[];
sortableOptions: ng.ui.UISortableOptions<SortableModelInfo>;
sortingLog: SortLogInfo[];
}
interface SortableModelInfo {
text: string;
value: number;
}
interface SortLogInfo {
ID: number;
Text: string;
}
myApp.controller('sortableController', function ($scope: MySortableControllerScope) {
$scope.sortableOptions = {
activate: function(e, ui) {
var jQueryEventObject: JQueryEventObject = e;
var uiSortableUIParams: ng.ui.UISortableUIParams<SortableModelInfo> = ui;
},
beforeStop: function(e, ui) {
var jQueryEventObject: JQueryEventObject = e;
var uiSortableUIParams: ng.ui.UISortableUIParams<SortableModelInfo> = ui;
},
change: function(e, ui) {
var jQueryEventObject: JQueryEventObject = e;
var uiSortableUIParams: ng.ui.UISortableUIParams<SortableModelInfo> = ui;
},
deactivate: function(e, ui) {
var jQueryEventObject: JQueryEventObject = e;
var uiSortableUIParams: ng.ui.UISortableUIParams<SortableModelInfo> = ui;
},
out: function(e, ui) {
var jQueryEventObject: JQueryEventObject = e;
var uiSortableUIParams: ng.ui.UISortableUIParams<SortableModelInfo> = ui;
},
over: function(e, ui) {
var jQueryEventObject: JQueryEventObject = e;
var uiSortableUIParams: ng.ui.UISortableUIParams<SortableModelInfo> = ui;
},
receive: function(e, ui) {
var jQueryEventObject: JQueryEventObject = e;
var uiSortableUIParams: ng.ui.UISortableUIParams<SortableModelInfo> = ui;
},
remove: function(e, ui) {
var jQueryEventObject: JQueryEventObject = e;
var uiSortableUIParams: ng.ui.UISortableUIParams<SortableModelInfo> = ui;
},
sort: function(e, ui) {
var jQueryEventObject: JQueryEventObject = e;
var uiSortableUIParams: ng.ui.UISortableUIParams<SortableModelInfo> = ui;
},
start: function(e, ui) {
var jQueryEventObject: JQueryEventObject = e;
var uiSortableUIParams: ng.ui.UISortableUIParams<SortableModelInfo> = ui;
},
stop: function(e, ui) {
var jQueryEventObject: JQueryEventObject = e;
var uiSortableUIParams: ng.ui.UISortableUIParams<SortableModelInfo> = ui;
var uiitem: ng.ui.UISortableUIItem<SortableModelInfo> = ui.item;
var uiitemscope: ng.IScope = uiitem.scope();
var uiitemsortable: ng.ui.UISortableProperties<SortableModelInfo> = uiitem.sortable;
var dropindex: number = uiitemsortable.dropindex;
var droptarget: number = uiitemsortable.droptarget;
var droptargetModel: SortableModelInfo[] = uiitemsortable.droptargetModel;
var index: number = uiitemsortable.index;
var model: SortableModelInfo = uiitemsortable.model;
var moved: SortableModelInfo = uiitemsortable.moved;
var received: Boolean = uiitemsortable.received;
var source: ng.IAugmentedJQuery = uiitemsortable.source;
var sourceModel: SortableModelInfo[] = uiitemsortable.sourceModel;
var logEntry = {
ID: $scope.sortingLog.length + 1,
Text: 'Moved element: ' + ui.item.sortable.model.text
};
$scope.sortingLog.push(logEntry);
},
update: function(e, ui) {
var jQueryEventObject: JQueryEventObject = e;
var uiSortableUIParams: ng.ui.UISortableUIParams<SortableModelInfo> = ui;
var voidcanceled: void = ui.item.sortable.cancel();
var isCanceled: Boolean = ui.item.sortable.isCanceled();
var isCustomHelperUsed: Boolean =ui.item.sortable.isCustomHelperUsed();
}
};
$scope.sortableOptions.appendTo = document.body;
$scope.sortableOptions.appendTo = angular.element(document.body);
$scope.sortableOptions.appendTo = 'body';
$scope.sortableOptions.axis = 'x';
$scope.sortableOptions.axis = 'y';
$scope.sortableOptions.axis = false;
$scope.sortableOptions.cancel = '.disabled';
$scope.sortableOptions.connectWith = '.connectedSortable';
$scope.sortableOptions.connectWith = false;
$scope.sortableOptions.containment = 'parent';
$scope.sortableOptions.containment = 'body';
$scope.sortableOptions.containment = document.body;
$scope.sortableOptions.containment = false;
$scope.sortableOptions.cursor = 'move';
$scope.sortableOptions.cursorAt = false;
$scope.sortableOptions.cursorAt = { left: 5 };
$scope.sortableOptions.delay = 300;
$scope.sortableOptions.disabled = true;
$scope.sortableOptions.distance = 5;
$scope.sortableOptions.dropOnEmpty = false;
$scope.sortableOptions.forceHelperSize = true;
$scope.sortableOptions.forcePlaceholderSize = true;
$scope.sortableOptions.grid = false;
$scope.sortableOptions.grid = [20, 10];
$scope.sortableOptions.handle = '.handle';
$scope.sortableOptions.helper = 'clone';
$scope.sortableOptions.helper = function(e: JQueryEventObject, item: ng.IAugmentedJQuery) {
return item.clone();
};
$scope.sortableOptions.items = '> li:not(.disabled)';
$scope.sortableOptions.opacity = false;
$scope.sortableOptions.opacity = 0.5;
$scope.sortableOptions.placeholder = false;
$scope.sortableOptions.placeholder = 'sortable-placeholder';
$scope.sortableOptions.revert = true;
$scope.sortableOptions.revert = 300;
$scope.sortableOptions.scroll = false;
$scope.sortableOptions.scrollSensitivity = 10;
$scope.sortableOptions.scrollSpeed = 40;
$scope.sortableOptions.tolerance = 'pointer';
$scope.sortableOptions.zIndex = 9999;
$scope.sortableOptions['ui-floating'] = undefined;
$scope.sortableOptions['ui-floating'] = null;
$scope.sortableOptions['ui-floating'] = false;
$scope.sortableOptions['ui-floating'] = true;
$scope.sortableOptions['ui-floating'] = "auto";
});

210
angular-ui/angular-ui-sortable.d.ts vendored Normal file
View File

@@ -0,0 +1,210 @@
// Type definitions for angular.ui.sortable module v0.13+
// Project: https://github.com/angular-ui/ui-sortable
// Definitions by: Thodoris Greasidis <https://github.com/thgreasi>
// Definitions: https://github.com/borisyankov/DefinitelyTyped
/// <reference path="../angularjs/angular.d.ts" />
declare module ng.ui {
interface UISortableOptions<T> extends SortableOptions<T> {
'ui-floating'?: string|boolean;
}
interface UISortableProperties<T> {
/**
* Holds the index of the drop target that the dragged item was dropped.
*/
dropindex: number;
/**
* Holds the ui-sortable element that the dragged item was dropped on.
*/
droptarget: number;
/**
* Holds the array that is specified by the `ng-model` attribute of the [`droptarget`](#droptarget) ui-sortable element.
*/
droptargetModel: Array<T>;
/**
* Holds the original index of the item dragged.
*/
index: number;
/**
* Holds the JavaScript object that is used as the model of the dragged item, as specified by the ng-repeat of the [`source`](#source) ui-sortable element and the item's [`index`](#index).
*/
model: T;
/**
* Holds the model of the dragged item only when a sorting happens between two connected ui-sortable elements.
* In other words: `'moved' in ui.item.sortable` will return false only when a sorting is withing the same ui-sortable element ([`source`](#source) equals to the [`droptarget`](#droptarget)).
*/
moved?: T;
/**
* When sorting between two connected sortables, it will be set to true inside the `update` callback of the [`droptarget`](#droptarget).
*/
received: Boolean;
/**
* Holds the ui-sortable element that the dragged item originated from.
*/
source: ng.IAugmentedJQuery
/**
* Holds the array that is specified by the `ng-model` of the [`source`](#source) ui-sortable element.
*/
sourceModel: Array<T>;
/**
* Can be called inside the `update` callback, in order to prevent/revert a sorting.
* Should be used instead of the [jquery-ui-sortable cancel()](http://api.jqueryui.com/sortable/#method-cancel) method.
*/
cancel(): void;
/**
* Returns whether the current sorting is marked as canceled, by an earlier call to [`ui.item.sortable.cancel()`](#cancel).
*/
isCanceled(): Boolean;
/**
* Returns whether the [`helper`](http://api.jqueryui.com/sortable/#option-helper) element used for the current sorting, is one of the original ui-sortable list elements.
*/
isCustomHelperUsed(): Boolean;
}
interface UISortableUIItem<T> extends ng.IAugmentedJQuery {
sortable: UISortableProperties<T>;
}
interface UISortableUIParams<T> extends SortableUIParams {
item: UISortableUIItem<T>;
}
// Base Sortable //////////////////////////////////////////////////
interface SortableCursorAtOptions {
top?: number;
left?: number;
right?: number;
bottom?: number;
}
interface SortableHelperFunctionOption {
(event: JQueryEventObject, ui: ng.IAugmentedJQuery): JQuery;
}
interface SortableOptions<T> extends SortableEvents<T> {
/**
* jQuery, Element, Selector or string
* Default: "parent"
*/
appendTo?: any;
/**
* "X", "Y" or false
* Default: false
*/
axis?: string|boolean;
/**
* Selector
* Default: "input,textarea,button,select,option"
*/
cancel?: string;
/**
* Selector or false
* Default: false
*/
connectWith?: string|boolean;
/**
* Element, Selector, string or false
* Default: false
*/
containment?: any;
cursor?: string;
/**
* Moves the sorting element or helper so the cursor always appears to drag from the same position. Coordinates can be given as a hash using a combination of one or two keys SortableCursorAtOptions: { top, left, right, bottom }
* Default: false
*/
cursorAt?: SortableCursorAtOptions|boolean;
delay?: number;
disabled?: boolean;
distance?: number;
dropOnEmpty?: boolean;
forceHelperSize?: boolean;
forcePlaceholderSize?: boolean;
/**
* Array of numbers or false
* Default: false
*/
grid?: number[]|boolean;
/**
* Selector or Element
*/
handle?: any;
/**
* "original", "clone" or Function()
* Default: "original"
*/
helper?: string|SortableHelperFunctionOption;
/**
* Selector
*/
items?: string;
/**
* Number or false
* Default: false
*/
opacity?: number|boolean;
/**
* string or false
* Default: false
*/
placeholder?: string|boolean;
/**
* boolean or number
* Default: false
*/
revert?: number|boolean;
scroll?: boolean;
scrollSensitivity?: number;
scrollSpeed?: number;
/**
* "intersect" or "pointer"
* Default: "intersect"
*/
tolerance?: string;
zIndex?: number;
}
interface SortableUIParams {
helper: ng.IAugmentedJQuery;
item: ng.IAugmentedJQuery;
offset: any;
position: any;
originalPosition: any;
sender: ng.IAugmentedJQuery;
placeholder: ng.IAugmentedJQuery;
}
interface SortableEvent<T> {
(event: JQueryEventObject, ui: UISortableUIParams<T>): void;
}
interface SortableEvents<T> {
activate?: SortableEvent<T>;
beforeStop?: SortableEvent<T>;
change?: SortableEvent<T>;
deactivate?: SortableEvent<T>;
out?: SortableEvent<T>;
over?: SortableEvent<T>;
receive?: SortableEvent<T>;
remove?: SortableEvent<T>;
sort?: SortableEvent<T>;
start?: SortableEvent<T>;
stop?: SortableEvent<T>;
update?: SortableEvent<T>;
}
}