Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URLs added here will be added as <link>s in order, and before the CSS in the editor. You can use the CSS from another Pen by using its URL and the proper URL extension.

+ add another resource

JavaScript

Babel includes JSX processing.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource

Packages

Add Packages

Search for and use JavaScript packages from npm here. By selecting a package, an import statement will be added to the top of the JavaScript editor for this package.

Behavior

Auto Save

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

HTML

              
                <html ng-app="swipeList">
  <head>
    <meta charset="utf-8">
    <title>List</title>
    <meta name="viewport" content="initial-scale=1, maximum-scale=1, user-scalable=no, width=device-width">
    <link href="https://code.ionicframework.com/1.0.0/css/ionic.min.css" rel="stylesheet">
    <script src="https://code.ionicframework.com/1.0.0/js/ionic.bundle.js"></script>
    <script src="//cdnjs.cloudflare.com/ajax/libs/gsap/1.19.0/TweenMax.min.js"></script>
    <script src="//cdnjs.cloudflare.com/ajax/libs/gsap/1.19.0/utils/Draggable.min.js"></script>
  </head>
  <body ng-controller="DemoController">
    <ion-side-menus>
      <ion-side-menu-content>
        
      <ion-header-bar class="bar-positive">
        <div class="buttons">
            <button class="button button-icon button-clear ion-navicon" menu-toggle="left"></button>
          </div>
        <h1 class="title">Swipe + Hold Items in Ionic</h1>
      </ion-header-bar>
      <ion-content overflow-scroll="true" scrollbar-y="false" has-bouncing="false" class="padding">
        <ion-list can-swipe="false">
                <ion-item item="group" ng-repeat="group in groups" class="item-text-wrap" draggable>
                  <span class="row">
                        <label class="col col-10 checkbox">
                                <input type="checkbox" ng-model="group.selected">
                        </label>
                        <b class="col col-20 columnGroup">
                            {{ group.lounge }}
                        </b>
                        <b class="col col-25 columnGroup {{group.color}}" ng-style="{'color' : '{{group.Color}}'}">
                            {{ group.area }}
                            <i class="icon {{ group.Icon }}"></i>
                        </b>
                        <b class="col col-20 columnGroup">
                            {{ group.degree }}
                        </b>
                        <b class="col col-25 columnGroup">
                            {{ group.monitor }}
                        </b>
                    </span>
                    <ion-option-button class="button-light icon ion-edit"></ion-option-button>
                    <ion-option-button class="button-assertive icon ion-trash-a"></ion-option-button>
                </ion-item>
            </ion-list>
      </ion-side-menu-content>

      <ion-side-menu side="left">
        <ion-header-bar class="bar-positive" align-title="left">
          <h1 class="title">Menu</h1>
        </ion-header-bar>
        <ion-content>
          Left menu!
        </ion-content>
      </ion-side-menu>
    </ion-side-menus>
  </body>
</html>
              
            
!

CSS

              
                b.columnGroup{
    max-height: 40px;
    margin-right: 5px;
    background-color: #f5f5f5;
}
              
            
!

JS

              
                ionic.Gestures.gestures.Hold.defaults.hold_threshold = 20;

var app = angular.module('swipeList', ['ionic']);

app.controller('DemoController', ['$scope', '$ionicSideMenuDelegate', function ($scope, $ionicSideMenuDelegate) {
  
  $ionicSideMenuDelegate.canDragContent(false);
  
  $scope.groups = [
    { selected: true, lounge: "LOL", area: "Game", degree: "1", monitor: "Nicholls" },
    { selected: false, lounge: "WOW", area: "Game", degree: "1", monitor: "Andrea" },
    { selected: false, lounge: "OMG", area: "Expression", degree: "1", monitor: "Osman" },
    { selected: true, lounge: "NaN", area: "None", degree: "2", monitor: "Cuartas" }
  ];
  
} ]);

app.directive('draggable', ['$ionicGesture', function ($ionicGesture) {
    return {
        restrict: 'A',
        link: function (scope, element, attrs) {
          var rowSize   = 0;
          var container = element.parent()[0];
          var content = element.find('item-content');
          
          function changeIndex(item, to, items) {
            // Change position in array
            arrayMove(items, item.index, to);
            if (to === items.length - 1) {
              container.appendChild(item.element);    
            } else {    
              var i = item.index > to ? to : to + 1;
              container.insertBefore(item.element, container.children[i]);
            }
            setIndex(to);
            TweenLite.to(items, 0.15, { yPercent: 0 });
          }
          
          var animation = TweenLite.to(content, 0.3, {
            boxShadow: "rgba(0,0,0,0.2) 0px 16px 32px 0px",
            force3D: true,
            scale: 1.1,
            paused: true
          });

          var dragger = new Draggable(element, {
            onPress: onPress,
            onDragStart: downAction,
            onRelease: upAction,
            onDrag: dragAction,
            cursor: "inherit",    
            type: "y"
          });

          // Public properties and methods
          var sortable = {
            dragger:  dragger,
            element:  element,
            index:    scope.$index,
            setIndex: setIndex
          };
          
          function setIndex(index) {
            sortable.index = index;
            // Don't layout if you're dragging
            if (!dragger.isDragging) layout();
          }
          
          function onPress(){
            var t = this.target,
                i = 0,
                child = t;
            while (child = child.previousSibling)
              if (child.nodeType === 1) i++;
            t.currentIndex = i;
            t.currentHeight = rowSize = t.offsetHeight;
            t.kids = [].slice.call(t.parentNode.children);
          }

          function downAction() {
            animation.play();
            this.update();
          }

          function dragAction() {
            var t = this.target;
            // Calculate the current index based on element's position
            var index = clamp(Math.round(this.y / t.currentHeight), 0, t.kids.length - 1);
console.log(index);
            if (index !== sortable.index) {
              changeIndex(sortable, index, t.kids);
            }
          }

          function upAction() {
            animation.reverse();
            layout();
          }

          function layout() {    
            TweenLite.to(element, 0.3, { y: sortable.index * rowSize });  
          }
          
          
          // Changes an elements's position in array
          function arrayMove(array, from, to) {
            array.splice(to, 0, array.splice(from, 1)[0]);
          }
          
          // Clamps a value to a min/max
          function clamp(value, a, b) {
            return value < a ? a : (value > b ? b : value);
          }
            
            /*dragger.disable();
            $ionicGesture.on('hold', function (e) {
              dragger.enable();
              dragger.startDrag();
            }, element, { hold_threshold: 20 });*/
          
        }
    };
} ]);

              
            
!
999px

Console