123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123 |
- define("dojox/mobile/_ScrollableMixin", [
- "dojo/_base/kernel",
- "dojo/_base/declare",
- "dojo/_base/lang",
- "dojo/_base/window",
- "dojo/dom",
- "dojo/dom-class",
- "dijit/registry", // registry.byNode
- "./scrollable"
- ], function(dojo, declare, lang, win, dom, domClass, registry, Scrollable){
- // module:
- // dojox/mobile/_ScrollableMixin
- // summary:
- // Mixin for widgets to have a touch scrolling capability.
- var cls = declare("dojox.mobile._ScrollableMixin", null, {
- // summary:
- // Mixin for widgets to have a touch scrolling capability.
- // description:
- // Actual implementation is in scrollable.js.
- // scrollable.js is not a dojo class, but just a collection
- // of functions. This module makes scrollable.js a dojo class.
- // fixedHeader: String
- // Id of the fixed header.
- fixedHeader: "",
- // fixedFooter: String
- // Id of the fixed footer.
- fixedFooter: "",
- // scrollableParams: Object
- // Parameters for dojox.mobile.scrollable.init().
- scrollableParams: null,
- // allowNestedScrolls: Boolean
- // e.g. Allow ScrollableView in a SwapView.
- allowNestedScrolls: true,
- constructor: function(){
- this.scrollableParams = {};
- },
- destroy: function(){
- this.cleanup();
- this.inherited(arguments);
- },
- startup: function(){
- if(this._started){ return; }
- var node;
- var params = this.scrollableParams;
- if(this.fixedHeader){
- node = dom.byId(this.fixedHeader);
- if(node.parentNode == this.domNode){ // local footer
- this.isLocalHeader = true;
- }
- params.fixedHeaderHeight = node.offsetHeight;
- }
- if(this.fixedFooter){
- node = dom.byId(this.fixedFooter);
- if(node.parentNode == this.domNode){ // local footer
- this.isLocalFooter = true;
- node.style.bottom = "0px";
- }
- params.fixedFooterHeight = node.offsetHeight;
- }
- this.init(params);
- if(this.allowNestedScrolls){
- for(var p = this.getParent(); p; p = p.getParent()){
- if(p && p.scrollableParams){
- this.isNested = true;
- this.dirLock = true;
- p.dirLock = true;
- break;
- }
- }
- }
- this.inherited(arguments);
- },
- findAppBars: function(){
- // summary:
- // Search for application-specific header or footer.
- var i, len, c;
- for(i = 0, len = win.body().childNodes.length; i < len; i++){
- c = win.body().childNodes[i];
- this.checkFixedBar(c, false);
- }
- if(this.domNode.parentNode){
- for(i = 0, len = this.domNode.parentNode.childNodes.length; i < len; i++){
- c = this.domNode.parentNode.childNodes[i];
- this.checkFixedBar(c, false);
- }
- }
- this.fixedFooterHeight = this.fixedFooter ? this.fixedFooter.offsetHeight : 0;
- },
- checkFixedBar: function(/*DomNode*/node, /*Boolean*/local){
- // summary:
- // Checks if the given node is a fixed bar or not.
- if(node.nodeType === 1){
- var fixed = node.getAttribute("fixed")
- || (registry.byNode(node) && registry.byNode(node).fixed);
- if(fixed === "top"){
- domClass.add(node, "mblFixedHeaderBar");
- if(local){
- node.style.top = "0px";
- this.fixedHeader = node;
- }
- return fixed;
- }else if(fixed === "bottom"){
- domClass.add(node, "mblFixedBottomBar");
- this.fixedFooter = node;
- return fixed;
- }
- }
- return null;
- }
- });
- lang.extend(cls, new Scrollable(dojo, dojox));
- return cls;
- });
|