User Tools

Site Tools


script_animation_cardstyle

====== About the script ====== * Purpose : This script will give you a beautiful page transition animation and an optional horizontal page loop * Author : [[https://plus.google.com/+LukasMorawietz|LM13]] * Current Version : 1.0 * Link: https://plus.google.com/115366157037831519359/posts/GqZBMeMEpLT * Download avialable! (Check repository) ====== Changelog ====== * Version 1.0 (13/7/2014): initial release in wiki ====== How to use the script ====== * Set the script to the positionchanged event of your container * enable infinte scrolling if you want a page loop, disable it if you don't want to loop through pages * in this container: create a shortcut or a gesture to the script * one click on the shortcut will enable the animation, clicking again will disable the animation. * BE SURE TO DISABLE THE ANIMATION BEFORE YOU EDIT, MOVE OR ADD ITEMS! //please report all bugs in the g+ community!// ====== Script ====== <sxh javascript;>var e=LL.getEvent(); var d=e.getContainer(); var dwidth=d.getWidth(); var dheight=d.getHeight(); var cont=JSON.parse(d.getTag()|| "null"); var items=d.getItems(); if(e.getSource()!="C_POSITION_CHANGED"){ var box=d.getBoundingBox(); if(cont==null) cont=new Object(); cont.minx=box.getLeft(); cont.maxx=box.getRight(); var minpage=Math.floor(cont.minx/dwidth); if(cont.setup!=true) { cont.pages=[]; var counters=[]; for(x=0;x<Math.ceil(cont.maxx/dwidth)-minpage;x++) { cont.pages[x]=[]; counters[x]=0; } for(x=0;x<items.length;x++) { var i=items.getAt(x); var pinned=i.getProperties() .getString("i.pinMode"); if(pinned=="NONE"|| pinned=="Y") { var data=new Object(); data.posx=i.getPositionX(); data.posy=i.getPositionY(); if(i.getProperties().getBoolean("i.onGrid")) data.onGrid=true; else data.onGrid=false; i.getProperties().edit().setBoolean("i.onGrid",false).commit(); var p=Math.floor(data.posx/dwidth)-minpage; cont.pages[p][counters[p]++]=i.getId(); i.setTag(JSON.stringify(data)); } } for(x=0;x<Math.ceil(cont.maxx/dwidth)-minpage;x++) { cont.pages[x].length=counters[x]; } cont.setup=true; Android.makeNewToast("Animation enabled",true).show(); } else { var cellw=d.getCellWidth(); var cellh=d.getCellHeight(); for(x=0;x<items.getLength();x++) { var i=items.getAt(x); var data=JSON.parse(i.getTag()); if(data!=null) { i.setPosition(data.posx,data.posy); if(data.onGrid==true) { iwidth=i.getWidth(); iheight=i.getHeight(); i.getProperties().edit().setBoolean("i.onGrid",true).commit(); i.setCell(Math.round(data.posx/cellw),Math.round(data.posy/cellh),Math.round((data.posx+iwidth)/cellw),Math.round(( data.posy+iheight)/cellh)); } } } cont.setup=false; Android.makeNewToast("Animation disabled",true).show(); } d.setTag(JSON.stringify(cont)); } if(cont==null || !cont.setup || d.getPositionScale()!=1)return; var dposx=d.getPositionX(); var dposy=d.getPositionY(); var current=Math.floor(dposx/dwidth); var pagepos=current*dwidth; var percent=(dposx-pagepos)/dwidth; var maxpage=Math.ceil((cont.maxx-dwidth)/dwidth); var minpage=Math.floor(cont.minx/dwidth); var zorder=items.length; if((percent>0.005 && percent<99.995) && dposx>cont.minx-dwidth) { var scrollLimit=d.getProperties() .getBoolean("noScrollLimit"); if(dposx>cont.maxx-dwidth&&scrollLimit){ d.setPosition(cont.minx-dwidth,dposy,1,false); } if(dposx<cont.minx&&scrollLimit) cont.state=true; var items=cont.pages[(cont.state?maxpage:current)-minpage]; if(items!=null) { for(z=0;z<items.length;z++) { var item=LL.getItemById(items[z]); var data=JSON.parse(item.getTag()); var x=(data.posx%dwidth+ dwidth)%dwidth; item.setScale(1,1); item.setPosition(pagepos+x,data.posy); item.getProperties().edit().setInteger("i.alpha",255).commit(); zorder=Math.min(zorder,d.getItemZIndex(items[z])); } } var items=cont.pages[current+1-minpage]; if(items!=null) { for(z=0;z<items.length;z++) { var item=LL.getItemById(items[z]); var data=JSON.parse(item.getTag()); var x=(data.posx%dwidth+ dwidth)%dwidth; var y=((data.posy%dheight +dheight)%dheight) if(d.getItemZIndex(items[z])>=zorder)d.setItemZIndex(items[z],0); item.setScale(0.75+percent/4,0.75+percent/4); item.setPosition(dposx+dwidth/2-(dwidth/2-x)*(0.75+percent/4),dposy+dheight/2-(dheight/2-y)*(0.75+percent/4)); item.getProperties().edit().setInteger("i.alpha",255*percent).commit(); } } } else { d.setPosition(dposx,dposy); d.setPosition(dposx<cont.minx?cont.maxx-dwidth:dposx,dposy,1,false); cont.state=false; for(i=0;i<items.length;i++) { item=items.getAt(i); var data=JSON.parse(item.getTag()); if(data!=null) { item.setScale(1,1); item.setPosition(data.posx,data.posy); } item.getProperties().edit().setInteger("i.alpha",255).commit(); } } </sxh>

script_animation_cardstyle.txt · Last modified: 2014/09/24 16:10 by lm13