mirror of
https://github.com/NativeScript/NativeScript.git
synced 2025-08-18 05:18:39 +08:00
Merge branch 'origin/master'
This commit is contained in:
21
BCL.csproj
21
BCL.csproj
@ -241,6 +241,14 @@
|
|||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<TypeScriptCompile Include="ui\core\view.d.ts" />
|
<TypeScriptCompile Include="ui\core\view.d.ts" />
|
||||||
<TypeScriptCompile Include="ui\core\observable.ts" />
|
<TypeScriptCompile Include="ui\core\observable.ts" />
|
||||||
|
<TypeScriptCompile Include="ui\dialogs\dialogs.android.ts">
|
||||||
|
<DependentUpon>dialogs.d.ts</DependentUpon>
|
||||||
|
</TypeScriptCompile>
|
||||||
|
<TypeScriptCompile Include="ui\dialogs\dialogs.d.ts" />
|
||||||
|
<TypeScriptCompile Include="ui\dialogs\dialogs.ios.ts">
|
||||||
|
<DependentUpon>dialogs.d.ts</DependentUpon>
|
||||||
|
</TypeScriptCompile>
|
||||||
|
<TypeScriptCompile Include="ui\dialogs\index.ts" />
|
||||||
<Content Include="_references.ts" />
|
<Content Include="_references.ts" />
|
||||||
<Content Include="image-source\Readme.md" />
|
<Content Include="image-source\Readme.md" />
|
||||||
<Content Include="http\Readme.md" />
|
<Content Include="http\Readme.md" />
|
||||||
@ -259,6 +267,9 @@
|
|||||||
<Folder Include="Deploy\Full\" />
|
<Folder Include="Deploy\Full\" />
|
||||||
<Folder Include="Deploy\xCode\" />
|
<Folder Include="Deploy\xCode\" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
<ItemGroup>
|
||||||
|
<Content Include="ui\dialogs\Readme.md" />
|
||||||
|
</ItemGroup>
|
||||||
<PropertyGroup Condition="'$(Configuration)' == 'Full'">
|
<PropertyGroup Condition="'$(Configuration)' == 'Full'">
|
||||||
<TypeScriptModuleKind>commonjs</TypeScriptModuleKind>
|
<TypeScriptModuleKind>commonjs</TypeScriptModuleKind>
|
||||||
<TypeScriptRemoveComments>True</TypeScriptRemoveComments>
|
<TypeScriptRemoveComments>True</TypeScriptRemoveComments>
|
||||||
@ -351,7 +362,15 @@
|
|||||||
<UsingTask TaskName="BuildTasks.CopyForPlatformBuildTask" AssemblyFile="../../Build/lib/BuildTasks.dll" />
|
<UsingTask TaskName="BuildTasks.CopyForPlatformBuildTask" AssemblyFile="../../Build/lib/BuildTasks.dll" />
|
||||||
<Target Name="AfterBuild">
|
<Target Name="AfterBuild">
|
||||||
<CopyForPlatformBuildTask TargetPlatform="$(TargetOS)" IncludeTests="$(CopyTests)" Platforms="iOS;Android" InputFiles="@(GeneratedJavascript)" DestinationFolder="$(OutputPath)\$(Configuration)\" JSConfigFile="$(JSConfig)" AppMainJSFile="$(JSMainFile)" ProjectDir="$(ProjectDir)" />
|
<CopyForPlatformBuildTask TargetPlatform="$(TargetOS)" IncludeTests="$(CopyTests)" Platforms="iOS;Android" InputFiles="@(GeneratedJavascript)" DestinationFolder="$(OutputPath)\$(Configuration)\" JSConfigFile="$(JSConfig)" AppMainJSFile="$(JSMainFile)" ProjectDir="$(ProjectDir)" />
|
||||||
<Exec Condition=" '$(Configuration)' == 'Documentation'" Command="node ../../Documentation/Src/TypeScriptAPIExtractor/app.js @(TypeScriptCompile) $(IntermediateOutputPath)\api.xml" IgnoreExitCode="true" IgnoreStandardErrorWarningFormat="false" LogStandardErrorAsError="true" />
|
|
||||||
|
<Exec Condition=" '$(Configuration)' == 'Documentation' " Command='rd /q /s "../../Documentation/Docs/"' />
|
||||||
|
<Exec Condition=" '$(Configuration)' == 'Documentation' " Command='md "../../Documentation/Docs/"' />
|
||||||
|
|
||||||
|
<Exec Condition=" '$(Configuration)' == 'Documentation' " Command='node ../../Documentation/Src/SnippetsExtractor/app.js -noclean -source bin\Documentation\Tests -destination ../../Documentation/Docs/' />
|
||||||
|
|
||||||
|
<Exec Condition=" '$(Configuration)' == 'Documentation' " Command="node ../../Documentation/Src/TypeScriptAPIExtractor/app.js @(TypeScriptCompile) $(IntermediateOutputPath)\api.xml" IgnoreExitCode="true" IgnoreStandardErrorWarningFormat="false" LogStandardErrorAsError="true" />
|
||||||
|
<Exec Condition=" '$(Configuration)' == 'Documentation' " Command='"../../Documentation/Src/XMLAPIPrinting/bin/Release/XMLAPIPrinting.exe" $(IntermediateOutputPath)\api.xml "../../Documentation/Docs/"' />
|
||||||
|
|
||||||
</Target>
|
</Target>
|
||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
<PostBuildEvent>
|
<PostBuildEvent>
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
// <snippet name="application">
|
// <snippet name="application/HOW-TO">
|
||||||
// # Application
|
// # Application
|
||||||
// The Application module provides abstraction over the platform-specific Application implementations.
|
// The Application module provides abstraction over the platform-specific Application implementations.
|
||||||
// It is the main BCL module and is required for other BCL modules to work properly.
|
// It is the main BCL module and is required for other BCL modules to work properly.
|
||||||
@ -9,7 +9,7 @@ import app = require("application");
|
|||||||
// The pre-required `app` module is used throughout the following code snippets.
|
// The pre-required `app` module is used throughout the following code snippets.
|
||||||
// </snippet>
|
// </snippet>
|
||||||
|
|
||||||
// <snippet name="application">
|
// <snippet name="application/HOW-TO">
|
||||||
// ### Initialization
|
// ### Initialization
|
||||||
// ``` JavaScript
|
// ``` JavaScript
|
||||||
//// The native app instance depends on the target platform
|
//// The native app instance depends on the target platform
|
||||||
@ -18,7 +18,7 @@ app.init(nativeAppInstance);
|
|||||||
// ```
|
// ```
|
||||||
// </snippet>
|
// </snippet>
|
||||||
|
|
||||||
// <snippet name="application">
|
// <snippet name="application/HOW-TO">
|
||||||
// ### Checking the target platform
|
// ### Checking the target platform
|
||||||
// Use the following code in case you need to check somewhere in your code the platform you are running against:
|
// Use the following code in case you need to check somewhere in your code the platform you are running against:
|
||||||
// ``` JavaScript
|
// ``` JavaScript
|
||||||
|
@ -6,7 +6,7 @@ import commonTests = require("Tests/application-tests-common");
|
|||||||
declare var exports;
|
declare var exports;
|
||||||
require("utils/module-merge").merge(commonTests, exports);
|
require("utils/module-merge").merge(commonTests, exports);
|
||||||
|
|
||||||
// <snippet name="application">
|
// <snippet name="application/HOW-TO">
|
||||||
// ### Using the Android-specific implementation
|
// ### Using the Android-specific implementation
|
||||||
// Accessing the Android-specific object instance (will be undefined if running on iOS)
|
// Accessing the Android-specific object instance (will be undefined if running on iOS)
|
||||||
// ``` JavaScript
|
// ``` JavaScript
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
|
|
||||||
// <snippet name="file-system">
|
// <snippet name="file-system/HOW-TO">
|
||||||
// # File System
|
// # File System
|
||||||
// Using the file system requires the FileSystem module.
|
// Using the file system requires the FileSystem module.
|
||||||
// ``` JavaScript
|
// ``` JavaScript
|
||||||
@ -10,12 +10,12 @@ import fs = require("file-system");
|
|||||||
|
|
||||||
import TKUnit = require("Tests/TKUnit");
|
import TKUnit = require("Tests/TKUnit");
|
||||||
|
|
||||||
// <snippet name="file-system">
|
// <snippet name="file-system/HOW-TO">
|
||||||
// ## Path
|
// ## Path
|
||||||
// </snippet>
|
// </snippet>
|
||||||
|
|
||||||
export var testPathNormalize = function () {
|
export var testPathNormalize = function () {
|
||||||
// <snippet name="file-system">
|
// <snippet name="file-system/HOW-TO">
|
||||||
// ### Normalize a Path
|
// ### Normalize a Path
|
||||||
// ``` JavaScript
|
// ``` JavaScript
|
||||||
var documents = fs.knownFolders.documents();
|
var documents = fs.knownFolders.documents();
|
||||||
@ -31,7 +31,7 @@ export var testPathNormalize = function () {
|
|||||||
};
|
};
|
||||||
|
|
||||||
export var testPathJoin = function () {
|
export var testPathJoin = function () {
|
||||||
// <snippet name="file-system">
|
// <snippet name="file-system/HOW-TO">
|
||||||
// ### Path Join
|
// ### Path Join
|
||||||
// Concatinate a path to a file by providing multiple path arguments.
|
// Concatinate a path to a file by providing multiple path arguments.
|
||||||
// ``` JavaScript
|
// ``` JavaScript
|
||||||
@ -47,7 +47,7 @@ export var testPathJoin = function () {
|
|||||||
};
|
};
|
||||||
|
|
||||||
export var testPathSeparator = function () {
|
export var testPathSeparator = function () {
|
||||||
// <snippet name="file-system">
|
// <snippet name="file-system/HOW-TO">
|
||||||
// ### Get the Path Separator
|
// ### Get the Path Separator
|
||||||
// ``` JavaScript
|
// ``` JavaScript
|
||||||
//// An OS dependant path separator, "\" or "/".
|
//// An OS dependant path separator, "\" or "/".
|
||||||
@ -61,7 +61,7 @@ export var testPathSeparator = function () {
|
|||||||
};
|
};
|
||||||
|
|
||||||
export var testFileFromPath = function () {
|
export var testFileFromPath = function () {
|
||||||
// <snippet name="file-system">
|
// <snippet name="file-system/HOW-TO">
|
||||||
// ### Get or Create a File With Path
|
// ### Get or Create a File With Path
|
||||||
// The following example writes some text to a file created for path.
|
// The following example writes some text to a file created for path.
|
||||||
// It will create a new file or overwrite an existing file.
|
// It will create a new file or overwrite an existing file.
|
||||||
@ -98,7 +98,7 @@ export var testFileFromPath = function () {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export var testFolderFromPath = function () {
|
export var testFolderFromPath = function () {
|
||||||
// <snippet name="file-system">
|
// <snippet name="file-system/HOW-TO">
|
||||||
// ### Get or Create a Folder With Path
|
// ### Get or Create a Folder With Path
|
||||||
// ``` JavaScript
|
// ``` JavaScript
|
||||||
var path = fs.path.join(fs.knownFolders.documents().path, "music");
|
var path = fs.path.join(fs.knownFolders.documents().path, "music");
|
||||||
@ -112,12 +112,12 @@ export var testFolderFromPath = function () {
|
|||||||
// </snippet>
|
// </snippet>
|
||||||
}
|
}
|
||||||
|
|
||||||
// <snippet name="file-system">
|
// <snippet name="file-system/HOW-TO">
|
||||||
// ## Create
|
// ## Create
|
||||||
// </snippet>
|
// </snippet>
|
||||||
|
|
||||||
export var testFileWrite = function () {
|
export var testFileWrite = function () {
|
||||||
// <snippet name="file-system">
|
// <snippet name="file-system/HOW-TO">
|
||||||
// ### Writing a string to a File
|
// ### Writing a string to a File
|
||||||
// The following example writes some text to a file.
|
// The following example writes some text to a file.
|
||||||
// It will create a new file or overwrite an existing file.
|
// It will create a new file or overwrite an existing file.
|
||||||
@ -153,7 +153,7 @@ export var testFileWrite = function () {
|
|||||||
};
|
};
|
||||||
|
|
||||||
export var testGetFile = function () {
|
export var testGetFile = function () {
|
||||||
// <snippet name="file-system">
|
// <snippet name="file-system/HOW-TO">
|
||||||
// ### Get or Create a File
|
// ### Get or Create a File
|
||||||
// ``` JavaScript
|
// ``` JavaScript
|
||||||
var documents = fs.knownFolders.documents();
|
var documents = fs.knownFolders.documents();
|
||||||
@ -168,7 +168,7 @@ export var testGetFile = function () {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export var testGetFolder = function () {
|
export var testGetFolder = function () {
|
||||||
// <snippet name="file-system">
|
// <snippet name="file-system/HOW-TO">
|
||||||
// ### Get or Create a Folder
|
// ### Get or Create a Folder
|
||||||
// ``` JavaScript
|
// ``` JavaScript
|
||||||
var documents = fs.knownFolders.documents();
|
var documents = fs.knownFolders.documents();
|
||||||
@ -182,12 +182,12 @@ export var testGetFolder = function () {
|
|||||||
// </snippet>
|
// </snippet>
|
||||||
};
|
};
|
||||||
|
|
||||||
// <snippet name="file-system">
|
// <snippet name="file-system/HOW-TO">
|
||||||
// ## Read
|
// ## Read
|
||||||
// </snippet>
|
// </snippet>
|
||||||
|
|
||||||
export var testFileRead = function () {
|
export var testFileRead = function () {
|
||||||
// <snippet name="file-system">
|
// <snippet name="file-system/HOW-TO">
|
||||||
// ### Reading from a File
|
// ### Reading from a File
|
||||||
// The following example writes some text to a file and then reads it back.
|
// The following example writes some text to a file and then reads it back.
|
||||||
// ``` JavaScript
|
// ``` JavaScript
|
||||||
@ -230,7 +230,7 @@ export var testFileRead = function () {
|
|||||||
};
|
};
|
||||||
|
|
||||||
export var testGetKnownFolders = function () {
|
export var testGetKnownFolders = function () {
|
||||||
// <snippet name="file-system">
|
// <snippet name="file-system/HOW-TO">
|
||||||
// ### Getting the Known Folders
|
// ### Getting the Known Folders
|
||||||
// Each app has several well known folders. This is how to access them:
|
// Each app has several well known folders. This is how to access them:
|
||||||
// ``` JavaScript
|
// ``` JavaScript
|
||||||
@ -251,7 +251,7 @@ export var testGetKnownFolders = function () {
|
|||||||
};
|
};
|
||||||
|
|
||||||
export var testGetEntities = function () {
|
export var testGetEntities = function () {
|
||||||
// <snippet name="file-system">
|
// <snippet name="file-system/HOW-TO">
|
||||||
// ### Getting Folder Contents
|
// ### Getting Folder Contents
|
||||||
// Getting all files and folders within a folder:
|
// Getting all files and folders within a folder:
|
||||||
// ``` JavaScript
|
// ``` JavaScript
|
||||||
@ -300,7 +300,7 @@ export var testGetEntities = function () {
|
|||||||
};
|
};
|
||||||
|
|
||||||
export var testEnumEntities = function () {
|
export var testEnumEntities = function () {
|
||||||
// <snippet name="file-system">
|
// <snippet name="file-system/HOW-TO">
|
||||||
// ### Enumerating Folder Contents
|
// ### Enumerating Folder Contents
|
||||||
// Getting all folder entities in array may be slow with large number of files.
|
// Getting all folder entities in array may be slow with large number of files.
|
||||||
// Enumerating the folder entities would itterate the files one by one without blocking the UI.
|
// Enumerating the folder entities would itterate the files one by one without blocking the UI.
|
||||||
@ -338,7 +338,7 @@ export var testEnumEntities = function () {
|
|||||||
};
|
};
|
||||||
|
|
||||||
export var testGetParent = function () {
|
export var testGetParent = function () {
|
||||||
// <snippet name="file-system">
|
// <snippet name="file-system/HOW-TO">
|
||||||
// ### Getting Parent Folder
|
// ### Getting Parent Folder
|
||||||
// ``` JavaScript
|
// ``` JavaScript
|
||||||
var documents = fs.knownFolders.documents();
|
var documents = fs.knownFolders.documents();
|
||||||
@ -357,7 +357,7 @@ export var testGetParent = function () {
|
|||||||
};
|
};
|
||||||
|
|
||||||
export var testFileNameExtension = function () {
|
export var testFileNameExtension = function () {
|
||||||
// <snippet name="file-system">
|
// <snippet name="file-system/HOW-TO">
|
||||||
// ### Getting File Name and Extension
|
// ### Getting File Name and Extension
|
||||||
// ``` JavaScript
|
// ``` JavaScript
|
||||||
var documents = fs.knownFolders.documents();
|
var documents = fs.knownFolders.documents();
|
||||||
@ -376,7 +376,7 @@ export var testFileNameExtension = function () {
|
|||||||
};
|
};
|
||||||
|
|
||||||
export var testFileExists = function () {
|
export var testFileExists = function () {
|
||||||
// <snippet name="file-system">
|
// <snippet name="file-system/HOW-TO">
|
||||||
// ### Checking if a File Exists
|
// ### Checking if a File Exists
|
||||||
// ``` JavaScript
|
// ``` JavaScript
|
||||||
var documents = fs.knownFolders.documents();
|
var documents = fs.knownFolders.documents();
|
||||||
@ -393,7 +393,7 @@ export var testFileExists = function () {
|
|||||||
};
|
};
|
||||||
|
|
||||||
export var testFolderExists = function () {
|
export var testFolderExists = function () {
|
||||||
// <snippet name="file-system">
|
// <snippet name="file-system/HOW-TO">
|
||||||
// ### Checking if a Folder Exists
|
// ### Checking if a Folder Exists
|
||||||
// ``` JavaScript
|
// ``` JavaScript
|
||||||
var documents = fs.knownFolders.documents();
|
var documents = fs.knownFolders.documents();
|
||||||
@ -419,12 +419,12 @@ export var testContainsFile = function () {
|
|||||||
file.remove();
|
file.remove();
|
||||||
};
|
};
|
||||||
|
|
||||||
// <snippet name="file-system">
|
// <snippet name="file-system/HOW-TO">
|
||||||
// ## Update
|
// ## Update
|
||||||
// </snippet>
|
// </snippet>
|
||||||
|
|
||||||
export var testFileRename = function () {
|
export var testFileRename = function () {
|
||||||
// <snippet name="file-system">
|
// <snippet name="file-system/HOW-TO">
|
||||||
// ### Renaming a File
|
// ### Renaming a File
|
||||||
// ``` JavaScript
|
// ``` JavaScript
|
||||||
var documents = fs.knownFolders.documents();
|
var documents = fs.knownFolders.documents();
|
||||||
@ -450,7 +450,7 @@ export var testFileRename = function () {
|
|||||||
};
|
};
|
||||||
|
|
||||||
export var testFolderRename = function () {
|
export var testFolderRename = function () {
|
||||||
// <snippet name="file-system">
|
// <snippet name="file-system/HOW-TO">
|
||||||
// ### Renaming a Folder
|
// ### Renaming a Folder
|
||||||
// ``` JavaScript
|
// ``` JavaScript
|
||||||
var folder = fs.knownFolders.documents();
|
var folder = fs.knownFolders.documents();
|
||||||
@ -475,12 +475,12 @@ export var testFolderRename = function () {
|
|||||||
// </snippet>
|
// </snippet>
|
||||||
};
|
};
|
||||||
|
|
||||||
// <snippet name="file-system">
|
// <snippet name="file-system/HOW-TO">
|
||||||
// ## Delete
|
// ## Delete
|
||||||
// </snippet>
|
// </snippet>
|
||||||
|
|
||||||
export var testFileRemove = function () {
|
export var testFileRemove = function () {
|
||||||
// <snippet name="file-system">
|
// <snippet name="file-system/HOW-TO">
|
||||||
// ### Removing a File
|
// ### Removing a File
|
||||||
// To 'delete', 'remove' or 'unlink' a file use the file's remove method:
|
// To 'delete', 'remove' or 'unlink' a file use the file's remove method:
|
||||||
// ``` JavaScript
|
// ``` JavaScript
|
||||||
@ -504,7 +504,7 @@ export var testFileRemove = function () {
|
|||||||
};
|
};
|
||||||
|
|
||||||
export var testFolderRemove = function () {
|
export var testFolderRemove = function () {
|
||||||
// <snippet name="file-system">
|
// <snippet name="file-system/HOW-TO">
|
||||||
// ### Removing a Folder
|
// ### Removing a Folder
|
||||||
// ``` JavaScript
|
// ``` JavaScript
|
||||||
var documents = fs.knownFolders.documents();
|
var documents = fs.knownFolders.documents();
|
||||||
@ -528,7 +528,7 @@ export var testFolderRemove = function () {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export var testFolderClear = function () {
|
export var testFolderClear = function () {
|
||||||
// <snippet name="file-system">
|
// <snippet name="file-system/HOW-TO">
|
||||||
// ### Clearing the Contents of a Folder
|
// ### Clearing the Contents of a Folder
|
||||||
// The clear method removes all files within a folder.
|
// The clear method removes all files within a folder.
|
||||||
// ``` JavaScript
|
// ``` JavaScript
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
import http = require("http");
|
import http = require("http");
|
||||||
require("globals");
|
require("globals");
|
||||||
|
|
||||||
// <snippet name="http">
|
// <snippet name="http/HOW-TO">
|
||||||
// # Http module
|
// # Http module
|
||||||
// ``` JavaScript
|
// ``` JavaScript
|
||||||
// var http = require("http");
|
// var http = require("http");
|
||||||
@ -18,7 +18,7 @@ export var test_getString = function () {
|
|||||||
var completed: boolean;
|
var completed: boolean;
|
||||||
var isReady = function () { return completed; }
|
var isReady = function () { return completed; }
|
||||||
|
|
||||||
// <snippet name="http">
|
// <snippet name="http/HOW-TO">
|
||||||
// ### Get string from URL
|
// ### Get string from URL
|
||||||
// ``` JavaScript
|
// ``` JavaScript
|
||||||
http.getString("http://httpbin.org/get").then(function (r) {
|
http.getString("http://httpbin.org/get").then(function (r) {
|
||||||
@ -61,7 +61,7 @@ export var test_getJSON = function () {
|
|||||||
var completed: boolean;
|
var completed: boolean;
|
||||||
var isReady = function () { return completed; }
|
var isReady = function () { return completed; }
|
||||||
|
|
||||||
// <snippet name="http">
|
// <snippet name="http/HOW-TO">
|
||||||
// ### Get JSON from URL
|
// ### Get JSON from URL
|
||||||
// ``` JavaScript
|
// ``` JavaScript
|
||||||
http.getJSON("http://httpbin.org/get").then(function (r) {
|
http.getJSON("http://httpbin.org/get").then(function (r) {
|
||||||
@ -104,7 +104,7 @@ export var test_getImage = function () {
|
|||||||
var completed: boolean;
|
var completed: boolean;
|
||||||
var isReady = function () { return completed; }
|
var isReady = function () { return completed; }
|
||||||
|
|
||||||
// <snippet name="http">
|
// <snippet name="http/HOW-TO">
|
||||||
// ### Get Image from URL
|
// ### Get Image from URL
|
||||||
// ``` JavaScript
|
// ``` JavaScript
|
||||||
http.getImage("http://www.google.com/images/errors/logo_sm_2.png").then(function (r) {
|
http.getImage("http://www.google.com/images/errors/logo_sm_2.png").then(function (r) {
|
||||||
@ -161,7 +161,7 @@ export var test_request_responseStatusCodeShouldBeDefined = function () {
|
|||||||
var completed: boolean;
|
var completed: boolean;
|
||||||
var isReady = function () { return completed; }
|
var isReady = function () { return completed; }
|
||||||
|
|
||||||
// <snippet name="http">
|
// <snippet name="http/HOW-TO">
|
||||||
// ### Get response status code
|
// ### Get response status code
|
||||||
// ``` JavaScript
|
// ``` JavaScript
|
||||||
http.request({ url: "http://httpbin.org/get", method: "GET" }).then(function (response) {
|
http.request({ url: "http://httpbin.org/get", method: "GET" }).then(function (response) {
|
||||||
@ -187,7 +187,7 @@ export var test_request_responseHeadersShouldBeDefined = function () {
|
|||||||
var completed: boolean;
|
var completed: boolean;
|
||||||
var isReady = function () { return completed; }
|
var isReady = function () { return completed; }
|
||||||
|
|
||||||
// <snippet name="http">
|
// <snippet name="http/HOW-TO">
|
||||||
// ### Get response headers
|
// ### Get response headers
|
||||||
// ``` JavaScript
|
// ``` JavaScript
|
||||||
http.request({ url: "http://httpbin.org/get", method: "GET" }).then(function (response) {
|
http.request({ url: "http://httpbin.org/get", method: "GET" }).then(function (response) {
|
||||||
@ -215,7 +215,7 @@ export var test_request_responseContentShouldBeDefined = function () {
|
|||||||
var completed: boolean;
|
var completed: boolean;
|
||||||
var isReady = function () { return completed; }
|
var isReady = function () { return completed; }
|
||||||
|
|
||||||
// <snippet name="http">
|
// <snippet name="http/HOW-TO">
|
||||||
// ### Get response content
|
// ### Get response content
|
||||||
// ``` JavaScript
|
// ``` JavaScript
|
||||||
http.request({ url: "http://httpbin.org/get", method: "GET" }).then(function (response) {
|
http.request({ url: "http://httpbin.org/get", method: "GET" }).then(function (response) {
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
// <snippet name="image-source">
|
// <snippet name="image-source/HOW-TO">
|
||||||
// # Image source
|
// # Image source
|
||||||
// Using the image source requires the image-source module.
|
// Using the image source requires the image-source module.
|
||||||
// ``` JavaScript
|
// ``` JavaScript
|
||||||
@ -18,7 +18,7 @@ import app = require("application");
|
|||||||
import TKUnit = require("Tests/TKUnit");
|
import TKUnit = require("Tests/TKUnit");
|
||||||
|
|
||||||
export var testFromResource = function () {
|
export var testFromResource = function () {
|
||||||
// <snippet name="image-source">
|
// <snippet name="image-source/HOW-TO">
|
||||||
// ### Load image using resource name
|
// ### Load image using resource name
|
||||||
// This is similar to loading Bitmap from `R.drawable.logo` on Android or calling `[UIImage imageNamed@"logo"]` on iOS
|
// This is similar to loading Bitmap from `R.drawable.logo` on Android or calling `[UIImage imageNamed@"logo"]` on iOS
|
||||||
// ``` JavaScript
|
// ``` JavaScript
|
||||||
@ -32,7 +32,7 @@ export var testFromUrl = function () {
|
|||||||
var completed;
|
var completed;
|
||||||
var result: imageSource.ImageSource;
|
var result: imageSource.ImageSource;
|
||||||
|
|
||||||
// <snippet name="image-source">
|
// <snippet name="image-source/HOW-TO">
|
||||||
// ### Load image from URL
|
// ### Load image from URL
|
||||||
// ``` JavaScript
|
// ``` JavaScript
|
||||||
imageSource.fromUrl("http://www.google.com/images/errors/logo_sm_2.png")
|
imageSource.fromUrl("http://www.google.com/images/errors/logo_sm_2.png")
|
||||||
@ -62,7 +62,7 @@ export var testFromUrl = function () {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export var testSaveToFile = function () {
|
export var testSaveToFile = function () {
|
||||||
// <snippet name="image-source">
|
// <snippet name="image-source/HOW-TO">
|
||||||
// ### Save image source to PNG or JPG file
|
// ### Save image source to PNG or JPG file
|
||||||
// ``` JavaScript
|
// ``` JavaScript
|
||||||
var img = imageSource.fromResource("logo");
|
var img = imageSource.fromResource("logo");
|
||||||
@ -76,7 +76,7 @@ export var testSaveToFile = function () {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export var testFromFile = function () {
|
export var testFromFile = function () {
|
||||||
// <snippet name="image-source">
|
// <snippet name="image-source/HOW-TO">
|
||||||
// ### Load image from a local file
|
// ### Load image from a local file
|
||||||
// ``` JavaScript
|
// ``` JavaScript
|
||||||
var folder = fs.knownFolders.documents();
|
var folder = fs.knownFolders.documents();
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
// <snippet name="local-settings">
|
// <snippet name="local-settings/HOW-TO">
|
||||||
// # Local Settings
|
// # Local Settings
|
||||||
// ``` JavaScript
|
// ``` JavaScript
|
||||||
var LocalSettings = require("local-settings");
|
var LocalSettings = require("local-settings");
|
||||||
@ -13,7 +13,7 @@ var noStringKey: string = "noStringKey";
|
|||||||
var noBoolKey: string = "noBoolKey";
|
var noBoolKey: string = "noBoolKey";
|
||||||
var noNumberKey: string = "noNumberKey";
|
var noNumberKey: string = "noNumberKey";
|
||||||
|
|
||||||
// <snippet name="local-settings">
|
// <snippet name="local-settings/HOW-TO">
|
||||||
// ## Working with string, number and boolean values
|
// ## Working with string, number and boolean values
|
||||||
// </snippet>
|
// </snippet>
|
||||||
|
|
||||||
@ -22,7 +22,7 @@ export var testBoolean = function () {
|
|||||||
var boolValue = LocalSettings.getBoolean(boolKey);
|
var boolValue = LocalSettings.getBoolean(boolKey);
|
||||||
TKUnit.assert(false == boolValue, "Cannot set boolean to false, currently it is: " + LocalSettings.getBoolean(boolKey));
|
TKUnit.assert(false == boolValue, "Cannot set boolean to false, currently it is: " + LocalSettings.getBoolean(boolKey));
|
||||||
|
|
||||||
// <snippet name="local-settings">
|
// <snippet name="local-settings/HOW-TO">
|
||||||
// ### Set and get boolean value and provide default value in case it is not set
|
// ### Set and get boolean value and provide default value in case it is not set
|
||||||
// ``` JavaScript
|
// ``` JavaScript
|
||||||
LocalSettings.setBoolean("boolKey", true);
|
LocalSettings.setBoolean("boolKey", true);
|
||||||
@ -35,7 +35,7 @@ export var testBoolean = function () {
|
|||||||
};
|
};
|
||||||
|
|
||||||
export var testString = function () {
|
export var testString = function () {
|
||||||
// <snippet name="local-settings">
|
// <snippet name="local-settings/HOW-TO">
|
||||||
// ### Set and get string value
|
// ### Set and get string value
|
||||||
// ``` JavaScript
|
// ``` JavaScript
|
||||||
LocalSettings.setString("stringKey", "String value");
|
LocalSettings.setString("stringKey", "String value");
|
||||||
@ -46,7 +46,7 @@ export var testString = function () {
|
|||||||
};
|
};
|
||||||
|
|
||||||
export var testNumber = function () {
|
export var testNumber = function () {
|
||||||
// <snippet name="local-settings">
|
// <snippet name="local-settings/HOW-TO">
|
||||||
// ### Set and get numeric value.
|
// ### Set and get numeric value.
|
||||||
// We use `toFixed()` here in order to avoid floating point errors - ex: `54.321` becoming `54.320999999537`.
|
// We use `toFixed()` here in order to avoid floating point errors - ex: `54.321` becoming `54.320999999537`.
|
||||||
// Beware the result of `toFixed()` is a string not a number therefore you cannot use `===` or `!==` when comparing with a number.
|
// Beware the result of `toFixed()` is a string not a number therefore you cannot use `===` or `!==` when comparing with a number.
|
||||||
@ -59,7 +59,7 @@ export var testNumber = function () {
|
|||||||
};
|
};
|
||||||
|
|
||||||
export var testDefaults = function () {
|
export var testDefaults = function () {
|
||||||
// <snippet name="local-settings">
|
// <snippet name="local-settings/HOW-TO">
|
||||||
// ### Reading values that are not set before while providing default value
|
// ### Reading values that are not set before while providing default value
|
||||||
// ``` JavaScript
|
// ``` JavaScript
|
||||||
var defaultValue = LocalSettings.getString("noStringKey", "No string value");
|
var defaultValue = LocalSettings.getString("noStringKey", "No string value");
|
||||||
@ -70,7 +70,7 @@ export var testDefaults = function () {
|
|||||||
TKUnit.assert(true === LocalSettings.getBoolean(noBoolKey, true), "Bad default boolean value");
|
TKUnit.assert(true === LocalSettings.getBoolean(noBoolKey, true), "Bad default boolean value");
|
||||||
TKUnit.assert(123.45 === LocalSettings.getNumber(noNumberKey, 123.45), "Bad default number value");
|
TKUnit.assert(123.45 === LocalSettings.getNumber(noNumberKey, 123.45), "Bad default number value");
|
||||||
|
|
||||||
// <snippet name="local-settings">
|
// <snippet name="local-settings/HOW-TO">
|
||||||
// ### Reading values that are not set before not providing default value
|
// ### Reading values that are not set before not providing default value
|
||||||
// ``` JavaScript
|
// ``` JavaScript
|
||||||
var defaultValue = LocalSettings.getString("noStringKey");
|
var defaultValue = LocalSettings.getString("noStringKey");
|
||||||
@ -83,12 +83,12 @@ export var testDefaults = function () {
|
|||||||
TKUnit.assert("undefined" === typeof LocalSettings.getNumber(noNumberKey), "Default number value is not undefined");
|
TKUnit.assert("undefined" === typeof LocalSettings.getNumber(noNumberKey), "Default number value is not undefined");
|
||||||
};
|
};
|
||||||
|
|
||||||
// <snippet name="local-settings">
|
// <snippet name="local-settings/HOW-TO">
|
||||||
// ## Other functions
|
// ## Other functions
|
||||||
// </snippet>
|
// </snippet>
|
||||||
|
|
||||||
export var testHasKey = function () {
|
export var testHasKey = function () {
|
||||||
// <snippet name="local-settings">
|
// <snippet name="local-settings/HOW-TO">
|
||||||
// ### Checking for existence of value for key
|
// ### Checking for existence of value for key
|
||||||
// ``` JavaScript
|
// ``` JavaScript
|
||||||
var hasKey = LocalSettings.hasKey("noBoolKey");
|
var hasKey = LocalSettings.hasKey("noBoolKey");
|
||||||
@ -105,7 +105,7 @@ export var testHasKey = function () {
|
|||||||
};
|
};
|
||||||
|
|
||||||
export var testRemove = function () {
|
export var testRemove = function () {
|
||||||
// <snippet name="local-settings">
|
// <snippet name="local-settings/HOW-TO">
|
||||||
// ### Removing value for key
|
// ### Removing value for key
|
||||||
// ``` JavaScript
|
// ``` JavaScript
|
||||||
LocalSettings.remove("boolKey");
|
LocalSettings.remove("boolKey");
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
// <snippet name="location">
|
// <snippet name="location/HOW-TO">
|
||||||
// # Location
|
// # Location
|
||||||
// Using the location requires the Location module.
|
// Using the location requires the Location module.
|
||||||
// ``` JavaScript
|
// ``` JavaScript
|
||||||
@ -12,12 +12,12 @@ import locationModule = require("location");
|
|||||||
var LocationManager = locationModule.LocationManager;
|
var LocationManager = locationModule.LocationManager;
|
||||||
var Location = locationModule.Location;
|
var Location = locationModule.Location;
|
||||||
|
|
||||||
// <snippet name="location">
|
// <snippet name="location/HOW-TO">
|
||||||
// ## Other functions
|
// ## Other functions
|
||||||
// </snippet>
|
// </snippet>
|
||||||
|
|
||||||
export var testIsEnabled = function () {
|
export var testIsEnabled = function () {
|
||||||
// <snippet name="location">
|
// <snippet name="location/HOW-TO">
|
||||||
// ### Test are location services available for this device
|
// ### Test are location services available for this device
|
||||||
// ``` JavaScript
|
// ``` JavaScript
|
||||||
var isEnabled = LocationManager.isEnabled();
|
var isEnabled = LocationManager.isEnabled();
|
||||||
@ -27,7 +27,7 @@ export var testIsEnabled = function () {
|
|||||||
};
|
};
|
||||||
|
|
||||||
export var testDistance = function () {
|
export var testDistance = function () {
|
||||||
// <snippet name="location">
|
// <snippet name="location/HOW-TO">
|
||||||
// ### Get distance between two locations
|
// ### Get distance between two locations
|
||||||
// ``` JavaScript
|
// ``` JavaScript
|
||||||
//var Location = require("location").Location;
|
//var Location = require("location").Location;
|
||||||
@ -43,14 +43,14 @@ export var testDistance = function () {
|
|||||||
TKUnit.assert((distance > 10780000) && (distance < 10860000), "invalid distance " + distance);
|
TKUnit.assert((distance > 10780000) && (distance < 10860000), "invalid distance " + distance);
|
||||||
};
|
};
|
||||||
|
|
||||||
// <snippet name="location">
|
// <snippet name="location/HOW-TO">
|
||||||
// ## Getting location
|
// ## Getting location
|
||||||
// </snippet>
|
// </snippet>
|
||||||
|
|
||||||
export var testLocation = function () {
|
export var testLocation = function () {
|
||||||
var locationReceived;
|
var locationReceived;
|
||||||
|
|
||||||
// <snippet name="location">
|
// <snippet name="location/HOW-TO">
|
||||||
// ### Receive continuous location updates
|
// ### Receive continuous location updates
|
||||||
// ``` JavaScript
|
// ``` JavaScript
|
||||||
var locationManager = new LocationManager();
|
var locationManager = new LocationManager();
|
||||||
@ -83,7 +83,7 @@ export var testLocation = function () {
|
|||||||
|
|
||||||
export var testLastKnownLocation = function () {
|
export var testLastKnownLocation = function () {
|
||||||
TKUnit.waitUntilReady(function () { return false; }, 1); // give it some time after the last test
|
TKUnit.waitUntilReady(function () { return false; }, 1); // give it some time after the last test
|
||||||
// <snippet name="location">
|
// <snippet name="location/HOW-TO">
|
||||||
// ### Get last known location
|
// ### Get last known location
|
||||||
// ``` JavaScript
|
// ``` JavaScript
|
||||||
var locationManager = new LocationManager();
|
var locationManager = new LocationManager();
|
||||||
@ -135,7 +135,7 @@ export var testLocationOnceTimeout10000 = function () {
|
|||||||
|
|
||||||
export var testSnippet = function () {
|
export var testSnippet = function () {
|
||||||
var locationReceived;
|
var locationReceived;
|
||||||
// <snippet name="location">
|
// <snippet name="location/HOW-TO">
|
||||||
// ### Get location once
|
// ### Get location once
|
||||||
// if there is `options.timeout` you will receive error on timeout. If `options.timeout` is 0 then the result is the same as the result from `LocationManager.lastKnownLocation`
|
// if there is `options.timeout` you will receive error on timeout. If `options.timeout` is 0 then the result is the same as the result from `LocationManager.lastKnownLocation`
|
||||||
// and there will be no wait. You can use `options.maximumAge` to specify you don't want to receive locations older than specified time in ms.
|
// and there will be no wait. You can use `options.maximumAge` to specify you don't want to receive locations older than specified time in ms.
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
import TKUnit = require("Tests/TKUnit");
|
import TKUnit = require("Tests/TKUnit");
|
||||||
var timer = require("timer/timer");
|
var timer = require("timer/timer");
|
||||||
|
|
||||||
// <snippet name="timer">
|
// <snippet name="timer/HOW-TO">
|
||||||
// # Timer module
|
// # Timer module
|
||||||
// ``` JavaScript
|
// ``` JavaScript
|
||||||
// require("globals");
|
// require("globals");
|
||||||
@ -30,7 +30,7 @@ export var test_setTimeout = function () {
|
|||||||
var completed: boolean;
|
var completed: boolean;
|
||||||
var isReady = function () { return completed; }
|
var isReady = function () { return completed; }
|
||||||
|
|
||||||
// <snippet name="timer">
|
// <snippet name="timer/HOW-TO">
|
||||||
// ### Evaluates an expression after 0 milliseconds.
|
// ### Evaluates an expression after 0 milliseconds.
|
||||||
// ``` JavaScript
|
// ``` JavaScript
|
||||||
timer.setTimeout(function () {
|
timer.setTimeout(function () {
|
||||||
@ -49,7 +49,7 @@ export var test_setTimeout_callbackCalledAfterSpecifedTime = function () {
|
|||||||
var completed: boolean;
|
var completed: boolean;
|
||||||
var isReady = function () { return completed; }
|
var isReady = function () { return completed; }
|
||||||
|
|
||||||
// <snippet name="timer">
|
// <snippet name="timer/HOW-TO">
|
||||||
// ### Evaluates an expression after a specified number of milliseconds.
|
// ### Evaluates an expression after a specified number of milliseconds.
|
||||||
// ``` JavaScript
|
// ``` JavaScript
|
||||||
timer.setTimeout(function () {
|
timer.setTimeout(function () {
|
||||||
@ -85,7 +85,7 @@ export var test_setTimeout_callbackShouldBeCleared = function () {
|
|||||||
var completed: boolean;
|
var completed: boolean;
|
||||||
var isReady = function () { return completed; }
|
var isReady = function () { return completed; }
|
||||||
|
|
||||||
// <snippet name="timer">
|
// <snippet name="timer/HOW-TO">
|
||||||
// ### Cancels the evaluation with the clearTimeout method.
|
// ### Cancels the evaluation with the clearTimeout method.
|
||||||
// ``` JavaScript
|
// ``` JavaScript
|
||||||
var id = timer.setTimeout(function () {
|
var id = timer.setTimeout(function () {
|
||||||
@ -109,7 +109,7 @@ export var test_setInterval_callbackCalledDuringPeriod = function () {
|
|||||||
var expected = 4;
|
var expected = 4;
|
||||||
var isReady = function () { return counter >= expected; }
|
var isReady = function () { return counter >= expected; }
|
||||||
|
|
||||||
// <snippet name="timer">
|
// <snippet name="timer/HOW-TO">
|
||||||
// ### Evaluates an expression each time a specified number of milliseconds has elapsed.
|
// ### Evaluates an expression each time a specified number of milliseconds has elapsed.
|
||||||
// ``` JavaScript
|
// ``` JavaScript
|
||||||
timer.setInterval(function () {
|
timer.setInterval(function () {
|
||||||
@ -129,7 +129,7 @@ export var test_setInterval_callbackShouldBeCleared = function () {
|
|||||||
var expected = 1;
|
var expected = 1;
|
||||||
var isReady = function () { return counter == expected; }
|
var isReady = function () { return counter == expected; }
|
||||||
|
|
||||||
// <snippet name="timer">
|
// <snippet name="timer/HOW-TO">
|
||||||
// ### Cancel the interval previously started using the setInterval method.
|
// ### Cancel the interval previously started using the setInterval method.
|
||||||
// ``` JavaScript
|
// ``` JavaScript
|
||||||
var id = timer.setInterval(function () {
|
var id = timer.setInterval(function () {
|
||||||
|
2
text/text.d.ts
vendored
2
text/text.d.ts
vendored
@ -2,7 +2,7 @@
|
|||||||
* Defines the supported character encodings.
|
* Defines the supported character encodings.
|
||||||
*/
|
*/
|
||||||
declare module "text" {
|
declare module "text" {
|
||||||
export module encoding {
|
module encoding {
|
||||||
export var ISO_8859_1: any;
|
export var ISO_8859_1: any;
|
||||||
export var US_ASCII: any;
|
export var US_ASCII: any;
|
||||||
export var UTF_16: any;
|
export var UTF_16: any;
|
||||||
|
15
ui/dialogs/Readme.md
Normal file
15
ui/dialogs/Readme.md
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
Dialogs module. Examples:
|
||||||
|
```js
|
||||||
|
dialogs.alert("Test").then(function(){ dialogs.alert("Test2"); });
|
||||||
|
dialogs.alert({message:"Test", title: "MyAlert", buttonName: "Close" })
|
||||||
|
.then(function(){ dialogs.alert("Test2"); });
|
||||||
|
|
||||||
|
dialogs.confirm("Test?").then(function(r){ dialogs.alert("Result:" + r); });
|
||||||
|
dialogs.confirm({message:"Confirm?", title: "MyConfirm", okButtonName: "Do it!", cancelButtonName: "Ignore it!" })
|
||||||
|
.then(function(r){ dialogs.alert("Result:" + r); });
|
||||||
|
|
||||||
|
dialogs.prompt("Enter something!").then(function(r){ dialogs.alert("Result:" + r); });
|
||||||
|
dialogs.prompt({message:"Enter something?", title: "MyPrompt", okButtonName: "Do it!",
|
||||||
|
cancelButtonName: "Ignore it!", defaultText : "Enter your password here!" })
|
||||||
|
.then(function(r){ dialogs.alert("Result:" + r); });
|
||||||
|
```
|
101
ui/dialogs/dialogs.android.ts
Normal file
101
ui/dialogs/dialogs.android.ts
Normal file
@ -0,0 +1,101 @@
|
|||||||
|
/**
|
||||||
|
* Android specific dialogs functions implementation.
|
||||||
|
*/
|
||||||
|
import promises = require("promises");
|
||||||
|
import dialogs = require("ui/dialogs");
|
||||||
|
import appmodule = require("application");
|
||||||
|
|
||||||
|
var STRING = "string",
|
||||||
|
ALERT = "Alert",
|
||||||
|
OK = "OK",
|
||||||
|
CANCEL = "Cancel";
|
||||||
|
|
||||||
|
function createAlertDialog(options: dialogs.DialogOptions): android.app.AlertDialog.Builder {
|
||||||
|
var alert = new android.app.AlertDialog.Builder(appmodule.android.currentActivity);
|
||||||
|
alert.setTitle(options.title);
|
||||||
|
alert.setMessage(options.message);
|
||||||
|
return alert;
|
||||||
|
}
|
||||||
|
|
||||||
|
function addOkCancelButtonsToAlertDialog(alert: android.app.AlertDialog.Builder, options: dialogs.ConfirmOptions,
|
||||||
|
okCallback: Function, cancelCallback?: Function): void {
|
||||||
|
alert.setPositiveButton(options.okButtonName, new android.content.DialogInterface.OnClickListener({
|
||||||
|
onClick: function (dialog: android.content.DialogInterface, id: number) {
|
||||||
|
dialog.cancel();
|
||||||
|
okCallback();
|
||||||
|
}
|
||||||
|
}));
|
||||||
|
|
||||||
|
alert.setNegativeButton(options.cancelButtonName, new android.content.DialogInterface.OnClickListener({
|
||||||
|
onClick: function (dialog: android.content.DialogInterface, id: number) {
|
||||||
|
dialog.cancel();
|
||||||
|
if (cancelCallback) {
|
||||||
|
cancelCallback();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}));
|
||||||
|
}
|
||||||
|
|
||||||
|
export function alert(arg: any): promises.Promise<void> {
|
||||||
|
var d = promises.defer<void>();
|
||||||
|
try {
|
||||||
|
var options = typeof arg === STRING ? { message: arg, title: ALERT, buttonName: OK } : arg
|
||||||
|
|
||||||
|
var alert = createAlertDialog(options);
|
||||||
|
|
||||||
|
alert.setPositiveButton(options.buttonName, new android.content.DialogInterface.OnClickListener({
|
||||||
|
onClick: function (dialog: android.content.DialogInterface, id: number) {
|
||||||
|
dialog.cancel();
|
||||||
|
d.resolve();
|
||||||
|
}
|
||||||
|
}));
|
||||||
|
|
||||||
|
alert.show();
|
||||||
|
|
||||||
|
} catch (ex) {
|
||||||
|
d.reject(ex);
|
||||||
|
}
|
||||||
|
|
||||||
|
return d.promise();
|
||||||
|
}
|
||||||
|
|
||||||
|
export function confirm(arg: any): promises.Promise<boolean> {
|
||||||
|
var d = promises.defer<boolean>();
|
||||||
|
try {
|
||||||
|
var options = typeof arg === STRING ? { message: arg, title: ALERT, okButtonName: OK, cancelButtonName: CANCEL } : arg
|
||||||
|
|
||||||
|
var alert = createAlertDialog(options);
|
||||||
|
|
||||||
|
addOkCancelButtonsToAlertDialog(alert, options, function () { d.resolve(true); }, function () { d.resolve(false); });
|
||||||
|
|
||||||
|
alert.show();
|
||||||
|
|
||||||
|
} catch (ex) {
|
||||||
|
d.reject(ex);
|
||||||
|
}
|
||||||
|
|
||||||
|
return d.promise();
|
||||||
|
}
|
||||||
|
|
||||||
|
export function prompt(arg: any): promises.Promise<string> {
|
||||||
|
var d = promises.defer<string>();
|
||||||
|
try {
|
||||||
|
var options = typeof arg === STRING ? { message: arg, title: ALERT, okButtonName: OK, cancelButtonName: CANCEL } : arg
|
||||||
|
|
||||||
|
var alert = createAlertDialog(options);
|
||||||
|
|
||||||
|
var input = new android.widget.EditText(appmodule.android.context);
|
||||||
|
input.setText(options.defaultText ? options.defaultText : "");
|
||||||
|
|
||||||
|
alert.setView(input);
|
||||||
|
|
||||||
|
addOkCancelButtonsToAlertDialog(alert, options, function () { d.resolve(input.getText().toString()); });
|
||||||
|
|
||||||
|
alert.show();
|
||||||
|
|
||||||
|
} catch (ex) {
|
||||||
|
d.reject(ex);
|
||||||
|
}
|
||||||
|
|
||||||
|
return d.promise();
|
||||||
|
}
|
88
ui/dialogs/dialogs.d.ts
vendored
Normal file
88
ui/dialogs/dialogs.d.ts
vendored
Normal file
@ -0,0 +1,88 @@
|
|||||||
|
declare module "ui/dialogs" {
|
||||||
|
import promises = require("promises");
|
||||||
|
/**
|
||||||
|
* The alert() method displays an alert box with a specified message.
|
||||||
|
* @param message Specifies the text to display in the alert box.
|
||||||
|
*/
|
||||||
|
function alert(message: string): promises.Promise<void>;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The alert() method displays an alert box with a specified options.
|
||||||
|
* @param options Specifies the options for the alert box.
|
||||||
|
*/
|
||||||
|
function alert(options: AlertOptions): promises.Promise<void>;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The confirm() method displays a dialog box with a specified message.
|
||||||
|
* @param message Specifies the text to display in the confirm box.
|
||||||
|
*/
|
||||||
|
function confirm(message: string): promises.Promise<boolean>;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The confirm() method displays a dialog box with a specified message.
|
||||||
|
* @param options Specifies the options for the confirm box.
|
||||||
|
*/
|
||||||
|
function confirm(options: ConfirmOptions): promises.Promise<boolean>;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The prompt() method displays a dialog box that prompts the visitor for input.
|
||||||
|
* @param message The text to display in the dialog box.
|
||||||
|
*/
|
||||||
|
function prompt(message: string): promises.Promise<string>;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The prompt() method displays a dialog box that prompts the visitor for input.
|
||||||
|
* @param options The options for the dialog box.
|
||||||
|
*/
|
||||||
|
function prompt(options: PromptOptions): promises.Promise<string>;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Provides options for the dialog.
|
||||||
|
*/
|
||||||
|
interface DialogOptions {
|
||||||
|
/**
|
||||||
|
* Gets or sets the alert message.
|
||||||
|
*/
|
||||||
|
message: string;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets or sets the alert title.
|
||||||
|
*/
|
||||||
|
title?: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Provides options for the alert.
|
||||||
|
*/
|
||||||
|
interface AlertOptions extends DialogOptions {
|
||||||
|
/**
|
||||||
|
* Gets or sets the button name.
|
||||||
|
*/
|
||||||
|
buttonName?: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Provides options for the confirm.
|
||||||
|
*/
|
||||||
|
interface ConfirmOptions extends DialogOptions {
|
||||||
|
/**
|
||||||
|
* Gets or sets the OK button name.
|
||||||
|
*/
|
||||||
|
okButtonName?: string;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets or sets the Cancel button name.
|
||||||
|
*/
|
||||||
|
cancelButtonName?: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Provides options for the prompt.
|
||||||
|
*/
|
||||||
|
interface PromptOptions extends ConfirmOptions {
|
||||||
|
/**
|
||||||
|
* Gets or sets the default text.
|
||||||
|
*/
|
||||||
|
defaultText?: string;
|
||||||
|
}
|
||||||
|
}
|
117
ui/dialogs/dialogs.ios.ts
Normal file
117
ui/dialogs/dialogs.ios.ts
Normal file
@ -0,0 +1,117 @@
|
|||||||
|
/**
|
||||||
|
* iOS specific dialogs functions implementation.
|
||||||
|
*/
|
||||||
|
import promises = require("promises");
|
||||||
|
import dialogs = require("ui/dialogs");
|
||||||
|
|
||||||
|
var UIALERTVIEWDELEGATE = "UIAlertViewDelegate",
|
||||||
|
STRING = "string",
|
||||||
|
ALERT = "Alert",
|
||||||
|
OK = "OK",
|
||||||
|
CANCEL = "Cancel";
|
||||||
|
|
||||||
|
function createUIAlertView(options: dialogs.DialogOptions): UIKit.UIAlertView {
|
||||||
|
var alert = new UIKit.UIAlertView();
|
||||||
|
alert.title = options.title;
|
||||||
|
alert.message = options.message;
|
||||||
|
return alert;
|
||||||
|
}
|
||||||
|
|
||||||
|
function createDelegate(callback) {
|
||||||
|
var delegateType = Foundation.NSObject.extends({}, {}).implements({
|
||||||
|
protocol: UIALERTVIEWDELEGATE,
|
||||||
|
implementation: {
|
||||||
|
alertViewClickedButtonAtIndex: function (view, index) {
|
||||||
|
callback(view, index);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
return new delegateType;
|
||||||
|
}
|
||||||
|
|
||||||
|
export function alert(arg: any): promises.Promise<void> {
|
||||||
|
var d = promises.defer<void>();
|
||||||
|
try {
|
||||||
|
var options = typeof arg === STRING ? { message: arg, title: ALERT, buttonName: OK } : arg
|
||||||
|
|
||||||
|
var alert = createUIAlertView(options);
|
||||||
|
|
||||||
|
alert.addButtonWithTitle(options.buttonName);
|
||||||
|
|
||||||
|
// Assign first to local variable, otherwise it will be garbage collected since delegate is weak reference.
|
||||||
|
var delegate = createDelegate(function (view, index) {
|
||||||
|
d.resolve();
|
||||||
|
// Remove the local variable for the delegate.
|
||||||
|
delegate = undefined;
|
||||||
|
});
|
||||||
|
|
||||||
|
alert.delegate = delegate;
|
||||||
|
|
||||||
|
alert.show();
|
||||||
|
} catch (ex) {
|
||||||
|
d.reject(ex);
|
||||||
|
}
|
||||||
|
|
||||||
|
return d.promise();
|
||||||
|
}
|
||||||
|
|
||||||
|
export function confirm(arg: any): promises.Promise<boolean> {
|
||||||
|
var d = promises.defer<boolean>();
|
||||||
|
try {
|
||||||
|
var options = typeof arg === STRING ? { message: arg, title: ALERT, okButtonName: OK, cancelButtonName: CANCEL } : arg
|
||||||
|
|
||||||
|
var alert = createUIAlertView(options);
|
||||||
|
|
||||||
|
alert.addButtonWithTitle(options.okButtonName);
|
||||||
|
alert.addButtonWithTitle(options.cancelButtonName);
|
||||||
|
|
||||||
|
// Assign first to local variable, otherwise it will be garbage collected since delegate is weak reference.
|
||||||
|
var delegate = createDelegate(function (view, index) {
|
||||||
|
d.resolve(index === 0);
|
||||||
|
// Remove the local variable for the delegate.
|
||||||
|
delegate = undefined;
|
||||||
|
});
|
||||||
|
|
||||||
|
alert.delegate = delegate;
|
||||||
|
|
||||||
|
alert.show();
|
||||||
|
|
||||||
|
} catch (ex) {
|
||||||
|
d.reject(ex);
|
||||||
|
}
|
||||||
|
|
||||||
|
return d.promise();
|
||||||
|
}
|
||||||
|
|
||||||
|
export function prompt(arg: any): promises.Promise<string> {
|
||||||
|
var d = promises.defer<string>();
|
||||||
|
try {
|
||||||
|
var options = typeof arg === STRING ? { message: arg, title: ALERT, okButtonName: OK, cancelButtonName: CANCEL } : arg
|
||||||
|
|
||||||
|
var alert = createUIAlertView(options);
|
||||||
|
alert.alertViewStyle = UIKit.UIAlertViewStyle.UIAlertViewStylePlainTextInput;
|
||||||
|
alert.addButtonWithTitle(options.okButtonName);
|
||||||
|
alert.addButtonWithTitle(options.cancelButtonName);
|
||||||
|
|
||||||
|
var textField = alert.textFieldAtIndex(0);
|
||||||
|
textField.text = options.defaultText ? options.defaultText : "";
|
||||||
|
|
||||||
|
// Assign first to local variable, otherwise it will be garbage collected since delegate is weak reference.
|
||||||
|
var delegate = createDelegate(function (view, index) {
|
||||||
|
if (index === 0) {
|
||||||
|
d.resolve(textField.text);
|
||||||
|
}
|
||||||
|
// Remove the local variable for the delegate.
|
||||||
|
delegate = undefined;
|
||||||
|
});
|
||||||
|
|
||||||
|
alert.delegate = delegate;
|
||||||
|
|
||||||
|
alert.show();
|
||||||
|
|
||||||
|
} catch (ex) {
|
||||||
|
d.reject(ex);
|
||||||
|
}
|
||||||
|
|
||||||
|
return d.promise();
|
||||||
|
}
|
2
ui/dialogs/index.ts
Normal file
2
ui/dialogs/index.ts
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
declare var module, require;
|
||||||
|
module.exports = require("ui/dialogs/dialogs");
|
Reference in New Issue
Block a user