PageRenderTime 7436ms CodeModel.GetById 30ms RepoModel.GetById 0ms app.codeStats 0ms

/src/com/cf/view/component/list/ListTile.as

https://github.com/isaacueca/copacino.com
ActionScript | 819 lines | 531 code | 127 blank | 161 comment | 95 complexity | 6d9c4cc3c6b2a033435553d884c3daab MD5 | raw file
  1. package com.cf.view.component.list
  2. {
  3. import com.cf.model.vo.AssetInfo;
  4. import com.cf.model.vo.ListItem;
  5. import com.cf.util.Component;
  6. import com.cf.util.Settings;
  7. import com.cf.util.TextFactory;
  8. import com.cf.util.Utility;
  9. import com.cf.view.component.OpacityLines;
  10. import com.cf.view.component.list.content.ContentBase;
  11. import com.cf.view.component.list.content.ListTileContent;
  12. import com.cf.view.component.list.content.custom.Contact;
  13. import com.cf.view.component.list.content.custom.Newsroom;
  14. import com.cf.view.component.list.content.items.ContentItemBase;
  15. import com.cf.view.component.scrollbar.Scrollbar;
  16. import com.cf.view.event.UIEvent;
  17. import com.greensock.TweenLite;
  18. import com.greensock.TweenMax;
  19. import com.greensock.easing.Strong;
  20. import flash.display.Bitmap;
  21. import flash.display.BitmapData;
  22. import flash.display.DisplayObject;
  23. import flash.display.Sprite;
  24. import flash.events.Event;
  25. import flash.events.MouseEvent;
  26. import flash.text.TextField;
  27. import flashpress.vo.WpPostCategoryVO;
  28. import flashpress.vo.WpPostVO;
  29. public class ListTile extends Component
  30. {
  31. public static const STATE_MINIMIZED:String = "listTileMinimized";
  32. public static const STATE_MAGNIFIED:String = "listTileMagnified";
  33. public static const STATE_MAXIMIZED:String = "listTileMaximized";
  34. public static const STATE_LARGE:String = "listTileLarge";
  35. public static const STATE_HIDDEN:String = "listTileHidden";
  36. private static const INACTIVE_TILE_ALPHA:Number = .4;
  37. private static const TILE_BG_ALPHA:Number = .5;
  38. private static const MAX_SCROLL_SPEED:Number = 30;
  39. // VISUAL
  40. private var _mask:Bitmap;
  41. private var _bg:Sprite;
  42. private var _bgLines:OpacityLines;
  43. private var _shapeSmall:Sprite;
  44. private var _closeButton:Sprite;
  45. private var _scrollbar:Scrollbar;
  46. // CONTAINERS
  47. private var _tagsContainer:Sprite;
  48. private var _navContainer:Sprite;
  49. private var _slidingContainer:Sprite;
  50. private var _contentContainer:Sprite;
  51. private var _content:ContentBase;
  52. private var _contentNav:ContentNavTile;
  53. // CURSORS
  54. private var _cursorContainer:Sprite;
  55. private var _cursor_prev:Sprite;
  56. private var _cursor_next:Sprite;
  57. // DATA
  58. private var _isScrolling :Boolean = false;
  59. private var _isHorzScrollingEnabled :Boolean = false;
  60. private var _scrollbarPercent :Number = 1;
  61. private var _tileHeight :Number;
  62. private var _isFullscreen :Boolean = false;
  63. private var _url :String;
  64. private var _currentIndex :Number = 1;
  65. private var _assetsArray :Array;
  66. public var originalY:Number;
  67. private var _displayIndex:int;
  68. private var _title:String;
  69. private var _color:uint;
  70. private var _listItem:ListItem;
  71. public function ListTile( listItem:ListItem, color:uint, url:String )
  72. {
  73. //_title = title;
  74. _color = color;
  75. _listItem = listItem;
  76. _url = url;
  77. super();
  78. state = STATE_HIDDEN;
  79. //this.addEventListener( MouseEvent.MOUSE_MOVE, mouse_move );
  80. this.addEventListener( Event.ENTER_FRAME, enter_frame );
  81. this.addEventListener( MouseEvent.ROLL_OVER, roll_over );
  82. this.addEventListener( MouseEvent.ROLL_OUT, roll_out );
  83. this.addEventListener( ContentNavItem.EVENT_SET_ACTIVE, contentNav_set_active );
  84. this.addEventListener( MouseEvent.MOUSE_WHEEL, mouse_wheel );
  85. if ( listItem.type == ListItem.LIST_ITEM_TYPE_SECTION ) _tileHeight = Settings.TILE_MARGIN + (Settings.TILE_HEIGHT << 1);
  86. else _tileHeight = Settings.TILE_HEIGHT;
  87. // SMALL SHAPE container
  88. _shapeSmall = new Sprite();
  89. addChild( _shapeSmall );
  90. }
  91. //
  92. // OVERRIDES
  93. //
  94. override protected function init():void
  95. {
  96. // BACKGROUND
  97. _bg = new Sprite();
  98. _bg.addChild( new Bitmap(new BitmapData((stage.stageWidth * Settings.LIST_WIDTH_PERCENT), _tileHeight, false, _color)));
  99. addChild(_bg);
  100. _bg.alpha = TILE_BG_ALPHA;
  101. // BG LINES
  102. _bgLines = new OpacityLines( Settings.CONTENT_LINE_COLOR );
  103. _bgLines.y = 3;
  104. _bgLines.setMinHeight( Settings.CONTENT_AREA_HEIGHT );
  105. _bgLines.setWidth( stage.stageWidth );
  106. // addChild( _bgLines );
  107. _bgLines.alpha = 0;
  108. // MASK
  109. _mask = Utility.getMaskShape( _bg.width, getMaxHeight() );
  110. _mask.width = 0;
  111. addChild( _mask );
  112. this.mask = _mask;
  113. // SLIDING CONTENT CONTAINER
  114. _slidingContainer = new Sprite();
  115. addChild( _slidingContainer );
  116. // CONTENT CONTAINER
  117. _contentContainer = new Sprite();
  118. // _contentContainer.mouseEnabled = _contentContainer.mouseChildren = false;
  119. _slidingContainer.addChild( _contentContainer );
  120. // TAGS CONTAINER
  121. _tagsContainer = new Sprite();
  122. _tagsContainer.mouseChildren = _tagsContainer.mouseEnabled = false;
  123. _slidingContainer.addChild( _tagsContainer );
  124. // NAV CONTAINER
  125. _navContainer = new Sprite();
  126. addChild( _navContainer );
  127. // ADD TITLES
  128. createTitleTags();
  129. // HORIZONTAL SCROLL
  130. _scrollbar = new Scrollbar( getExpectedWidth(), Settings.TILE_ROW_HEIGHT, Scrollbar.ORIENTATION_HORIZONTAL, 1 );
  131. _scrollbar.y = Settings.CONTENT_AREA_HEIGHT;
  132. addChild( _scrollbar );
  133. _scrollbar.visible = false;
  134. _scrollbar.addEventListener( Scrollbar.SCROLLBAR_START, scrollbar_start );
  135. _scrollbar.addEventListener( Scrollbar.SCROLLBAR_STOP, scrollbar_stop );
  136. _scrollbar.addEventListener( Scrollbar.SCROLLBAR_UPDATE, scrollbar_update );
  137. }
  138. override protected function position() : void
  139. {
  140. super.position();
  141. _scrollbar.width = getExpectedWidth();
  142. // BG LINES
  143. _bgLines.setWidth( stage.stageWidth );
  144. if ( state != STATE_HIDDEN )
  145. {
  146. if ( state == STATE_MAXIMIZED )
  147. {
  148. _bg.width = _mask.width = int(stage.stageWidth * Settings.LIST_WIDTH_PERCENT);
  149. _bg.height = Settings.CONTENT_AREA_HEIGHT;
  150. // FIX SCROLLBAR to bottom edge
  151. _scrollbar.y = bottomEdge; // - _scrollbarContainer.height;
  152. }
  153. else if ( state == STATE_MINIMIZED || state == STATE_MAGNIFIED )
  154. {
  155. _bg.width = _mask.width = int(stage.stageWidth * Settings.LIST_WIDTH_PERCENT);
  156. }
  157. else if ( state == STATE_LARGE )
  158. {
  159. _bg.width = stage.stageWidth; // int(stage.stageWidth * Settings.LIST_WIDTH_PERCENT);
  160. _bg.height = stage.stageHeight;
  161. _mask.width = stage.stageWidth;
  162. _mask.height = stage.stageHeight;
  163. // SCROLLBAR
  164. //_scrollbarBg.width = getExpectedWidth();
  165. //_scrollbarGutterBg.width = getListWidth() - 30;
  166. //_scrollbarGutter.x = (_scrollbarBg.width >> 1) - ( _scrollbarGutter.width >> 1 );
  167. _scrollbar.y = stage.stageHeight - _scrollbar.height;
  168. }
  169. // ENABLE / DISABLE HORIZONTAL SCROLLING as necessary
  170. if ( _content != null )
  171. {
  172. scrollAsNeeded();
  173. scrollUsingScrollbar();
  174. }
  175. }
  176. if ( _contentNav != null )
  177. {
  178. _contentNav.y = this.height - Settings.CONTENT_NAV_VERT_MARGIN;
  179. }
  180. }
  181. override public function get height():Number
  182. {
  183. return _bg.height;
  184. }
  185. //
  186. // EVENT HANDLERS
  187. //
  188. // private function stage_mouse_up(e:MouseEvent):void
  189. // {
  190. // stage.removeEventListener( MouseEvent.MOUSE_UP, stage_mouse_up );
  191. // stage.removeEventListener( Event.MOUSE_LEAVE, stage_mouse_leave );
  192. // this.removeEventListener( Event.ENTER_FRAME, enter_frame );
  193. // _isScrolling = false;
  194. // _scrollbarSlider.stopDrag();
  195. // }
  196. // private function stage_mouse_leave(e:Event):void
  197. // {
  198. // //stage_mouse_up(null);
  199. // }
  200. // private function scrollbarSlider_mouse_down(e:MouseEvent):void
  201. // {
  202. // _isScrolling = true;
  203. // stage.addEventListener( MouseEvent.MOUSE_UP, stage_mouse_up );
  204. // stage.addEventListener( Event.MOUSE_LEAVE, stage_mouse_leave );
  205. // this.addEventListener( Event.ENTER_FRAME, enter_frame );
  206. //
  207. // var dragBounds:Rectangle = new Rectangle( 0, _scrollbarSlider.y, _scrollbarGutter.width - _scrollbarSlider.width, 0 );
  208. // _scrollbarSlider.startDrag( false, dragBounds );
  209. // }
  210. private function mouse_wheel( e:MouseEvent ):void
  211. {
  212. if ( (state == STATE_MAXIMIZED || state == STATE_LARGE) && _isHorzScrollingEnabled )
  213. {
  214. /*var toX:Number = Utility.boundNumber( _scrollbarSlider.x - (e.delta * 1000 / ( _scrollbarSlider.width )), _minSlider, _maxSlider );
  215. _scrollbarSlider.x = toX;
  216. var percentScrolled:Number = (_scrollbarSlider.x - _minSlider) / (_maxSlider - _minSlider);
  217. setAmountScrolled( percentScrolled );*/
  218. _scrollbar.scrollByDelta( e.delta );
  219. }
  220. }
  221. private function content_mode_small(e:Event):void
  222. {
  223. // CHANGE url to return to normal
  224. dispatchEvent( new UIEvent( UIEvent.URL_EVENT, _listItem.postData.postTitle, _url + "/" + _currentIndex, true, true ) );
  225. }
  226. private function content_mode_large(e:Event):void
  227. {
  228. // CHANGE url to go large
  229. if ( _currentIndex == 0 ) _currentIndex = 1;
  230. dispatchEvent( new UIEvent( UIEvent.URL_EVENT, _listItem.postData.postTitle, _url + "/" + _currentIndex + "/" + Settings.URL_FLAG_LARGE, true, true ) );
  231. }
  232. private function contentNav_set_active(e:Event):void
  233. {
  234. // DISPATCH event to change url
  235. var item:ContentNavItem = e.target as ContentNavItem;
  236. dispatchEvent( new UIEvent( UIEvent.URL_EVENT, _listItem.postData.postTitle, _url + "/" + item.number, true, true ) );
  237. }
  238. private function roll_over(e:MouseEvent):void
  239. {
  240. if ( this.state == STATE_MINIMIZED && this.listItem.type != ListItem.LIST_ITEM_TYPE_SECTION) _bg.alpha = .8;
  241. }
  242. private function roll_out(e:MouseEvent):void
  243. {
  244. if ( this.state == STATE_MINIMIZED ) _bg.alpha = TILE_BG_ALPHA; // INACTIVE_TILE_ALPHA;
  245. }
  246. private function disableHorzScroll():void
  247. {
  248. // TODO large view positioning
  249. TweenLite.to( _scrollbar, .8, { y: Settings.CONTENT_AREA_HEIGHT - Settings.CONTENT_SCROLL_HORZ_CONTAINER_HEIGHT });
  250. _isHorzScrollingEnabled = false;
  251. _scrollbar.visible = false;
  252. }
  253. private function enableHorzScroll():void
  254. {
  255. // TODO large view positioning
  256. TweenLite.to( _scrollbar, .8, { y: Settings.CONTENT_AREA_HEIGHT });
  257. _isHorzScrollingEnabled = true;
  258. _scrollbar.visible = true;
  259. }
  260. private function showVertScroll():void
  261. {
  262. }
  263. private function content_assets_loaded(e:Event):void
  264. {
  265. // check if scrolling is necessary
  266. scrollAsNeeded();
  267. }
  268. private function scrollUsingScrollbar():void
  269. {
  270. setAmountScrolled( _scrollbar.percentScrolled );
  271. }
  272. private function enter_frame(e:Event):void
  273. {
  274. if ( _isScrolling ) scrollUsingScrollbar();
  275. }
  276. //
  277. // PRIVATE
  278. //
  279. private function scrollbar_stop(e:Event):void
  280. {
  281. _isScrolling = false;
  282. }
  283. private function scrollbar_start(e:Event):void
  284. {
  285. _isScrolling = true;
  286. }
  287. private function scrollbar_update(e:Event):void
  288. {
  289. scrollUsingScrollbar();
  290. }
  291. private function getContentToViewportRatio():Number
  292. {
  293. var contentWidth:Number = _content.width;
  294. var viewableWidth:Number = getExpectedWidth();
  295. //var scrollAreaWidth:Number = getListWidth();
  296. //var scrollbarWidth:Number = (viewableWidth * scrollAreaWidth) / contentWidth;
  297. return viewableWidth / contentWidth;
  298. // return scrollbarWidth;
  299. }
  300. private function scrollAsNeeded():void
  301. {
  302. if ( (_content.width) > getExpectedWidth() )
  303. {
  304. // SCROLLBAR SLIDER WIDTH
  305. // TweenLite.to( _scrollbar, .2, { ease:Strong.easeOut, width: getExpectedScrollbarWidth() });
  306. // SET scrollbar content ratio
  307. _scrollbar.contentRatio = getContentToViewportRatio();
  308. if ( !_isHorzScrollingEnabled ) enableHorzScroll();
  309. }
  310. else
  311. {
  312. if ( _isHorzScrollingEnabled ) disableHorzScroll();
  313. }
  314. }
  315. private function get _minScroll():Number
  316. {
  317. if ( state == STATE_LARGE ) return -Settings.CONTENT_AREA_WIDTH;
  318. else return 0;
  319. }
  320. private function get _maxScroll():Number
  321. {
  322. // if ( state == STATE_LARGE )
  323. // {
  324. // return -_content.contentWidth - getExpectedWidth();
  325. // }
  326. // else
  327. return -_content.contentWidth - Settings.CONTENT_AREA_WIDTH + getExpectedWidth();
  328. }
  329. //private function get _minSlider():Number { return 0; }
  330. //private function get _maxSlider():Number { return _scrollbarGutter.width - _scrollbarSlider.width }
  331. private function setAmountScrolled( percent:Number ):void
  332. {
  333. percent = Utility.boundNumber( percent, 0, 1 );
  334. // trace( percent );
  335. // CONTENT position
  336. var min:Number = getExpectedWidth() - _slidingContainer.width;
  337. _slidingContainer.x = _minScroll + (percent * (_maxScroll - _minScroll)); // Math.min( min, -_slidingContainer.width * percent );
  338. // _copy.scrollV = percent * _copy.maxScrollV;
  339. // SCROLL BAR
  340. // if ( !_isScrolling )
  341. // TweenMax.to( _scrollbarSlider, .5, { ease: Strong.easeOut,
  342. // y: Utility.boundNumber( _minSlider + ( percent * (_maxSlider-_minSlider)), _minSlider, _maxSlider - getExpectedWidth() ) } );
  343. }
  344. private function getExpectedWidth():Number
  345. {
  346. if ( state == STATE_LARGE )
  347. {
  348. return stage.stageWidth;
  349. }
  350. else
  351. {
  352. return getListWidth();
  353. }
  354. }
  355. private function getListWidth():Number
  356. {
  357. return int(stage.stageWidth * Settings.LIST_WIDTH_PERCENT);
  358. }
  359. private function buildContentNav( count:Number ):void
  360. {
  361. //_contentNav = new ContentNavTile( count );
  362. // _contentNav.x = -_contentNav.width;
  363. // _contentNav.alpha = 0;
  364. // TweenLite.to( _contentNav, .8, { alpha:1 } );
  365. // _navContainer.addChild( _contentNav );
  366. position();
  367. }
  368. private function getWidth():Number
  369. {
  370. if ( this.state == STATE_LARGE ) return stage.stageWidth;
  371. else return stage.stageWidth * Settings.LIST_WIDTH_PERCENT;
  372. }
  373. private function getMaxHeight():Number
  374. {
  375. // TODO: make dynamic based on browser height, snapped to lines
  376. return Settings.CONTENT_AREA_HEIGHT;
  377. }
  378. private function createTitleTags():void
  379. {
  380. // GENERATE titles array
  381. var titlesArray:Array = new Array();
  382. if ( _listItem.type == ListItem.LIST_ITEM_TYPE_SECTION ) titlesArray = [ _listItem.sectionTitle ];
  383. else if ( _listItem.type == ListItem.LIST_ITEM_TYPE_POST )
  384. {
  385. // LOOP post tags
  386. for each (var tag:WpPostCategoryVO in _listItem.postData.tags)
  387. {
  388. titlesArray.push( tag.categoryName );
  389. }
  390. // FOR "What's New" - we add a date tile
  391. if ( _listItem.sectionTitle == Settings.NAV_MAIN_NEW )
  392. {
  393. var date:Date = Utility.parseDate( _listItem.postData.postDate );
  394. titlesArray.push( (date.month+1) + "/" + date.date + "/" + date.fullYear );
  395. }
  396. // ADD post title last
  397. titlesArray.push( _listItem.postData.postTitle );
  398. }
  399. // CREATE visual tags
  400. var tileAlpha:Number = 1;
  401. for each (var title:String in titlesArray)
  402. {
  403. addTag( title.toLowerCase(), tileAlpha );
  404. if ( tileAlpha > .2 ) tileAlpha -= .25;
  405. }
  406. }
  407. private var _currentX:Number = 0;
  408. private function addTag(title:String, alpha:Number):void
  409. {
  410. var sprite:Sprite = new Sprite();
  411. sprite.alpha = alpha;
  412. _tagsContainer.addChild( sprite );
  413. // TITLE
  414. var titleText:TextField = TextFactory.TagText( title );
  415. titleText.scaleX = titleText.scaleY = _tileHeight / Settings.TILE_HEIGHT;
  416. sprite.addChild( titleText );
  417. // BACKGROUND
  418. var bg:Bitmap = new Bitmap(new BitmapData(titleText.width + Settings.TILE_TEXT_HORIZONTAL_MARGIN, _tileHeight, false, _color));
  419. sprite.addChildAt( bg, 0 );
  420. // POSITION
  421. titleText.x = (bg.width >> 1) - (titleText.width >> 1);
  422. titleText.y = (bg.height >> 1) - (titleText.height >> 1);
  423. sprite.x = _currentX;
  424. _currentX += bg.width + Settings.TILE_MARGIN;
  425. }
  426. //
  427. // PUBLIC API
  428. //
  429. public function get bottomEdge():Number
  430. {
  431. if ( stage.stageHeight < ( Settings.CONTENT_AREA_HEIGHT + (2 * Settings.CONTENT_SCROLL_HORZ_CONTAINER_HEIGHT) ) )
  432. {
  433. return stage.stageHeight - (2 * Settings.CONTENT_SCROLL_HORZ_CONTAINER_HEIGHT);
  434. }
  435. else
  436. return Settings.CONTENT_AREA_HEIGHT;
  437. }
  438. public function set bgAndMaskHeight(h:Number):void
  439. {
  440. _bg.height = _mask.height = h;
  441. //if ( _isHorzScrollingEnabled )
  442. //{
  443. _mask.height = h + Settings.CONTENT_SCROLL_HORZ_CONTAINER_HEIGHT;
  444. //}
  445. }
  446. public function get bgAndMaskHeight():Number { return _bg.height; }
  447. public function setShapeSmall( ss:Sprite ):void
  448. {
  449. _shapeSmall.x = 0;
  450. _shapeSmall.addChild( ss );
  451. }
  452. public function reveal(delay:Number):void
  453. {
  454. if ( (state != STATE_HIDDEN || state != STATE_MINIMIZED) && listItem.type == ListItem.LIST_ITEM_TYPE_POST ) minimize();
  455. //_mask.width = 0;
  456. _bg.width = int(stage.stageWidth * Settings.LIST_WIDTH_PERCENT);
  457. state = STATE_MINIMIZED;
  458. //trace(this, "reveal", delay);
  459. TweenMax.to( _mask, 2, { ease:Strong.easeInOut, delay:delay, width: int(stage.stageWidth * Settings.LIST_WIDTH_PERCENT) })
  460. }
  461. public function hide(delay:Number):void
  462. {
  463. if ( state == STATE_HIDDEN ) return;
  464. state = STATE_HIDDEN;
  465. TweenMax.to( _mask, 2, { ease:Strong.easeInOut, delay:delay, width: 0 })
  466. }
  467. public function get listItem():ListItem
  468. {
  469. return _listItem;
  470. }
  471. public function createContent():void
  472. {
  473. // CREATE content
  474. switch ( _listItem.postData.postTitle.toLowerCase() )
  475. {
  476. case "newsroom":
  477. _content = new Newsroom( _color );
  478. break;
  479. case "contact":
  480. _content = new Contact( _color );
  481. break;
  482. default:
  483. _content = new ListTileContent( _color );
  484. break;
  485. }
  486. _contentContainer.addEventListener( ContentItemBase.MODE_LARGE, content_mode_large );
  487. _contentContainer.addEventListener( ContentItemBase.MODE_NORMAL, content_mode_small );
  488. _content.addEventListener( ContentBase.ASSETS_LOADED, content_assets_loaded );
  489. _contentContainer.addChild( _content );
  490. }
  491. // GET/SET content
  492. public function get content():ContentBase
  493. {
  494. return _content;
  495. }
  496. public function get tileHeight():Number { return _tileHeight; }
  497. // STATE transitions
  498. public function largify():TweenMax
  499. {
  500. // need to wait for current content item to be ready to transition
  501. if ( state == STATE_LARGE ) return TweenMax.to(this, 0, {});
  502. state = STATE_LARGE;
  503. _content.largify();
  504. // scrollToSegment( _currentIndex, 1 );
  505. // BG HEIGHTEN and TINT
  506. TweenMax.to( _bg, 1, { tint: Settings.CONTENT_OPEN_BG, height: stage.stageHeight, width: stage.stageWidth }); //
  507. // ALIGN scrollbar
  508. TweenMax.to( _scrollbar, 1, { y: stage.stageHeight - _scrollbar.height, width: getExpectedWidth() });
  509. //TweenMax.to( _scrollbarGutter, 1, { x: ( stage.stageWidth - (getListWidth() - 30) >> 1) });
  510. //TweenMax.to( _scrollbarGutterBg, 1, { width: getListWidth() - 30 });
  511. // MASK ENLARGE
  512. TweenMax.to( _mask, 1, { width: stage.stageWidth });
  513. TweenMax.to( _mask, 1, { delay: 1, height: stage.stageHeight });
  514. // TAGS are fixed-position in large mode, instead of scrolling
  515. this.addChild( _tagsContainer );
  516. _tagsContainer.x = -_tagsContainer.width;
  517. // TAGS go back to 100%, push on top of contents
  518. TweenMax.to ( _tagsContainer, .3, { scaleX:1, scaleY:1, y: Settings.LIST_MARGIN_TOP + int(2.5 * (Settings.TILE_HEIGHT)) + Settings.TILE_MARGIN } );
  519. // SLIDE tags X in place
  520. var lastTag:DisplayObject = _tagsContainer.getChildAt(_tagsContainer.numChildren - 1) as DisplayObject;
  521. return TweenMax.to ( _tagsContainer, 1.5, { delay:1.5, x: int(2.5 * Settings.TILE_HEIGHT) + (3 * Settings.TILE_MARGIN) + (1 * -lastTag.x), ease:Strong.easeInOut }); // scaleX:1, scaleY:1, x:0, y:0 } );
  522. }
  523. public function maximize( slideTiles:Boolean = true ):TweenMax
  524. {
  525. if ( _scrollbar ) _scrollbar.percentScrolled = 0;
  526. var prevState:String = state;
  527. if ( state == STATE_MAXIMIZED ) return TweenMax.to(this, 0, {});
  528. if ( state == STATE_HIDDEN ) reveal(0); // NECESSARY in cases where we're just opening the tile for CLOUD_DISPLAY
  529. state = STATE_MAXIMIZED;
  530. // SLIDE tags left till only last tag is shown
  531. var lastTag:DisplayObject = _tagsContainer.getChildAt(_tagsContainer.numChildren - 1) as DisplayObject;
  532. if ( slideTiles )
  533. TweenLite.to( _tagsContainer, .8, { delay:.3, ease:Strong.easeInOut, x: 2 * -lastTag.x } );
  534. // BRIGHTEN all tags
  535. for (var i:int = 0;i < _tagsContainer.numChildren; i++)
  536. {
  537. var s:DisplayObject = _tagsContainer.getChildAt( i );
  538. TweenMax.to(s, 1, { alpha: 1 });
  539. }
  540. // BG LINES
  541. TweenMax.to( _bgLines, 1, { alpha: 1 });
  542. // SHOW CONTENT
  543. if (_content != null)
  544. {
  545. if ( prevState == STATE_LARGE )
  546. {
  547. _content.delargify();
  548. // ALIGN scrollbar
  549. var scrollbarY:Number = Settings.CONTENT_AREA_HEIGHT;
  550. if ( stage.stageHeight < ((Settings.CONTENT_SCROLL_HORZ_CONTAINER_HEIGHT * 2) + Settings.CONTENT_AREA_HEIGHT) )
  551. {
  552. scrollbarY = stage.stageHeight - _scrollbar.height - Settings.CONTENT_SCROLL_HORZ_CONTAINER_HEIGHT;
  553. }
  554. TweenMax.to( _scrollbar, 1, { y: scrollbarY });
  555. //TweenMax.to( _scrollbarBg, 1, { width: getExpectedWidth() });
  556. //TweenMax.to( _scrollbarGutter, 1, { x: 15 });
  557. //TweenMax.to( _scrollbarGutterBg, 1, { width: getExpectedWidth() - 30 });
  558. }
  559. else
  560. {
  561. _content.show();
  562. // CHECK IF scrollbar needs to float
  563. if ( stage.stageHeight < ((Settings.CONTENT_SCROLL_HORZ_CONTAINER_HEIGHT * 2) + Settings.CONTENT_AREA_HEIGHT) )
  564. {
  565. _scrollbar.y = stage.stageHeight - _scrollbar.height - Settings.CONTENT_SCROLL_HORZ_CONTAINER_HEIGHT;
  566. }
  567. }
  568. }
  569. // ENABLE HORIZONTAL SCROLLING
  570. // _isHorzScrollingEnabled = true;
  571. // RETURNING FROM large
  572. if ( prevState == STATE_LARGE )
  573. {
  574. // TINT back
  575. TweenMax.to( _bg, 1, { tint: Settings.CONTENT_OPEN_BG, height: Settings.CONTENT_AREA_HEIGHT });
  576. // SIZE mask + bg: _bg.width
  577. _mask.width = int(stage.stageWidth * Settings.LIST_WIDTH_PERCENT);
  578. // TAGS SLIDE AGAIN
  579. _slidingContainer.addChild( _tagsContainer );
  580. // MOVE BACK
  581. scrollToSegment( _currentIndex, 0 );
  582. }
  583. else
  584. {
  585. // TINT BG
  586. TweenMax.to( _bg, .4, { tint: Settings.CONTENT_OPEN_BG, alpha:1 });
  587. }
  588. TweenMax.to( _tagsContainer, .4, { y: 2 * Settings.TILE_HEIGHT } );
  589. TweenMax.to( _tagsContainer, .2, { ease:Strong.easeInOut, scaleX:2, scaleY:2 } );
  590. // GROW BG AND MASK
  591. return TweenMax.to( this, .4, { ease:Strong.easeInOut, bgAndMaskHeight: getMaxHeight(), alpha:1 });
  592. }
  593. public function magnify():TweenMax
  594. {
  595. state = STATE_MAGNIFIED;
  596. var magnifyTime:Number = 1; //.2;
  597. this.alpha = 1;
  598. var magScale:Number = 1; // 2
  599. // MAGNIFY TAGS
  600. TweenMax.to ( _tagsContainer, magnifyTime, { ease:Strong.easeInOut, scaleX:magScale, scaleY:magScale, x:0, y:0 } );
  601. TweenMax.to( _bg, magnifyTime, { tint: null, alpha:INACTIVE_TILE_ALPHA } );
  602. // GROW BG and MASK
  603. return TweenMax.to( this, magnifyTime, { ease:Strong.easeInOut,
  604. bgAndMaskHeight: (Settings.TILE_HEIGHT * magScale) + ((magScale-1) * Settings.TILE_MARGIN)
  605. });
  606. }
  607. public function minimize():TweenMax
  608. {
  609. var prevState:String = state;
  610. state = STATE_MINIMIZED;
  611. // STOP current tweens
  612. //TweenMax.killTweensOf( this, true );
  613. //TweenMax.killTweensOf( _bg, true );
  614. //TweenMax.killTweensOf( _tagsContainer, true );
  615. // DECIDE close time
  616. var closeTime:Number = 1;//.02;
  617. if (prevState == STATE_MAXIMIZED) // RETURNING from maximized
  618. {
  619. closeTime = .4;
  620. // RESTORE brightness
  621. var tileAlpha:Number = 1;
  622. for (var i:int = 0;i < _tagsContainer.numChildren; i++)
  623. {
  624. var s:DisplayObject = _tagsContainer.getChildAt( i );
  625. TweenMax.to(s, 1, { alpha: tileAlpha });
  626. if ( tileAlpha > .2 ) tileAlpha -= .25;
  627. }
  628. _content.hide();
  629. // BG LINES
  630. TweenMax.to( _bgLines, 1, { alpha: 0 });
  631. }
  632. // RETURN to 1st slide
  633. scrollToSegment( 0 );
  634. // SCALE DOWN and slide to 0
  635. TweenLite.to( _tagsContainer, closeTime, { ease:Strong.easeInOut, scaleX:1, scaleY:1, x:0, y:0 } );
  636. // REMOVE the tint and return the _bg alpha
  637. TweenMax.to( _bg, closeTime, { tint: null, alpha:TILE_BG_ALPHA });
  638. return TweenMax.to( this, closeTime, { ease:Strong.easeInOut, bgAndMaskHeight: Settings.TILE_HEIGHT });
  639. }
  640. public function scrollToSegment( index:Number, delay:Number = 0 ):void
  641. {
  642. if ( _content == null ) return; // TODO: CONTENT isn't loaded, SAVE it for later to jump to specific index
  643. _currentIndex = index;
  644. // ACTIVATE item
  645. _content.setActiveSegment( index );
  646. // CENTER the active item
  647. var item:ContentItemBase = _content.currentActiveContent;
  648. var toX:Number = 0;
  649. var containerWidth:Number;
  650. if ( this.state == STATE_LARGE ) containerWidth = stage.stageWidth;
  651. else containerWidth = stage.stageWidth * Settings.LIST_WIDTH_PERCENT;
  652. if ( item != null )
  653. {
  654. var itemDesiredWidth:Number;
  655. if ( this.state == STATE_LARGE ) itemDesiredWidth = (stage.stageHeight * item.aspectRatio);
  656. else itemDesiredWidth = item.desiredWidth;
  657. var itemDesiredX:Number = item.desiredX;
  658. // if ( this.state == STATE_LARGE ) itemDesiredX = item.desiredX;
  659. // CENTERING
  660. // toX = int(-(Settings.CONTENT_AREA_WIDTH + itemDesiredX) + (containerWidth >> 1) - (itemDesiredWidth >> 1));
  661. // LEFT ALIGN
  662. toX = int(-(Settings.CONTENT_AREA_WIDTH + itemDesiredX));
  663. }
  664. TweenLite.to( _slidingContainer, 1, { ease: Strong.easeInOut, delay:delay, x: Math.min( toX, 0 ) });
  665. }
  666. public function setPostData( postData:WpPostVO ):void
  667. {
  668. _content.postData = postData;
  669. }
  670. public function setAssetsArray( assetsArray:Array ):void // assetsArray = Array of AssetInfo objects
  671. {
  672. // buildContentNav( assetsArray.length + 1 );
  673. _assetsArray = assetsArray;
  674. _content.assetInfoArray = assetsArray;
  675. // TOOD: _content.setData( postData, postAssetsData, postAssets );
  676. }
  677. public function load_complete():void
  678. {
  679. content.load_complete();
  680. }
  681. public function addLoadedAsset( ai:AssetInfo ):void
  682. {
  683. content.addLoadedAsset( ai );
  684. // SCROLLING?
  685. scrollAsNeeded();
  686. }
  687. public function get displayIndex():int { return _displayIndex; }
  688. public function set displayIndex(i:int):void { _displayIndex = i; }
  689. public function get color():uint { return _color; }
  690. }
  691. }