topical media & game development
mobile-js-jquery-ch10.txt / txt
chapter: Extending the Framework
==================
(function( is
// linked to the jQuery global object
// Widget definition
.mobile.widget, {
options: {
// Here we can create default options of our widget
},
// Private methods
_create: function() {
// The constructor function
},
// Public methods
enable: function() {
// Enable the widget
},
disable: function() {
// Disable the widget
},
refresh: function() {
// Refresh the widget
}
});
// End of widget definition
// Auto-initialization code
document.bind("pagecreate", function(event) {
// We find data-role's and apply our widget constructor
$(event.target).find(":jqmData(role='ourWidgetName')").ourWidgetName();
});
}(jQuery));
====================================
.mobile.widget, {
options: {
width: "100%",
margin: 0
}
});
====================================
.mobile.widget, {
options: {
width: 100,
margin: 0
},
_create: function() {
// We call a private function
this._loadURL();
}
});
====================================
.mobile.widget, {
options: {
width: 100,
margin: 0
},
_create: function() {
// We call a private function
this._loadURL();
},
// Public methods
enable: function() {
// Enable the widget
$(this.element).attr('disabled', '');
},
disable: function() {
// Disable the widget
$(this.element).removeAttr('disabled');
},
refresh: function() {
// Refresh the widget
this._loadURL();
}
});
====================================
_loadURL: function() {
// this.element will be our +img+ element
var url; // we create the service URL
url = "http://src.sencha.io/";
var parameters = "";
if (!isNaN(this.options.width)) {
parameters += "x" + this.options.width;
}
if ((!isNaN(this.options.margin)) && this.options.margin>0) {
parameters += "-" + this.options.margin;
}
if (parameters.length>0) {
url += parameters + "/";
}
// Sencha IO needs an absolute URL
var originalUrl = $(this.element).jqmData("src");
if (originalUrl.length>1) {
var newUrl = "";
if (.mobile.path.parseUrl(location.href);
var baseUrlWithoutScript = baseUrl.protocol + "//" +
baseUrl.host + baseUrl.directory;
newUrl = ){
// Widget definition
.mobile.widget, {
options: {
margin: 0, width: 100
},
_create: function() {
this._loadURL();
},
// Private methods
_loadURL: function() {
// this.element will be our +img+ element
var url; // we create the service URL
url = "http://src.sencha.io/";
var parameters = "";
if (!isNaN(this.options.width)) {
parameters += "x" + this.options.width;
}
if ((!isNaN(this.options.margin)) && this.options.margin>0) {
parameters += "-" + this.options.margin;
}
if (parameters.length>0) {
url += parameters + "/";
}
// Sencha IO needs an absolute URL
var originalUrl = $(this.element).jqmData("src");
if (originalUrl.length>1) {
var newUrl = "";
if (.mobile.path.parseUrl(location.href);
var baseUrlWithoutScript = baseUrl.protocol + "//"
+ baseUrl.host + baseUrl.directory;
newUrl =
(C) Æliens
04/09/2009
You may not copy or print any of this material without explicit permission of the author or the publisher.
In case of other copyright issues, contact the author.