DVHMA/DVHMA-OpenUI5/www/resources/sap/m/Carousel.js

7 lines
12 KiB
JavaScript

/*!
* SAP UI development toolkit for HTML5 (SAPUI5/OpenUI5)
* (c) Copyright 2009-2015 SAP SE or an SAP affiliate company.
* Licensed under the Apache License, Version 2.0 - see LICENSE.txt.
*/
sap.ui.define(['jquery.sap.global','./library','sap/ui/core/Control','sap/ui/thirdparty/mobify-carousel'],function(q,l,C,m){"use strict";var a=C.extend("sap.m.Carousel",{metadata:{library:"sap.m",properties:{height:{type:"sap.ui.core.CSSSize",group:"Dimension",defaultValue:'100%'},width:{type:"sap.ui.core.CSSSize",group:"Dimension",defaultValue:'100%'},loop:{type:"boolean",group:"Misc",defaultValue:false},showPageIndicator:{type:"boolean",group:"Appearance",defaultValue:true},pageIndicatorPlacement:{type:"sap.m.PlacementType",group:"Appearance",defaultValue:sap.m.PlacementType.Bottom},showBusyIndicator:{type:"boolean",group:"Appearance",defaultValue:true,deprecated:true},busyIndicatorSize:{type:"sap.ui.core.CSSSize",group:"Dimension",defaultValue:'6em',deprecated:true}},defaultAggregation:"pages",aggregations:{pages:{type:"sap.ui.core.Control",multiple:true,singularName:"page"}},associations:{activePage:{type:"sap.ui.core.Control",multiple:false}},events:{loadPage:{deprecated:true,parameters:{pageId:{type:"string"}}},unloadPage:{deprecated:true,parameters:{pageId:{type:"string"}}},pageChanged:{parameters:{oldActivePageId:{type:"string"},newActivePageId:{type:"string"}}}}}});a._INNER_SELECTOR=".sapMCrslInner";a._PAGE_INDICATOR_SELECTOR=".sapMCrslBulleted";a._HUD_SELECTOR=".sapMCrslHud";a._ITEM_SELECTOR=".sapMCrslItem";a._LEFTMOST_CLASS="sapMCrslLeftmost";a._RIGHTMOST_CLASS="sapMCrslRightmost";a._LATERAL_CLASSES="sapMCrslLeftmost sapMCrslRightmost";a._bIE9=(sap.ui.Device.browser.internet_explorer&&sap.ui.Device.browser.version<10);a.prototype.init=function(){this._aScrollContainers=[];this._fnAdjustAfterResize=q.proxy(function(){var $=this.$().find(a._INNER_SELECTOR);this._oMobifyCarousel.resize($);},this);this.data("sap-ui-fastnavgroup","true",true);};a.prototype.exit=function(){if(this._oMobifyCarousel){this._oMobifyCarousel.destroy();delete this._oMobifyCarousel;}if(this._oArrowLeft){this._oArrowLeft.destroy();delete this._oArrowLeft;}if(this._oArrowRight){this._oArrowRight.destroy();delete this._oArrowRight;}if(this._sResizeListenerId){sap.ui.core.ResizeHandler.deregister(this._sResizeListenerId);this._sResizeListenerId=null;}this.$().off('afterSlide');this._cleanUpScrollContainer();this._fnAdjustAfterResize=null;this._aScrollContainers=null;if(!a._bIE9&&this._$InnerDiv){q(window).off("resize",this._fnAdjustAfterResize);}this._$InnerDiv=null;};a.prototype._cleanUpScrollContainer=function(){var s;while(this.length>0){s=this._aScrollContainers.pop();s.removeAllContent();if(s&&typeof s.destroy==='function'){s.destroy();}}};a.prototype.ontouchstart=function(e){if(this._oMobifyCarousel){this._oMobifyCarousel.touchstart(e);}};a.prototype.ontouchmove=function(e){if(this._oMobifyCarousel){this._oMobifyCarousel.touchmove(e);}};a.prototype.ontouchend=function(e){if(this._oMobifyCarousel){this._oMobifyCarousel.touchend(e);}};a.prototype.onBeforeRendering=function(){var A=this.getActivePage();if(!A&&this.getPages().length>0){this.setAssociation("activePage",this.getPages()[0].getId(),true);}if(this._sResizeListenerId){sap.ui.core.ResizeHandler.deregister(this._sResizeListenerId);this._sResizeListenerId=null;}if(!a._bIE9&&this._$InnerDiv){q(window).off("resize",this._fnAdjustAfterResize);}return this;};a.prototype.onAfterRendering=function(){if(this._oMobifyCarousel){this._oMobifyCarousel.destroy();}this.$().carousel();this._oMobifyCarousel=this.getDomRef()._carousel;this._oMobifyCarousel.setLoop(this.getLoop());this._oMobifyCarousel.setRTL(sap.ui.getCore().getConfiguration().getRTL());var A=this.getActivePage();if(A){var i=this._getPageNumber(A);if(isNaN(i)||i==0){if(this.getPages().length>0){this.setAssociation("activePage",this.getPages()[0].getId(),true);this._adjustHUDVisibility(1);}}else{this._oMobifyCarousel.changeAnimation('sapMCrslNoTransition');this._oMobifyCarousel.move(i+1);this._changePage(i+1);}}this.$().on('afterSlide',q.proxy(function(e,p,n){if(e.target!==this.getDomRef()){return;}if(n>0){this._changePage(n);}},this));this._$InnerDiv=this.$().find(a._INNER_SELECTOR)[0];if(a._bIE9){this._sResizeListenerId=sap.ui.core.ResizeHandler.register(this._$InnerDiv,this._fnAdjustAfterResize);}else{q(window).on("resize",this._fnAdjustAfterResize);}};a.prototype._changePage=function(n){this._adjustHUDVisibility(n);var o=this.getActivePage();var N=this.getPages()[n-1].getId();this.setAssociation("activePage",N,true);q.sap.log.debug("sap.m.Carousel: firing pageChanged event: old page: "+o+", new page: "+N);this.firePageChanged({oldActivePageId:o,newActivePageId:N});};a.prototype._adjustHUDVisibility=function(n){if(sap.ui.Device.system.desktop&&!this.getLoop()&&this.getPages().length>1){var h=this.$().find(a._HUD_SELECTOR);h.removeClass(a._LATERAL_CLASSES);if(n===1){h.addClass(a._LEFTMOST_CLASS);}else if(n===this.getPages().length){h.addClass(a._RIGHTMOST_CLASS);}}};a.prototype.setActivePage=function(p){var P=null;if(typeof(p)=='string'){P=p;}else if(p instanceof C){P=p.getId();}if(P){if(P===this.getActivePage()){return this;}var i=this._getPageNumber(P);if(!isNaN(i)){if(this._oMobifyCarousel){this._oMobifyCarousel.move(i+1);}}}this.setAssociation("activePage",P,true);return this;};a.prototype.setHeight=function(h){this.setProperty("height",h,true);this.$().css("height",h);return this;};a.prototype.setWidth=function(w){this.setProperty("width",w,true);this.$().css("width",w);return this;};a.prototype.setPageIndicatorPlacement=function(p){if(sap.m.PlacementType.Top!=p&&sap.m.PlacementType.Bottom!=p){p=sap.m.PlacementType.Bottom;}this.setProperty("pageIndicatorPlacement",p,true);var P=this.$().find(a._PAGE_INDICATOR_SELECTOR);if(sap.m.PlacementType.Top===p){this.$().prepend(P);P.removeClass('sapMCrslBottomOffset');this.$().find(a._ITEM_SELECTOR).removeClass('sapMCrslBottomOffset');}else{this.$().append(P);P.addClass('sapMCrslBottomOffset');this.$().find(a._ITEM_SELECTOR).addClass('sapMCrslBottomOffset');}return this;};a.prototype.setShowPageIndicator=function(s){var p=this.$().find(a._PAGE_INDICATOR_SELECTOR);s?p.show():p.hide();this.setProperty("showPageIndicator",s,true);return this;};a.prototype.setLoop=function(L){this.setProperty("loop",L,true);if(this._oMobifyCarousel){this._oMobifyCarousel.setLoop(L);}return this;};a.prototype._getNavigationArrow=function(n){q.sap.require("sap.ui.core.IconPool");var p={src:"sap-icon://navigation-"+n+"-arrow"};if(n==="left"){if(!this._oArrowLeft){this._oArrowLeft=sap.m.ImageHelper.getImageControl(this.getId()+"-arrowScrollLeft",this._oArrowLeft,this,p);}return this._oArrowLeft;}else if(n==="right"){if(!this._oArrowRight){this._oArrowRight=sap.m.ImageHelper.getImageControl(this.getId()+"-arrowScrollRight",this._oArrowRight,this,p);}return this._oArrowRight;}};a.prototype._createScrollContainer=function(p){var c=p instanceof sap.m.Image?"sapMCrslItemTableCell sapMCrslImg":"sapMCrslItemTableCell",o=new sap.ui.core.HTML({content:"<div class='sapMCrslItemTable'>"+"<div class='"+c+"'></div>"+"</div>",afterRendering:function(e){var r=sap.ui.getCore().createRenderManager();r.render(p,this.getDomRef().firstChild);r.destroy();}});var s=new sap.m.ScrollContainer({horizontal:false,vertical:false,content:[o],width:'100%',height:'100%'});s.setParent(this,null,true);this._aScrollContainers.push(s);return s;};a.prototype.previous=function(){if(this._oMobifyCarousel){this._oMobifyCarousel.prev();}else{q.sap.log.warning("Unable to execute sap.m.Carousel.previous: carousel must be rendered first.");}return this;};a.prototype.next=function(){if(this._oMobifyCarousel){this._oMobifyCarousel.next();}else{q.sap.log.warning("Unable to execute sap.m.Carousel.next: carousel must be rendered first.");}return this;};a.prototype._getPageNumber=function(p){var i,r;for(i=0;i<this.getPages().length;i++){if(this.getPages()[i].getId()==p){r=i;break;}}return r;};a.prototype.onsaptabprevious=function(e){this._fnOnTabPress(e,false);};a.prototype.onsaptabnext=function(e){this._fnOnTabPress(e,true);};a.prototype._fnOnTabPress=function(e,d){var s=e.target;var $=this.$().find('.sapMCrslItem.sapMCrslActive');if(s===this.$()[0]){this._fnOnCarouselEnter(e,d);return;}if(d===true){if(s===$.lastFocusableDomRef()){this._handleGroupNavigation(e,false);}}else{if(s===$.firstFocusableDomRef()){e.preventDefault();this.$().focus();}}this._iLastActivePage=this._getPageNumber(this.getActivePage());this._oLastFocusedElement=s;};a.prototype._fnOnCarouselEnter=function(e,d){var $=this.$().find('.sapMCrslItem.sapMCrslActive');if(this._bIsTabUsed===undefined){this._bIsTabUsed=true;e.preventDefault();if($.firstFocusableDomRef()!==null){$.firstFocusableDomRef().focus();}else{this._handleGroupNavigation(e,false);}return;}if(this._iLastActivePage===this._getPageNumber(this.getActivePage())&&this._oLastFocusedElement){if($.has(this._oLastFocusedElement).length&&d===true){e.preventDefault();this._oLastFocusedElement.focus();}}};a.prototype._handleGroupNavigation=function(e,s){var E=q.Event("keydown");e.preventDefault();this.$().focus();E.target=e.target;E.keyCode=q.sap.KeyCodes.F6;E.shiftKey=s;q.sap.handleF6GroupNavigation(E);};a.prototype._fnSkipToIndex=function(e,n){e.preventDefault();var b=n;if(e.target!==this.$()[0]){return;}if(n!==0){b=this._getPageNumber(this.getActivePage())+1+n;}b=Math.max(b,1);b=Math.min(b,this.getPages().length);this._oMobifyCarousel.move(b);};a.prototype.onfocusin=function(e){var $=this.$().find('.sapMCrslItem.sapMCrslActive');if(this.nFirstActivePageIndex===undefined){this.nFirstActivePageIndex=this._getPageNumber(this.getActivePage());}if(e.target===this.$().lastFocusableDomRef()&&e.target.parentNode!==$[0]){e.preventDefault();if(this._iLastActivePage===this._getPageNumber(this.getActivePage())&&this._oLastFocusedElement){this._oLastFocusedElement.focus();return;}if($.lastFocusableDomRef()!==null){$.lastFocusableDomRef().focus();}else{this.$().focus();}}};a.prototype.onsapskipforward=function(e){e.preventDefault();this._iLastActivePage=this._getPageNumber(this.getActivePage());this._oLastFocusedElement=e.target;this._handleGroupNavigation(e,false);};a.prototype.onsapskipback=function(e){e.preventDefault();this._iLastActivePage=this._getPageNumber(this.getActivePage());this._oLastFocusedElement=e.target;this._handleGroupNavigation(e,true);};a.prototype.onkeydown=function(e){var $;if(e.keyCode===q.sap.KeyCodes.F7){e.preventDefault();$=this.$().find('.sapMCrslItem.sapMCrslActive');if(this._oLastFocusedElementFromF7===undefined){this.$().focus();this._oLastFocusedElementFromF7=e.target;return;}if($.has(this._oLastFocusedElementFromF7).length>0){this._oLastFocusedElementFromF7.focus();this._oLastFocusedElementFromF7=undefined;}else{this.$().focus();this._oLastFocusedElementFromF7=e.target;}}if(e.keyCode===q.sap.KeyCodes.MINUS||e.keyCode===q.sap.KeyCodes.NUMPAD_MINUS){this._fnSkipToIndex(e,-1);}if(e.keyCode===q.sap.KeyCodes.PLUS||e.keyCode===q.sap.KeyCodes.NUMPAD_PLUS){this._fnSkipToIndex(e,1);}};a.prototype.onsapescape=function(e){if(this.nFirstActivePageIndex){this._oMobifyCarousel.move(this.nFirstActivePageIndex+1);this._changePage(this.nFirstActivePageIndex+1);}};a.prototype.onsapright=function(e){this._fnSkipToIndex(e,1);};a.prototype.onsapup=function(e){this._fnSkipToIndex(e,1);};a.prototype.onsapleft=function(e){this._fnSkipToIndex(e,-1);};a.prototype.onsapdown=function(e){this._fnSkipToIndex(e,-1);};a.prototype.onsaphome=function(e){this._fnSkipToIndex(e,0);};a.prototype.onsapend=function(e){this._fnSkipToIndex(e,this.getPages().length);};a.prototype.onsaprightmodifiers=function(e){if(e.ctrlKey){this._fnSkipToIndex(e,10);}};a.prototype.onsapupmodifiers=function(e){if(e.ctrlKey){this._fnSkipToIndex(e,10);}};a.prototype.onsappageup=function(e){this._fnSkipToIndex(e,10);};a.prototype.onsapleftmodifiers=function(e){if(e.ctrlKey){this._fnSkipToIndex(e,-10);}};a.prototype.onsapdownmodifiers=function(e){if(e.ctrlKey){this._fnSkipToIndex(e,-10);}};a.prototype.onsappagedown=function(e){this._fnSkipToIndex(e,-10);};a.prototype.setShowBusyIndicator=function(){q.sap.log.warning("sap.m.Carousel: Deprecated function 'setShowBusyIndicator' called. Does nothing.");return this;};a.prototype.getShowBusyIndicator=function(){q.sap.log.warning("sap.m.Carousel: Deprecated function 'getShowBusyIndicator' called. Does nothing.");return false;};a.prototype.setBusyIndicatorSize=function(){q.sap.log.warning("sap.m.Carousel: Deprecated function 'setBusyIndicatorSize' called. Does nothing.");return this;};a.prototype.getBusyIndicatorSize=function(){q.sap.log.warning("sap.m.Carousel: Deprecated function 'getBusyIndicatorSize' called. Does nothing.");return"";};return a;},true);