Advertisement
Guest User

Untitled

a guest
Jun 1st, 2016
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. _.namespace('PORSCHE.View.SplitterContainer');
  2. PORSCHE.View.SplitterContainer = PORSCHE.View.Module.extend({
  3.  
  4.         tag: 'tagName',
  5.         className: 'module',
  6.         templateHTML: undefined,
  7.  
  8.         usedElements: {
  9.             $splitter: undefined,
  10.             $dragger: undefined,
  11.             $left: undefined,
  12.             $right: undefined,
  13.             $leftContent: undefined,
  14.             $rightContent: undefined
  15.         },
  16.         prevWidth: undefined,
  17.         fullwidth: undefined,
  18.  
  19.         initialize: function (options)
  20.         {
  21.         },
  22.  
  23.         render: function ()
  24.         {
  25.             this.$el.html(this.model.get('templateHTML'));
  26.             var dataModel = this.model.get("dataModel");
  27.             var background1 = dataModel.splitter.background1;
  28.             var background2 = dataModel.splitter.background2;
  29.  
  30.             this.usedElements = {
  31.                 $splitter: this.$el.find('.splitterParentContainer'),
  32.                 $dragger: this.$el.find('.splitterDragger'),
  33.                 $left: this.$el.find('.splitterLeftContainer'),
  34.                 $right: this.$el.find('.splitterRightContainer'),
  35.                 $leftContent: this.$el.find('.splitterLeftContainer > div'),
  36.                 $rightContent: this.$el.find('.splitterRightContainer > div')
  37.             };
  38.  
  39.             // Dummy image to resize the container properly
  40.             this.usedElements.$splitter.append("<img src='" + background1 + "' class='dummy-image'/>");
  41.  
  42.             // Click events
  43.             this.usedElements.$left.on('click', _.bind(this.onClick, this));
  44.             this.usedElements.$right.on('click', _.bind(this.onClick, this));
  45.  
  46.             // Resize events
  47.             $(window).on('resize', _.bind(this.onResize, this));
  48.  
  49.             if (Draggable)
  50.             {
  51.                 Draggable.create(this.usedElements.$dragger, {
  52.                     type: "left",
  53.                     lockAxis: true,
  54.  
  55.                     throwProps: true,
  56.                     overshootTolerance: 0,
  57.  
  58.                     bounds: this.usedElements.$splitter,
  59.  
  60.                     onDrag: this.onDrag,
  61.                     onDragParams: [this],
  62.  
  63.                     onDragStart: this.onDragStart,
  64.                     onDragStartParams: [this],
  65.  
  66.                     onThrowComplete: this.onThrowComplete,
  67.                     onThrowCompleteParams: [this],
  68.  
  69.                     onThrowUpdate: this.onThrowUpdate,
  70.                     onThrowUpdateParams: [this]
  71.  
  72.                 })
  73.                 ;
  74.             }
  75.  
  76.             this.usedElements.$left.css('background-image', "url(" + background1 + ")");
  77.             this.usedElements.$right.css('background-image', "url(" + background2 + ")");
  78.  
  79.             return this;
  80.         },
  81.  
  82.  
  83.         // LISTENERS
  84.  
  85.         onDragStart: function (splitterView)
  86.         {
  87.             splitterView.fullwidth = splitterView.usedElements.$splitter.actual('width');
  88.         },
  89.         onDrag: function (splitterView)
  90.         {
  91.             splitterView.updateContainers(this.x);
  92.         },
  93.         onThrowComplete: function (splitterView)
  94.         {
  95.             splitterView.updateContainers(this.endX);
  96.         },
  97.         onThrowUpdate: function (splitterView)
  98.         {
  99.             splitterView.updateContainers(this.x);
  100.         },
  101.         onClick: function (event)
  102.         {
  103.             this.fullwidth = this.usedElements.$splitter.actual('width');
  104.             var eventLeft = event.clientX - this.usedElements.$splitter.offset().left;
  105.             this.animateToPosition(eventLeft);
  106.         },
  107.         onResize: function ()
  108.         {
  109.             this.fullwidth = this.usedElements.$splitter.actual('width');
  110.             this.animateToPosition(this.fullwidth / 2);
  111.         },
  112.  
  113.         // DOM MANIPULATION
  114.  
  115.         updateContainers: function (pos)
  116.         {
  117.             pos = _.calculateInRangeValue(pos, 0, this.fullwidth);
  118.             TweenMax.set(
  119.                 this.usedElements.$left,
  120.                 {
  121.                     css: {
  122.                         width: pos + 'px'
  123.                     }
  124.                 }
  125.             );
  126.             TweenMax.set(
  127.                 this.usedElements.$right,
  128.                 {
  129.                     css: {
  130.                         width: (this.fullwidth - pos) + 'px'
  131.                     }
  132.                 }
  133.             );
  134.         },
  135.  
  136.  
  137.         // ANIMATION
  138.  
  139.         introAnimation: function (pos)
  140.         {
  141.             TweenMax.to(this.usedElements.$dragger, 0, {
  142.                 left: pos,
  143.                 onUpdate: this.updateContainers(this.usedElements.$splitter.actual('width') / 2)
  144.             });
  145.         },
  146.         animateToPosition: function (pos)
  147.         {
  148.             var currentLeft = parseInt(this.usedElements.$dragger.css('left'));
  149.             var tweenTarget = {left: currentLeft};
  150.             TweenMax.to(tweenTarget, 1, {
  151.                 left: pos,
  152.                 onUpdate: function (splitterView, tween)
  153.                 {
  154.                     TweenMax.set(
  155.                         splitterView.usedElements.$dragger,
  156.                         {
  157.                             css: {
  158.                                 left: tweenTarget.left + 'px'
  159.                             }
  160.                         }
  161.                     );
  162.  
  163.                     splitterView.updateContainers(tweenTarget.left);
  164.                 },
  165.                 onUpdateParams: [this, '{self}']
  166.             });
  167.         }
  168.  
  169.     })
  170.     ;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement