341. EPMO Open Source Coordination Office Redaction File Detail Report

Produced by Araxis Merge on 12/7/2018 11:36:19 AM Central Standard Time. See www.araxis.com for information about Merge. This report uses XHTML and CSS2, and is best viewed with a modern standards-compliant browser. For optimum results when printing this report, use landscape orientation and enable printing of background images and colours in your browser.

341.1 Files compared

# Location File Last Modified
1 C:\SCRUB\MHED\MHED\VATS 2.3.0\var-utility-web-2.3.0@19406cb7810\app\libs\angular-touch\js angular-touch.js Thu Sep 13 18:55:48 2018 UTC
2 C:\MHED-scrubbed\MHED\MHED\VATS 2.3.0\var-utility-web-2.3.0@19406cb7810\app\libs\angular-touch\js angular-touch.js Fri Dec 7 13:48:40 2018 UTC

341.2 Comparison summary

Description Between
Files 1 and 2
Text Blocks Lines
Unchanged 2 1240
Changed 1 4
Inserted 0 0
Removed 0 0

341.3 Comparison options

Whitespace
Character case Differences in character case are significant
Line endings Differences in line endings (CR and LF characters) are ignored
CR/LF characters Not shown in the comparison detail

341.4 Active regular expressions

No regular expressions were active.

