Add JQuery Mobile Definitions and tests

This commit is contained in:
Boris Yankov
2012-10-25 04:43:38 +03:00
parent 8e9876c6a3
commit 8957de3116
3 changed files with 636 additions and 1 deletions
+380
View File
@@ -0,0 +1,380 @@
// Type definitions for jQuery Mobile 1.2
// Project: http://jquerymobile.com/
// Definitions: https://github.com/borisyankov/DefinitelyTyped
/// <reference path="jquery-1.8.d.ts"/>
interface JQueryMobileEvent { (event: Event, ui): void; }
interface DialogOptions {
closeBtnText?: string;
initSelector?: string;
overlayTheme?: string;
}
interface DialogEvents {
create?: JQueryMobileEvent;
}
interface PopupOptions {
corners?: bool;
history?: bool;
initSelector?: string;
overlayTheme?: string;
positionTo?: string;
shadow?: bool;
theme?: string;
tolerance?: string;
transition?: string;
}
interface PopupEvents {
popupbeforeposition?: JQueryMobileEvent;
popupafteropen?: JQueryMobileEvent;
popupafterclose?: JQueryMobileEvent;
}
interface FixedToolbarOptions {
visibleOnPageShow?: bool;
disablePageZoom?: bool;
transition?: string;
fullscreen?: bool;
tapToggle?: bool;
tapToggleBlacklist?: string;
hideDuringFocus?: string;
updatePagePadding?: bool;
supportBlacklist?: Function;
initSelector?: string;
}
interface FixedToolbarEvents {
create?: JQueryMobileEvent;
}
interface ButtonOptions {
corners?: bool;
icon?: string;
iconpos?: string;
iconshadow?: bool;
inline?: bool;
mini?: bool;
shadow?: bool;
theme?: string;
initSelector?: string;
}
interface ButtonEvents {
create?: JQueryMobileEvent;
}
interface CollapsibleOptions {
collapsed?: bool;
collapseCueText?: string;
collapsedIcon?: string;
contentTheme?: string;
expandCueText?: string;
expandedIcon?: string;
heading?: string;
iconpos?: string;
initSelector?: string;
inset?: bool;
mini?: bool;
theme?: string;
}
interface CollapsibleEvents {
create?: JQueryMobileEvent;
collapse?: JQueryMobileEvent;
expand?: JQueryMobileEvent;
}
interface CollapsibleSetOptions {
collapsedIcon?: string;
expandedIcon?: string;
iconpos?: string;
initSelector?: string;
inset?: bool;
mini?: bool;
theme?: string;
}
interface CollapsibleSetEvents {
create?: JQueryMobileEvent;
}
interface TextInputOptions {
disabled?: bool;
initSelector?: string;
mini?: bool;
preventFocusZoom?: bool;
theme?: string;
}
interface TextInputEvents {
create?: JQueryMobileEvent;
}
interface SearchInputOptions {
clearSearchButtonText?: string;
disabled?: bool;
initSelector?: string;
mini?: bool;
theme?: string;
}
interface SliderOptions {
disabled?: bool;
highlight?: bool;
initSelector?: string;
mini?: bool;
theme?: string;
trackTheme?: string;
}
interface SliderEvents {
create?: JQueryMobileEvent;
slidestart?: JQueryMobileEvent;
slidestop?: JQueryMobileEvent;
}
interface CheckboxRadioOptions {
mini?: bool;
theme?: string;
}
interface CheckboxRadioEvents {
createp?: JQueryMobileEvent;
}
interface SelectMenuOptions {
corners?: bool;
icon?: string;
iconpos?: string;
iconshadow?: bool;
initSelector?: string;
inline?: bool;
mini?: bool;
nativeMenu?: bool;
overlayTheme?: string;
preventFocusZoom?: bool;
shadow?: bool;
theme?: string;
}
interface SelectMenuEvents {
create?: JQueryMobileEvent;
}
interface ListViewOptions {
countTheme?: string;
dividerTheme?: string;
filter?: bool;
filterCallback?: Function;
filterPlaceholder?: string;
filterTheme?: string;
headerTheme?: string;
initSelector?: string;
inset?: bool;
splitIcon?: string;
splitTheme?: string;
theme?: string;
}
interface ListViewEvents {
create?: JQueryMobileEvent;
}
interface JQueryMobileOptions {
activeBtnClass?: string;
activePageClass?: string;
ajaxEnabled?: bool;
allowCrossDomainPages?: bool;
autoInitializePage?: bool;
buttonMarkup;
defaultDialogTransition?: string;
defaultPageTransition?: string;
getMaxScrollForTransition?: number;
gradeA?: Function;
hashListeningEnabled?: bool;
ignoreContentEnabled?: bool;
linkBindingEnabled?: bool;
loadingMessageTextVisible?: bool;
loadingMessageTheme?: string;
maxTransitionWidth?: number;
minScrollBack?: number;
ns?: number;
pageLoadErrorMessage?: string;
pageLoadErrorMessageTheme?: string;
phonegapNavigationEnabled?: bool;
pushStateEnabled?: bool;
subPageUrlKey?: string;
touchOverflowEnabled?: bool;
transitionFallbacks;
}
interface JQueryMobileEvents {
tap;
taphold;
swipe;
swipeleft;
swiperight;
vmouseover;
vmouseout;
vmousedown;
vmousemove;
vmouseup;
vclick;
vmousecancel;
orientationchange;
scrollstart;
scrollstop;
pagebeforeload;
pageload;
pageloadfailed;
pagebeforechange;
pagechange;
pagechangefailed;
pagebeforeshow;
pagebeforehide;
pageshow;
pagehide;
pagebeforecreate;
pagecreate;
pageinit;
pageremove;
updatelayout;
}
interface ChangePageOptions {
allowSamePageTransition?: bool;
changeHash?: bool;
data?: any;
dataUrl?: string;
pageContainer?: JQuery;
reloadPage?: bool;
reverse?: bool;
role?: string;
showLoadMsg?: bool;
transition?: string;
type?: string;
}
interface LoadPageOptions {
data?: any;
loadMsgDelay?: number;
pageContainer?: JQuery;
reloadPage?: bool;
role?: string;
showLoadMsg?: bool;
type?: string;
}
interface JQueryMobile extends JQueryMobileOptions {
changePage(to: any, options?: ChangePageOptions): void;
loadPage(url: any, options?: LoadPageOptions): void;
loading(command: string, options?): void;
base;
silentScroll(yPos: number):void;
activePage;
options: JQueryMobileOptions;
transitionFallbacks;
loader;
loading;
loadPage;
page;
silentScroll;
touchOverflow;
showCategory;
path;
dialog;
popup;
fixedtoolbar;
button;
collapsible;
collapsibleset;
textinput;
slider;
checkboxradio;
selectmenu;
listview;
}
interface JQuerySupport {
touchOverflow;
}
interface JQuery {
dialog(): JQuery;
dialog(command: string): JQuery;
dialog(options: DialogOptions): JQuery;
dialog(events: DialogEvents): JQuery;
popup(): JQuery;
popup(command: string): JQuery;
popup(options: PopupOptions): JQuery;
popup(command: string, options: PopupOptions): JQuery;
popup(events: PopupEvents): JQuery;
fixedtoolbar(): JQuery;
fixedtoolbar(command: string): JQuery;
fixedtoolbar(options: FixedToolbarOptions): JQuery;
fixedtoolbar(events: FixedToolbarEvents): JQuery;
button(): JQuery;
button(command: string): JQuery;
buttonMarkup(options: ButtonOptions): JQuery;
button(events: ButtonEvents): JQuery;
collapsible(): JQuery;
collapsible(command: string): JQuery;
collapsible(options: CollapsibleOptions): JQuery;
collapsible(events: CollapsibleEvents): JQuery;
collapsibleSet(): JQuery;
collapsibleSet(command: string): JQuery;
collapsibleset(options: CollapsibleSetOptions): JQuery;
collapsibleset(events: CollapsibleSetEvents): JQuery;
textinput(): JQuery;
textinput(command: string): JQuery;
textinput(options: TextInputOptions): JQuery;
textinput(events: TextInputEvents): JQuery;
textinput(options: SearchInputOptions): JQuery;
slider(): JQuery;
slider(command: string): JQuery;
slider(options: SliderOptions): JQuery;
slider(events: SliderEvents): JQuery;
checkboxradio(): JQuery;
checkboxradio(command: string): JQuery;
checkboxradio(options: CheckboxRadioOptions): JQuery;
checkboxradio(events: CheckboxRadioEvents): JQuery;
selectmenu(): JQuery;
selectmenu(command: string): JQuery;
selectmenu(command: string, update: bool): JQuery;
selectmenu(options: CheckboxRadioOptions): JQuery;
selectmenu(events: CheckboxRadioEvents): JQuery;
listview(): JQuery;
listview(command: string): JQuery;
listview(options: ListViewOptions): JQuery;
listview(events: ListViewEvents): JQuery;
}
interface JQueryStatic {
mobile: JQueryMobile;
}
+2 -1
View File
@@ -20,6 +20,7 @@ Complete
* [Jasmine](http://pivotal.github.com/jasmine/)
* [jQuery.Globalize](https://github.com/jquery/globalize)
* [jQuery](http://jquery.com/) (from TypeScript samples)
* [jQuery Mobile](http://jquerymobile.com)
* [jQuery UI](http://jqueryui.com/)
* [Knockout.js](http://knockoutjs.com/)
* [Modernizr](http://modernizr.com/)
@@ -35,10 +36,10 @@ Complete
Next
----
* Knockout.Mapping
* Chosen
* Angular.js
* Facebook SDK
* jQuery.Validate
* jQuery Mobile
* google.visualization
* Meteor
* PhoneGap
+254
View File
@@ -0,0 +1,254 @@
/// <reference path="../Definitions/jquery-1.8.d.ts" />
/// <reference path="../Definitions/jquerymobile-1.2.d.ts" />
function test_api() {
$.mobile.changePage("about/us.html", { transition: "slideup" });
$.mobile.changePage("searchresults.php", {
type: "post",
data: $("form#search").serialize()
});
$.mobile.changePage("../alerts/confirm.html", {
transition: "pop",
reverse: false,
changeHash: false
});
$.mobile.loadPage("about/us.html");
$.mobile.loadPage("searchresults.php", {
type: "post",
data: $("form#search").serialize()
});
$.mobile.loading('show', { theme: "b", text: "foo", textonly: true });
$.mobile.path.parseUrl("http://jblas:password@mycompany.com:8080/mail/inbox?msg=1234");
var absUrl = $.mobile.path.makeUrlAbsolute("#bar", "http://foo.com/a/b/c/test.html");
var isRel = $.mobile.path.isRelativeUrl("#foo");
var isAbs = $.mobile.path.isAbsoluteUrl("//foo.com/a/file.html");
var dirName = $.mobile.path.get("http://foo.com/a");
$.mobile.silentScroll(100);
}
function test_pagesDialogs() {
$.mobile.transitionFallbacks.slideout = "none";
$(document).bind('mobileinit', function () {
$.mobile.loader.prototype.options.text = "loading";
$.mobile.loader.prototype.options.textVisible = false;
$.mobile.loader.prototype.options.theme = "a";
$.mobile.loader.prototype.options.html = "";
});
$.mobile.loading('show', {
text: 'foo',
textVisible: true,
theme: 'z',
html: ""
});
$('.ui-dialog').dialog('close');
$("#myPopupDiv").popup();
var options;
$(".selector").popup("open", options);
$("#myPopupDiv").popup("open");
$(document).on("pageinit", function () {
$('.popupParent').on({
popupafterclose: function () {
setTimeout(function () { $('.popupChild').popup('open') }, 100);
}
});
});
var pageUrl;
$.mobile.loadPage(pageUrl, { showLoadMsg: false });
$.mobile.page.prototype.options.domCache = true;
$.ajaxPrefilter(function (options, originalOptions, jqXHR) {
if (applicationCache &&
applicationCache.status != applicationCache.UNCACHED &&
applicationCache.status != applicationCache.OBSOLETE) {
// the important bit
options.isLocal = true;
}
});
$(document).bind("pagebeforechange", function (e, data) {
if (typeof data.toPage === "string") {
var u = $.mobile.path.parseUrl(data.toPage),
re = /^#category-item/;
if (u.hash.search(re) !== -1) {
var showCategory;
showCategory(u, data.options);
e.preventDefault();
}
}
});
$(document).delegate("#aboutPage", "pageinit", function () {
alert('A page with an id of "aboutPage" was just created by jQuery Mobile!');
});
$(document).delegate("#aboutPage", "pagebeforecreate", function () {
alert('A page with an id of "aboutPage" is about to be created by jQuery Mobile!');
});
$.mobile.changePage("about/us.html", { transition: "slideup" });
$.mobile.changePage("searchresults.php", {
type: "post",
data: $("form#search").serialize()
});
$.mobile.loadPage("about/us.html");
$.mobile.silentScroll(300);
$(document).bind("mobileinit", function () {
$.mobile.allowCrossDomainPages = true;
});
$.mobile.touchOverflowEnabled = true;
$(document).bind("mobileinit", function () {
$.support.touchOverflow = true;
$.mobile.touchOverflowEnabled = true;
});
}
function test_toolbars() {
$.mobile.page.prototype.options.backBtnText = "previous";
$.mobile.page.prototype.options.backBtnTheme = "a";
$("[data-role=header]").fixedtoolbar({ visibleOnPageShow: false });
$("[data-role=header]").fixedtoolbar({ disablePageZoom: false });
$("[data-role=header]").fixedtoolbar({ transition: "fade" });
$("[data-role=header]").fixedtoolbar({ fullscreen: true });
$("[data-role=header]").fixedtoolbar({ tapToggle: true });
$("[data-role=header]").fixedtoolbar({ tapToggleBlacklist: "a, button, input, select, textarea, .ui-header-fixed, .ui-footer-fixed" });
$("[data-role=header]").fixedtoolbar({ hideDuringFocus: "input, select, textarea" });
$("[data-role=header]").fixedtoolbar({ updatePagePadding: false });
$(document).bind("mobileinit", function () {
$.mobile.fixedtoolbar.prototype.options.supportBlacklist = function () {
var result;
return result;
};
$(document).bind("mobileinit", function () {
$.mobile.fixedtoolbar.prototype.options.initSelector = ".myselector";
});
});
$("[data-position='fixed']").fixedtoolbar('show');
$("[data-position='fixed']").fixedtoolbar('hide');
$(".selector").fixedtoolbar({
create: function (event, ui) { }
});
}
function test_button() {
$('[type="submit"]').button();
$('a').buttonMarkup({ corners: false });
$('a').buttonMarkup({ icon: "star" });
$('a').buttonMarkup({ iconpos: "right" });
$('a').buttonMarkup({ iconshadow: false });
$('a').buttonMarkup({ inline: true });
$('a').buttonMarkup({ mini: true });
$('a').buttonMarkup({ shadow: false });
$('a').buttonMarkup({ theme: "a" });
$.mobile.button.prototype.options.initSelector = ".myButtons";
$('[type="submit"]').button('enable');
$('[type="submit"]').button('disable');
$('[type="submit"]').button('refresh');
$('[type="submit"]').button({
create: function (event, ui) { }
});
}
function test_collapsible() {
$.mobile.collapsible.prototype.options.collapsed = false;
$.mobile.collapsible.prototype.options.collapseCueText = " collapse with a click";
$.mobile.collapsible.prototype.options.collapsedIcon = "arrow-r";
$.mobile.collapsible.prototype.options.contentTheme = "a";
$.mobile.collapsible.prototype.options.expandCueText = " expand with a click";
$.mobile.collapsible.prototype.options.expandedIcon = "arrow-d";
$.mobile.collapsible.prototype.options.heading = ".mycollapsibleheading";
$.mobile.collapsible.prototype.options.iconpos = "right";
$.mobile.collapsible.prototype.options.initSelector = ".mycollapsible";
$.mobile.collapsible.prototype.options.inset = false;
$.mobile.collapsible.prototype.options.mini = true;
$.mobile.collapsible.prototype.options.theme = "a";
$(".selector").trigger("collapse");
$(".selector").collapsible({
create: function (event, ui) { },
collapse: function (event, ui) { },
expand: function (event, ui) { }
});
$.mobile.collapsibleset.prototype.options.collapsedIcon = "arrow-r";
$.mobile.collapsibleset.prototype.options.expandedIcon = "arrow-d";
$.mobile.collapsibleset.prototype.options.iconpos = "right";
$.mobile.collapsibleset.prototype.options.initSelector = ".mycollapsibleset";
$.mobile.collapsible.prototype.options.inset = false;
$.mobile.collapsibleset.prototype.options.mini = true;
$.mobile.collapsibleset.prototype.options.theme = "a";
$(".selector").collapsibleset({
create: function (event, ui) { }
});
}
function test_form() {
$("input[type='checkbox']").prop("checked", true).checkboxradio("refresh");
$.mobile.page.prototype.options.keepNative = "select, input.foo, textarea.bar";
$('input').textinput();
$('.selector').textinput({ disabled: true });
$.mobile.textinput.prototype.options.initSelector = ".myInputs";
$('.selector').textinput({ mini: true });
$('input').textinput({ preventFocusZoom: true });
$('.selector').textinput({ theme: "a" });
$('.selector').textinput('enable');
$(".selector").textinput({
create: function (event, ui) { }
});
$('select').slider();
$('.selector').slider({ disabled: true });
$('.selector').slider({ highlight: true });
$.mobile.slider.prototype.options.initSelector = ".myslider";
$('.selector').slider({ mini: true });
$('.selector').slider({ theme: "a" });
$('.selector').slider({ trackTheme: "a" });
$(".selector").slider({
create: function (event, ui) { }
});
$(".selector").on('slidestart', function (event) { });
$(".selector").on('slidestop', function (event) { });
$("input[type='radio']").checkboxradio({ mini: true });
$("input[type='radio']").checkboxradio({ theme: "a" });
$("input[type='radio']").checkboxradio('enable');
$("input[type='radio']:first").attr("checked", true).checkboxradio("refresh");
$("input[type='radio']").checkboxradio({
create: function (event, ui) { }
});
$('select').selectmenu();
$('select').selectmenu('enable');
$('select').selectmenu('refresh', true);
$(".selector").selectmenu({
create: function (event, ui) { }
});
}
function test_listview() {
$("#mylistview").listview({
autodividers: true,
autodividersSelector: function (li) {
var out;
return out;
}
});
$.mobile.listview.prototype.options.countTheme = "a";
$.mobile.listview.prototype.options.dividerTheme = "a";
$.mobile.listview.prototype.options.filter = true;
$.mobile.listview.prototype.options.filterCallback = function (text, searchValue) {
// only show items that *begin* with the search string
return text.toLowerCase().substring(0, searchValue.length) !== searchValue;
};
$.mobile.listview.prototype.options.filterPlaceholder = "Search...";
$.mobile.listview.prototype.options.filterTheme = "a";
$.mobile.listview.prototype.options.headerTheme = "a";
$.mobile.listview.prototype.options.initSelector = ".mylistview";
$.mobile.listview.prototype.options.inset = true;
$.mobile.listview.prototype.options.splitIcon = "star";
$.mobile.listview.prototype.options.splitTheme = "a";
$.mobile.listview.prototype.options.theme = "a";
$('#mylist').listview();
$('#mylist').listview('refresh');
}