Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URL's 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 it's URL and the proper URL extention.

+ 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

Save Automatically?

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="ionicApp">
  <head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no">
    <title>Ionic List Directive</title>
   
    <link href="//code.ionicframework.com/nightly/css/ionic.css" rel="stylesheet">
    <script src="//code.ionicframework.com/nightly/js/ionic.bundle.js"></script>
  </head>

  <body ng-controller="MyCtrl">
    
    <ion-header-bar class="bar-positive">
      <div class="buttons">
        <button class="button button-icon icon ion-ios7-minus-outline" 
          ng-click="data.showDelete = !data.showDelete; data.showReorder = false"></button>
      <h1 class="title">Ionic Delete/Option Buttons</h1>
      <button class="button"
          ng-click="data.showDelete = false; data.showReorder = !data.showReorder">
            Reorder
          </button>
      </div>
    </ion-header-bar>

    <ion-content>

      <!-- The list directive is great, but be sure to also checkout the collection repeat directive when scrolling through large lists -->
      
      <ion-list click-for-options-wrapper show-delete="data.showDelete" show-reorder="data.showReorder">

        <ion-item click-for-options ng-repeat="item in items"  class="item item-avatar"
                  item="item">
          <img src="http://placehold.it/150x150">
          Item {{ item.id }}
          <ion-delete-button class="ion-minus-circled" 
                             ng-click="onItemDelete(item)">
          </ion-delete-button>
          <ion-option-button class="button-assertive"
                             ng-click="edit(item)">
            Edit
          </ion-option-button>
          <ion-option-button class="button-calm"
                             ng-click="share(item)">
            Share
          </ion-option-button>
          <ion-reorder-button class="ion-navicon" on-reorder="moveItem(item, $fromIndex, $toIndex)"></ion-reorder-button>
        </ion-item>

      </ion-list>

    </ion-content>
      
  </body>
</html>
              
            
!

CSS

              
                body {
  cursor: url('https://ionicframework.com/img/finger.png'), auto;
}
              
            
!

JS

              
                angular.module('ionicApp', ['ionic'])

.directive('clickForOptionsWrapper', [function() {
	return {
		restrict: 'A',
		controller: function($scope) {
			this.closeOptions = function() {
				$scope.$broadcast('closeOptions');
			}
		}
	};
}])

.directive('clickForOptions', ['$ionicGesture', function($ionicGesture) {
	return {
		restrict: 'A',
		scope: false,
		require: '^clickForOptionsWrapper',
		link: function (scope, element, attrs, parentController) {
			// A basic variable that determines wether the element was currently clicked
			var clicked;

			// Set an initial attribute for the show state
			attrs.$set('optionButtons', 'hidden');

			// Grab the content
			var content = element[0].querySelector('.item-content');

			// Grab the buttons and their width
			var buttons = element[0].querySelector('.item-options');			

			var closeAll = function() {
				element.parent()[0].$set('optionButtons', 'show');
			};

			// Add a listener for the broadcast event from the parent directive to close
			var previouslyOpenedElement;
			scope.$on('closeOptions', function() {
				if (!clicked) {
					attrs.$set('optionButtons', 'hidden');
				}
			});

			// Function to show the options
			var showOptions = function() {
				// close all potentially opened items first
				parentController.closeOptions();

				var buttonsWidth = buttons.offsetWidth;
				ionic.requestAnimationFrame(function() {
					// Add the transition settings to the content
					content.style[ionic.CSS.TRANSITION] = 'all ease-out .25s';

					// Make the buttons visible and animate the content to the left
					buttons.classList.remove('invisible');
					content.style[ionic.CSS.TRANSFORM] = 'translate3d(-' + buttonsWidth + 'px, 0, 0)';

					// Remove the transition settings from the content
					// And set the "clicked" variable to false
					setTimeout(function() {
						content.style[ionic.CSS.TRANSITION] = '';
						clicked = false;
					}, 250);
				});		
			};

			// Function to hide the options
			var hideOptions = function() {
				var buttonsWidth = buttons.offsetWidth;
				ionic.requestAnimationFrame(function() {
					// Add the transition settings to the content
					content.style[ionic.CSS.TRANSITION] = 'all ease-out .25s';

					// Move the content back to the original position
					content.style[ionic.CSS.TRANSFORM] = '';
					
					// Make the buttons invisible again
					// And remove the transition settings from the content
					setTimeout(function() {
						buttons.classList.add('invisible');
						content.style[ionic.CSS.TRANSITION] = '';
					}, 250);				
				});
			};

			// Watch the open attribute for changes and call the corresponding function
			attrs.$observe('optionButtons', function(value){
				if (value == 'show') {
					showOptions();
				} else {
					hideOptions();
				}
			});

			// Change the open attribute on tap
			$ionicGesture.on('tap', function(e){
				clicked = true;
				if (attrs.optionButtons == 'show') {
					attrs.$set('optionButtons', 'hidden');
				} else {
					attrs.$set('optionButtons', 'show');
				}
			}, element);
		}
	};
}])

.controller('MyCtrl', function($scope) {
  
  $scope.data = {
    showDelete: false
  };
  
  $scope.edit = function(item) {
    alert('Edit Item: ' + item.id);
  };
  $scope.share = function(item) {
    alert('Share Item: ' + item.id);
  };
  
  $scope.moveItem = function(item, fromIndex, toIndex) {
    $scope.items.splice(fromIndex, 1);
    $scope.items.splice(toIndex, 0, item);
  };
  
  $scope.onItemDelete = function(item) {
    $scope.items.splice($scope.items.indexOf(item), 1);
  };
  
  $scope.items = [
    { id: 0 },
    { id: 1 },
    { id: 2 },
    { id: 3 },
    { id: 4 },
    { id: 5 },
    { id: 6 },
    { id: 7 },
    { id: 8 },
    { id: 9 },
    { id: 10 },
    { id: 11 },
    { id: 12 },
    { id: 13 },
    { id: 14 },
    { id: 15 },
    { id: 16 },
    { id: 17 },
    { id: 18 },
    { id: 19 },
    { id: 20 },
    { id: 21 },
    { id: 22 },
    { id: 23 },
    { id: 24 },
    { id: 25 },
    { id: 26 },
    { id: 27 },
    { id: 28 },
    { id: 29 },
    { id: 30 },
    { id: 31 },
    { id: 32 },
    { id: 33 },
    { id: 34 },
    { id: 35 },
    { id: 36 },
    { id: 37 },
    { id: 38 },
    { id: 39 },
    { id: 40 },
    { id: 41 },
    { id: 42 },
    { id: 43 },
    { id: 44 },
    { id: 45 },
    { id: 46 },
    { id: 47 },
    { id: 48 },
    { id: 49 },
    { id: 50 }
  ];
  
});
              
            
!
999px

Console