341.5 Comparison detail

  1   /**
  2    * @licens e AngularJ S v1.3.5
  3    * (c) 201 0-2014 Goo gle, Inc.  http://ang ularjs.org
  4    * License : MIT
  5    */
  6   (function( window, an gular, und efined) {' use strict ';
  7  
  8   /**
  9    * @ngdoc  module
  10    * @name n gTouch
  11    * @descri ption
  12    *
  13    * # ngTou ch
  14    *
  15    * The `ng Touch` mod ule provid es touch e vents and  other help ers for to uch-enable d devices.
  16    * The imp lementatio n is based  on jQuery  Mobile to uch event  handling
  17    * ([jquer ymobile.co m](http:// jquerymobi le.com/)).
  18    *
  19    *
  20    * See {@l ink ngTouc h.$swipe ` $swipe`} f or usage.
  21    *
  22    * <div do c-module-c omponents= "ngTouch"> </div>
  23    *
  24    */
  25  
  26   // define  ngTouch mo dule
  27   /* global  -ngTouch * /
  28   var ngTouc h = angula r.module(' ngTouch',  []);
  29  
  30   /* global  ngTouch: f alse */
  31  
  32       /**
  33        * @ng doc servic e
  34        * @na me $swipe
  35        *
  36        * @de scription
  37        * The  `$swipe`  service is  a service  that abst racts the  messier de tails of h old-and-dr ag swipe
  38        * beh avior, to  make imple menting sw ipe-relate d directiv es more co nvenient.
  39        *
  40        * Req uires the  {@link ngT ouch `ngTo uch`} modu le to be i nstalled.
  41        *
  42        * `$s wipe` is u sed by the  `ngSwipeL eft` and ` ngSwipeRig ht` direct ives in `n gTouch`, a nd by
  43        * `ng Carousel`  in a separ ate compon ent.
  44        *
  45        * # U sage
  46        * The  `$swipe`  service is  an object  with a si ngle metho d: `bind`.  `bind` ta kes an ele ment
  47        * whi ch is to b e watched  for swipes , and an o bject with  four hand ler functi ons. See t he
  48        * doc umentation  for `bind ` below.
  49        */
  50  
  51   ngTouch.fa ctory('$sw ipe', [fun ction() {
  52     // The t otal dista nce in any  direction  before we  make the  call on sw ipe vs. sc roll.
  53     var MOVE _BUFFER_RA DIUS = 10;
  54  
  55     var POIN TER_EVENTS  = {
  56       'mouse ': {
  57         star t: 'moused own',
  58         move : 'mousemo ve',
  59         end:  'mouseup'
  60       },
  61       'touch ': {
  62         star t: 'touchs tart',
  63         move : 'touchmo ve',
  64         end:  'touchend ',
  65         canc el: 'touch cancel'
  66       }
  67     };
  68  
  69     function  getCoordi nates(even t) {
  70       var to uches = ev ent.touche s && event .touches.l ength ? ev ent.touche s : [event ];
  71       var e  = (event.c hangedTouc hes && eve nt.changed Touches[0] ) ||
  72           (e vent.origi nalEvent & & event.or iginalEven t.changedT ouches &&
  73                event.or iginalEven t.changedT ouches[0])  ||
  74           to uches[0].o riginalEve nt || touc hes[0];
  75  
  76       return  {
  77         x: e .clientX,
  78         y: e .clientY
  79       };
  80     }
  81  
  82     function  getEvents (pointerTy pes, event Type) {
  83       var re s = [];
  84       angula r.forEach( pointerTyp es, functi on(pointer Type) {
  85         var  eventName  = POINTER_ EVENTS[poi nterType][ eventType] ;
  86         if ( eventName)  {
  87           re s.push(eve ntName);
  88         }
  89       });
  90       return  res.join( ' ');
  91     }
  92  
  93     return {
  94       /**
  95        * @ng doc method
  96        * @na me $swipe# bind
  97        *
  98        * @de scription
  99        * The  main meth od of `$sw ipe`. It t akes an el ement to b e watched  for swipe  motions, a nd an
  100        * obj ect contai ning event  handlers.
  101        * The  pointer t ypes that  should be  used can b e specifie d via the  optional
  102        * thi rd argumen t, which i s an array  of string s `'mouse' ` and `'to uch'`. By  default,
  103        * `$s wipe` will  listen fo r `mouse`  and `touch ` events.
  104        *
  105        * The  four even ts are `st art`, `mov e`, `end`,  and `canc el`. `star t`, `move` , and `end `
  106        * rec eive as a  parameter  a coordina tes object  of the fo rm `{ x: 1 50, y: 310  }`.
  107        *
  108        * `st art` is ca lled on ei ther `mous edown` or  `touchstar t`. After  this event , `$swipe`  is
  109        * wat ching for  `touchmove ` or `mous emove` eve nts. These  events ar e ignored  until the  total
  110        * dis tance move d in eithe r dimensio n exceeds  a small th reshold.
  111        *
  112        * Onc e this thr eshold is  exceeded,  either the  horizonta l or verti cal delta  is greater .
  113        * - I f the hori zontal dis tance is g reater, th is is a sw ipe and `m ove` and ` end` event s follow.
  114        * - I f the vert ical dista nce is gre ater, this  is a scro ll, and we  let the b rowser tak e over.
  115        *   A  `cancel`  event is s ent.
  116        *
  117        * `mo ve` is cal led on `mo usemove` a nd `touchm ove` after  the above  logic has  determine d that
  118        * a s wipe is in  progress.
  119        *
  120        * `en d` is call ed when a  swipe is s uccessfull y complete d with a ` touchend`  or `mouseu p`.
  121        *
  122        * `ca ncel` is c alled eith er on a `t ouchcancel ` from the  browser,  or when we  begin scr olling
  123        * as  described  above.
  124        *
  125        */
  126       bind:  function(e lement, ev entHandler s, pointer Types) {
  127         // A bsolute to tal moveme nt, used t o control  swipe vs.  scroll.
  128         var  totalX, to talY;
  129         // C oordinates  of the st art positi on.
  130         var  startCoord s;
  131         // L ast event' s position .
  132         var  lastPos;
  133         // W hether a s wipe is ac tive.
  134         var  active = f alse;
  135  
  136         poin terTypes =  pointerTy pes || ['m ouse', 'to uch'];
  137         elem ent.on(get Events(poi nterTypes,  'start'),  function( event) {
  138           st artCoords  = getCoord inates(eve nt);
  139           ac tive = tru e;
  140           to talX = 0;
  141           to talY = 0;
  142           la stPos = st artCoords;
  143           ev entHandler s['start']  && eventH andlers['s tart'](sta rtCoords,  event);
  144         });
  145         var  events = g etEvents(p ointerType s, 'cancel ');
  146         if ( events) {
  147           el ement.on(e vents, fun ction(even t) {
  148              active = f alse;
  149              eventHandl ers['cance l'] && eve ntHandlers ['cancel'] (event);
  150           }) ;
  151         }
  152  
  153         elem ent.on(get Events(poi nterTypes,  'move'),  function(e vent) {
  154           if  (!active)  return;
  155  
  156           //  Android w ill send a  touchcanc el if it t hinks we'r e starting  to scroll .
  157           //  So when t he total d istance (+  or - or b oth) excee ds 10px in  either di rection,
  158           //  we either :
  159           //  - On tota lX > total Y, we send  preventDe fault() an d treat th is as a sw ipe.
  160           //  - On tota lY > total X, we let  the browse r handle i t as a scr oll.
  161  
  162           if  (!startCo ords) retu rn;
  163           va r coords =  getCoordi nates(even t);
  164  
  165           to talX += Ma th.abs(coo rds.x - la stPos.x);
  166           to talY += Ma th.abs(coo rds.y - la stPos.y);
  167  
  168           la stPos = co ords;
  169  
  170           if  (totalX <  MOVE_BUFF ER_RADIUS  && totalY  < MOVE_BUF FER_RADIUS ) {
  171              return;
  172           }
  173  
  174           //  One of to talX or to talY has e xceeded th e buffer,  so decide  on swipe v s. scroll.
  175           if  (totalY >  totalX) {
  176              // Allow n ative scro lling to t ake over.
  177              active = f alse;
  178              eventHandl ers['cance l'] && eve ntHandlers ['cancel'] (event);
  179              return;
  180           }  else {
  181              // Prevent  the brows er from sc rolling.
  182              event.prev entDefault ();
  183              eventHandl ers['move' ] && event Handlers[' move'](coo rds, event );
  184           }
  185         });
  186  
  187         elem ent.on(get Events(poi nterTypes,  'end'), f unction(ev ent) {
  188           if  (!active)  return;
  189           ac tive = fal se;
  190           ev entHandler s['end'] & & eventHan dlers['end '](getCoor dinates(ev ent), even t);
  191         });
  192       }
  193     };
  194   }]);
  195  
  196   /* global  ngTouch: f alse */
  197  
  198   /**
  199    * @ngdoc  directive
  200    * @name n gClick
  201    *
  202    * @descri ption
  203    * A more  powerful r eplacement  for the d efault ngC lick desig ned to be  used on to uchscreen
  204    * devices . Most mob ile browse rs wait ab out 300ms  after a ta p-and-rele ase before  sending
  205    * the cli ck event.  This versi on handles  them imme diately, a nd then pr events the
  206    * followi ng click e vent from  propagatin g.
  207    *
  208    * Require s the {@li nk ngTouch  `ngTouch` } module t o be insta lled.
  209    *
  210    * This di rective ca n fall bac k to using  an ordina ry click e vent, and  so works o n desktop
  211    * browser s as well  as mobile.
  212    *
  213    * This di rective al so sets th e CSS clas s `ng-clic k-active`  while the  element is  being hel d
  214    * down (b y a mouse  click or t ouch) so y ou can res tyle the d epressed e lement if  you wish.
  215    *
  216    * @elemen t ANY
  217    * @param  {expressio n} ngClick  {@link gu ide/expres sion Expre ssion} to  evaluate
  218    * upon ta p. (Event  object is  available  as `$event `)
  219    *
  220    * @exampl e
  221       <examp le module= "ngClickEx ample" dep s="angular -touch.js" >
  222         <fil e name="in dex.html">
  223           <b utton ng-c lick="coun t = count  + 1" ng-in it="count= 0">
  224              Increment
  225           </ button>
  226           co unt: {{ co unt }}
  227         </fi le>
  228         <fil e name="sc ript.js">
  229           an gular.modu le('ngClic kExample',  ['ngTouch ']);
  230         </fi le>
  231       </exam ple>
  232    */
  233  
  234   ngTouch.co nfig(['$pr ovide', fu nction($pr ovide) {
  235     $provide .decorator ('ngClickD irective',  ['$delega te', funct ion($deleg ate) {
  236       // dro p the defa ult ngClic k directiv e
  237       $deleg ate.shift( );
  238       return  $delegate ;
  239     }]);
  240   }]);
  241  
  242   ngTouch.di rective('n gClick', [ '$parse',  '$timeout' , '$rootEl ement',
  243       functi on($parse,  $timeout,  $rootElem ent) {
  244     var TAP_ DURATION =  750; // S horter tha n 750ms is  a tap, lo nger is a  taphold or  drag.
  245     var MOVE _TOLERANCE  = 12; //  12px seems  to work i n most mob ile browse rs.
  246     var PREV ENT_DURATI ON = 2500;  // 2.5 se conds maxi mum from p reventGhos tClick cal l to click
  247     var CLIC KBUSTER_TH RESHOLD =  25; // 25  pixels in  any dimens ion is the  limit for  busting c licks.
  248  
  249     var ACTI VE_CLASS_N AME = 'ng- click-acti ve';
  250     var last PreventedT ime;
  251     var touc hCoordinat es;
  252     var last LabelClick Coordinate s;
  253  
  254  
  255     // TAP E VENTS AND  GHOST CLIC KS
  256     //
  257     // Why t ap events?
  258     // Mobil e browsers  detect a  tap, then  wait a mom ent (usual ly ~300ms)  to see if  you're
  259     // doubl e-tapping,  and then  fire a cli ck event.
  260     //
  261     // This  delay suck s and make s mobile a pps feel u nresponsiv e.
  262     // So we  detect to uchstart,  touchmove,  touchcanc el and tou chend ours elves and  determine  when
  263     // the u ser has ta pped on so mething.
  264     //
  265     // What  happens wh en the bro wser then  generates  a click ev ent?
  266     // The b rowser, of  course, a lso detect s the tap  and fires  a click af ter a dela y. This re sults in
  267     // tappi ng/clickin g twice. W e do "clic kbusting"  to prevent  it.
  268     //
  269     // How d oes it wor k?
  270     // We at tach globa l touchsta rt and cli ck handler s, that ru n during t he capture  (early) p hase.
  271     // So th e sequence  for a tap  is:
  272     // - glo bal touchs tart: Sets  an "allow able regio n" at the  point touc hed.
  273     // - ele ment's tou chstart: S tarts a to uch
  274     // (- to uchmove or  touchcanc el ends th e touch, n o click fo llows)
  275     // - ele ment's tou chend: Det ermines if  the tap i s valid (d idn't move  too far a way, didn' t hold
  276     //   too  long) and  fires the  user's ta p handler.  The touch end also c alls preve ntGhostCli ck().
  277     // - pre ventGhostC lick() rem oves the a llowable r egion the  global tou chstart cr eated.
  278     // - The  browser g enerates a  click eve nt.
  279     // - The  global cl ick handle r catches  the click,  and check s whether  it was in  an allowab le region.
  280     //     -  If preven tGhostClic k was call ed, the re gion will  have been  removed, t he click i s busted.
  281       //       - If the r egion is s till there , the clic k proceeds  n DNS     y. Therefo re clicks  on links a nd
  282       //         other elem ents witho ut ngTap o n them wor k n DNS     y.
  283     //
  284     // This  is an ugly , terrible  hack!
  285     // Yeah,  tell me a bout it. T he alterna tives are  using the  slow click  events, o r making o ur users
  286     // deal  with the g host click s, so I co nsider thi s the leas t of evils . Fortunat ely Angula r
  287     // encap sulates th is ugly lo gic away f rom the us er.
  288     //
  289     // Why n ot just pu t click ha ndlers on  the elemen t?
  290     // We do  that too,  just to b e sure. If  the tap e vent cause d the DOM  to change,
  291     // it is  possible  another el ement is n ow in that  position.  To take a ccount for  these pos sibly
  292     // disti nct elemen ts, the ha ndlers are  global an d care onl y about co ordinates.
  293  
  294     // Check s if the c oordinates  are close  enough to  be within  the regio n.
  295     function  hit(x1, y 1, x2, y2)  {
  296       return  Math.abs( x1 - x2) <  CLICKBUST ER_THRESHO LD && Math .abs(y1 -  y2) < CLIC KBUSTER_TH RESHOLD;
  297     }
  298  
  299     // Check s a list o f allowabl e regions  against a  click loca tion.
  300     // Retur ns true if  the click  should be  allowed.
  301     // Splic es out the  allowable  region fr om the lis t after it  has been  used.
  302     function  checkAllo wableRegio ns(touchCo ordinates,  x, y) {
  303       for (v ar i = 0;  i < touchC oordinates .length; i  += 2) {
  304         if ( hit(touchC oordinates [i], touch Coordinate s[i + 1],  x, y)) {
  305           to uchCoordin ates.splic e(i, i + 2 );
  306           re turn true;  // allowa ble region
  307         }
  308       }
  309       return  false; //  No allowa ble region ; bust it.
  310     }
  311  
  312     // Globa l click ha ndler that  prevents  the click  if it's in  a bustabl e zone and  preventGh ostClick
  313     // was c alled rece ntly.
  314     function  onClick(e vent) {
  315       if (Da te.now() -  lastPreve ntedTime >  PREVENT_D URATION) {
  316         retu rn; // Too  old.
  317       }
  318  
  319       var to uches = ev ent.touche s && event .touches.l ength ? ev ent.touche s : [event ];
  320       var x  = touches[ 0].clientX ;
  321       var y  = touches[ 0].clientY ;
  322       // Wor k around d esktop Web kit quirk  where clic king a lab el will fi re two cli cks (on th e label
  323       // and  on the in put elemen t). Depend ing on the  exact bro wser, this  second cl ick we don 't want
  324       // to  bust has e ither (0,0 ), negativ e coordina tes, or co ordinates  equal to t riggering  label
  325       // cli ck event
  326       if (x  < 1 && y <  1) {
  327         retu rn; // off screen
  328       }
  329       if (la stLabelCli ckCoordina tes &&
  330           la stLabelCli ckCoordina tes[0] ===  x && last LabelClick Coordinate s[1] === y ) {
  331         retu rn; // inp ut click t riggered b y label cl ick
  332       }
  333       // res et label c lick coord inates on  first subs equent cli ck
  334       if (la stLabelCli ckCoordina tes) {
  335         last LabelClick Coordinate s = null;
  336       }
  337       // rem ember labe l click co ordinates  to prevent  click bus ting of tr igger clic k event on  input
  338       if (ev ent.target .tagName.t oLowerCase () === 'la bel') {
  339         last LabelClick Coordinate s = [x, y] ;
  340       }
  341  
  342       // Loo k for an a llowable r egion cont aining thi s click.
  343       // If  we find on e, that me ans it was  created b y touchsta rt and not  removed b y
  344       // pre ventGhostC lick, so w e don't bu st it.
  345       if (ch eckAllowab leRegions( touchCoord inates, x,  y)) {
  346         retu rn;
  347       }
  348  
  349       // If  we didn't  find an al lowable re gion, bust  the click .
  350       event. stopPropag ation();
  351       event. preventDef ault();
  352  
  353       // Blu r focused  form eleme nts
  354       event. target &&  event.targ et.blur();
  355     }
  356  
  357  
  358     // Globa l touchsta rt handler  that crea tes an all owable reg ion for a  click even t.
  359     // This  allowable  region can  be remove d by preve ntGhostCli ck if we w ant to bus t it.
  360     function  onTouchSt art(event)  {
  361       var to uches = ev ent.touche s && event .touches.l ength ? ev ent.touche s : [event ];
  362       var x  = touches[ 0].clientX ;
  363       var y  = touches[ 0].clientY ;
  364       touchC oordinates .push(x, y );
  365  
  366       $timeo ut(functio n() {
  367         // R emove the  allowable  region.
  368         for  (var i = 0 ; i < touc hCoordinat es.length;  i += 2) {
  369           if  (touchCoo rdinates[i ] == x &&  touchCoord inates[i +  1] == y)  {
  370              touchCoord inates.spl ice(i, i +  2);
  371              return;
  372           }
  373         }
  374       }, PRE VENT_DURAT ION, false );
  375     }
  376  
  377     // On th e first ca ll, attach es some ev ent handle rs. Then w henever it  gets call ed, it cre ates a
  378     // zone  around the  touchstar t where cl icks will  get busted .
  379     function  preventGh ostClick(x , y) {
  380       if (!t ouchCoordi nates) {
  381         $roo tElement[0 ].addEvent Listener(' click', on Click, tru e);
  382         $roo tElement[0 ].addEvent Listener(' touchstart ', onTouch Start, tru e);
  383         touc hCoordinat es = [];
  384       }
  385  
  386       lastPr eventedTim e = Date.n ow();
  387  
  388       checkA llowableRe gions(touc hCoordinat es, x, y);
  389     }
  390  
  391     // Actua l linking  function.
  392     return f unction(sc ope, eleme nt, attr)  {
  393       var cl ickHandler  = $parse( attr.ngCli ck),
  394           ta pping = fa lse,
  395           ta pElement,   // Used t o blur the  element a fter a tap .
  396           st artTime,    // Used t o check if  the tap w as held to o long.
  397           to uchStartX,
  398           to uchStartY;
  399  
  400       functi on resetSt ate() {
  401         tapp ing = fals e;
  402         elem ent.remove Class(ACTI VE_CLASS_N AME);
  403       }
  404  
  405       elemen t.on('touc hstart', f unction(ev ent) {
  406         tapp ing = true ;
  407         tapE lement = e vent.targe t ? event. target : e vent.srcEl ement; //  IE uses sr cElement.
  408         // H ack for Sa fari, whic h can targ et text no des instea d of conta iners.
  409         if ( tapElement .nodeType  == 3) {
  410           ta pElement =  tapElemen t.parentNo de;
  411         }
  412  
  413         elem ent.addCla ss(ACTIVE_ CLASS_NAME );
  414  
  415         star tTime = Da te.now();
  416  
  417         var  touches =  event.touc hes && eve nt.touches .length ?  event.touc hes : [eve nt];
  418         var  e = touche s[0].origi nalEvent | | touches[ 0];
  419         touc hStartX =  e.clientX;
  420         touc hStartY =  e.clientY;
  421       });
  422  
  423       elemen t.on('touc hmove', fu nction(eve nt) {
  424         rese tState();
  425       });
  426  
  427       elemen t.on('touc hcancel',  function(e vent) {
  428         rese tState();
  429       });
  430  
  431       elemen t.on('touc hend', fun ction(even t) {
  432         var  diff = Dat e.now() -  startTime;
  433  
  434         var  touches =  (event.cha ngedTouche s && event .changedTo uches.leng th) ? even t.changedT ouches :
  435              ((event.to uches && e vent.touch es.length)  ? event.t ouches : [ event]);
  436         var  e = touche s[0].origi nalEvent | | touches[ 0];
  437         var  x = e.clie ntX;
  438         var  y = e.clie ntY;
  439         var  dist = Mat h.sqrt(Mat h.pow(x -  touchStart X, 2) + Ma th.pow(y -  touchStar tY, 2));
  440  
  441         if ( tapping &&  diff < TA P_DURATION  && dist <  MOVE_TOLE RANCE) {
  442           //  Call prev entGhostCl ick so the  clickbust er will ca tch the co rrespondin g click.
  443           pr eventGhost Click(x, y );
  444  
  445           //  Blur the  focused el ement (the  button, p robably) b efore firi ng the cal lback.
  446           //  This does n't work p erfectly o n Android  Chrome, bu t seems to  work else where.
  447           //  I couldn' t get anyt hing to wo rk reliabl y on Andro id Chrome.
  448           if  (tapEleme nt) {
  449              tapElement .blur();
  450           }
  451  
  452           if  (!angular .isDefined (attr.disa bled) || a ttr.disabl ed === fal se) {
  453              element.tr iggerHandl er('click' , [event]) ;
  454           }
  455         }
  456  
  457         rese tState();
  458       });
  459  
  460       // Hac k for iOS  Safari's b enefit. It  goes sear ching for  onclick ha ndlers and  is liable  to click
  461       // som ething els e nearby.
  462       elemen t.onclick  = function (event) {  };
  463  
  464       // Act ual click  handler.
  465       // The re are thr ee differe nt kinds o f clicks,  only two o f which re ach this p oint.
  466       // - O n desktop  browsers w ithout tou ch events,  their cli cks will a lways come  here.
  467       // - O n mobile b rowsers, t he simulat ed "fast"  click will  call this .
  468       // - B ut the bro wser's fol low-up slo w click wi ll be "bus ted" befor e it reach es this ha ndler.
  469       // The refore it' s safe to  use this d irective o n both mob ile and de sktop.
  470       elemen t.on('clic k', functi on(event,  touchend)  {
  471         scop e.$apply(f unction()  {
  472           cl ickHandler (scope, {$ event: (to uchend ||  event)});
  473         });
  474       });
  475  
  476       elemen t.on('mous edown', fu nction(eve nt) {
  477         elem ent.addCla ss(ACTIVE_ CLASS_NAME );
  478       });
  479  
  480       elemen t.on('mous emove mous eup', func tion(event ) {
  481         elem ent.remove Class(ACTI VE_CLASS_N AME);
  482       });
  483  
  484     };
  485   }]);
  486  
  487   /* global  ngTouch: f alse */
  488  
  489   /**
  490    * @ngdoc  directive
  491    * @name n gSwipeLeft
  492    *
  493    * @descri ption
  494    * Specify  custom be havior whe n an eleme nt is swip ed to the  left on a  touchscree n device.
  495    * A leftw ard swipe  is a quick , right-to -left slid e of the f inger.
  496    * Though  ngSwipeLef t is desig ned for to uch-based  devices, i t will wor k with a m ouse click  and drag
  497    * too.
  498    *
  499    * To disa ble the mo use click  and drag f unctionali ty, add `n g-swipe-di sable-mous e` to
  500    * the `ng -swipe-lef t` or `ng- swipe-righ t` DOM Ele ment.
  501    *
  502    * Require s the {@li nk ngTouch  `ngTouch` } module t o be insta lled.
  503    *
  504    * @elemen t ANY
  505    * @param  {expressio n} ngSwipe Left {@lin k guide/ex pression E xpression}  to evalua te
  506    * upon le ft swipe.  (Event obj ect is ava ilable as  `$event`)
  507    *
  508    * @exampl e
  509       <examp le module= "ngSwipeLe ftExample"  deps="ang ular-touch .js">
  510         <fil e name="in dex.html">
  511           <d iv ng-show ="!showAct ions" ng-s wipe-left= "showActio ns = true" >
  512              Some list  content, l ike an ema il in the  inbox
  513           </ div>
  514           <d iv ng-show ="showActi ons" ng-sw ipe-right= "showActio ns = false ">
  515              <button ng -click="re ply()">Rep ly</button >
  516              <button ng -click="de lete()">De lete</butt on>
  517           </ div>
  518         </fi le>
  519         <fil e name="sc ript.js">
  520           an gular.modu le('ngSwip eLeftExamp le', ['ngT ouch']);
  521         </fi le>
  522       </exam ple>
  523    */
  524  
  525   /**
  526    * @ngdoc  directive
  527    * @name n gSwipeRigh t
  528    *
  529    * @descri ption
  530    * Specify  custom be havior whe n an eleme nt is swip ed to the  right on a  touchscre en device.
  531    * A right ward swipe  is a quic k, left-to -right sli de of the  finger.
  532    * Though  ngSwipeRig ht is desi gned for t ouch-based  devices,  it will wo rk with a  mouse clic k and drag
  533    * too.
  534    *
  535    * Require s the {@li nk ngTouch  `ngTouch` } module t o be insta lled.
  536    *
  537    * @elemen t ANY
  538    * @param  {expressio n} ngSwipe Right {@li nk guide/e xpression  Expression } to evalu ate
  539    * upon ri ght swipe.  (Event ob ject is av ailable as  `$event`)
  540    *
  541    * @exampl e
  542       <examp le module= "ngSwipeRi ghtExample " deps="an gular-touc h.js">
  543         <fil e name="in dex.html">
  544           <d iv ng-show ="!showAct ions" ng-s wipe-left= "showActio ns = true" >
  545              Some list  content, l ike an ema il in the  inbox
  546           </ div>
  547           <d iv ng-show ="showActi ons" ng-sw ipe-right= "showActio ns = false ">
  548              <button ng -click="re ply()">Rep ly</button >
  549              <button ng -click="de lete()">De lete</butt on>
  550           </ div>
  551         </fi le>
  552         <fil e name="sc ript.js">
  553           an gular.modu le('ngSwip eRightExam ple', ['ng Touch']);
  554         </fi le>
  555       </exam ple>
  556    */
  557  
  558   function m akeSwipeDi rective(di rectiveNam e, directi on, eventN ame) {
  559     ngTouch. directive( directiveN ame, ['$pa rse', '$sw ipe', func tion($pars e, $swipe)  {
  560       // The  maximum v ertical de lta for a  swipe shou ld be less  than 75px .
  561       var MA X_VERTICAL _DISTANCE  = 75;
  562       // Ver tical dist ance shoul d not be m ore than a  fraction  of the hor izontal di stance.
  563       var MA X_VERTICAL _RATIO = 0 .3;
  564       // At  least a 30 px lateral  motion is  necessary  for a swi pe.
  565       var MI N_HORIZONT AL_DISTANC E = 30;
  566  
  567       return  function( scope, ele ment, attr ) {
  568         var  swipeHandl er = $pars e(attr[dir ectiveName ]);
  569  
  570         var  startCoord s, valid;
  571  
  572         func tion valid Swipe(coor ds) {
  573           //  Check tha t it's wit hin the co ordinates.
  574           //  Absolute  vertical d istance mu st be with in toleran ces.
  575           //  Horizonta l distance , we take  the curren t X - the  starting X .
  576           //  This is n egative fo r leftward  swipes an d positive  for right ward swipe s.
  577           //  After mul tiplying b y the dire ction (-1  for left,  +1 for rig ht), legal  swipes
  578           //  (ie. same  direction  as the di rective wa nts) will  have a pos itive delt a and
  579           //  illegal o nes a nega tive delta .
  580           //  Therefore  this delt a must be  positive,  and larger  than the  minimum.
  581           if  (!startCo ords) retu rn false;
  582           va r deltaY =  Math.abs( coords.y -  startCoor ds.y);
  583           va r deltaX =  (coords.x  - startCo ords.x) *  direction;
  584           re turn valid  && // Sho rt circuit  for alrea dy-invalid ated swipe s.
  585                deltaY <  MAX_VERTI CAL_DISTAN CE &&
  586                deltaX >  0 &&
  587                deltaX >  MIN_HORIZ ONTAL_DIST ANCE &&
  588                deltaY /  deltaX <  MAX_VERTIC AL_RATIO;
  589         }
  590  
  591         var  pointerTyp es = ['tou ch'];
  592         if ( !angular.i sDefined(a ttr['ngSwi peDisableM ouse'])) {
  593           po interTypes .push('mou se');
  594         }
  595         $swi pe.bind(el ement, {
  596           's tart': fun ction(coor ds, event)  {
  597              startCoord s = coords ;
  598              valid = tr ue;
  599           },
  600           'c ancel': fu nction(eve nt) {
  601              valid = fa lse;
  602           },
  603           'e nd': funct ion(coords , event) {
  604              if (validS wipe(coord s)) {
  605                scope.$a pply(funct ion() {
  606                  elemen t.triggerH andler(eve ntName);
  607                  swipeH andler(sco pe, {$even t: event}) ;
  608                });
  609              }
  610           }
  611         }, p ointerType s);
  612       };
  613     }]);
  614   }
  615  
  616   // Left is  negative  X-coordina te, right  is positiv e.
  617   makeSwipeD irective(' ngSwipeLef t', -1, 's wipeleft') ;
  618   makeSwipeD irective(' ngSwipeRig ht', 1, 's wiperight' );
  619  
  620  
  621  
  622   })(window,  window.an gular);