Skip to content

Instantly share code, notes, and snippets.

@hailiang-wang
Created December 21, 2014 07:30
Show Gist options
  • Save hailiang-wang/fc4d0e97e4d6b7106c7e to your computer and use it in GitHub Desktop.
Save hailiang-wang/fc4d0e97e4d6b7106c7e to your computer and use it in GitHub Desktop.
GgqzKM
<html ng-app="navTest">
<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 rel="stylesheet" href="http://code.ionicframework.com/1.0.0-beta.1/css/ionic.css">
<script src="http://code.ionicframework.com/1.0.0-beta.1/js/ionic.bundle.js"></script>
<style>
#click-notify {
position: absolute;
display: none;
top: 150px;
left: 48%;
z-index: 9999;
background: red;
}
</style>
</head>
<body ng-controller="TestCtrl">
<div id="click-notify">CLICK!</div>
<ion-side-menus>
<ion-side-menu-content>
<ion-header-bar class="bar-positive">
<div class="buttons">
<button ng-click="toggleDelete()" class="button button-clear">{{ editBtnText }}</button>
<button ng-click="toggleLeft()" class="button">Toggle Left Menu</button>
</div>
<h1 class="title">List Tests</h1>
<div class="buttons">
<button ng-click="toggleReorder()" class="button button-clear">{{ reorderBtnText }}</button>
</div>
</ion-header-bar>
<ion-content class="has-header">
<ion-list show-delete="isDeletingItems"
show-reorder="isReorderingItems"
on-refresh-holding="refreshHolding()"
on-refresh-opening="refreshOpening(ratio)"
on-refresh="refreshItems()"
on-reorder="onReorder(el, start, end)"
refresh-complete="refreshComplete"
on-delete="deleteListItem(item, index)"
delete-icon="ion-minus-circled"
reorder-icon="ion-navicon"
animation="my-repeat-animation"
can-delete="true"
can-reorder="true"
can-swipe="true"
option-buttons="optionButtons1">
<!-- shows that the item directive does not need attributes and can get values from the list attributes -->
<ion-item item="item" ng-href="#" ng-click="itemClick()" class="item-thumbnail-left" ng-repeat="item in items" ng-class="{ active: item.isActive}">
<img ng-src="{{item.face}}">
<h2>{{item.from}}</h2>
<p>{{item.text}}</p>
</ion-item>
<!-- shows how a divider could be included-->
<div class="item item-divider">
Me Divider, just plain ol' HTML nested in the list directive.
</div>
<!-- shows it can override the attributes set by the list -->
<ion-item can-delete="false"
can-reorder="false"
can-swipe="false"
item-type="item-icon-left item-icon-right">
<i class="icon ion-stats-bars"></i>
Individual item directive, but can't do much. Overrides list attributes with its own left and right icons.
<i class="icon ion-arrow-graph-up-right"></i>
</ion-item>
<!-- shows that the item directive can receive many attributes and overrides the list attributes -->
<ion-item on-delete="deleteItem(item, index)"
delete-icon="ion-trash-a"
reorder-icon="ion-navicon-round"
can-delete="true"
can-reorder="true"
option-buttons="optionButtons2">
<i class="icon ion-person-stalker"></i>
Individual item directive and overrides list attrs with item attributes
</ion-item>
<!-- shows how a divider could be included-->
<div class="item item-divider">
Below is NOT using the item directive, but just nested HTML
</div>
<!-- shows how very simple lists don't need the item directive at all -->
<div class="item item-thumbnail-left">
<img src="http://pbs.twimg.com/profile_images/2913427048/ed94193baa04ace85aa8a8bf4bf6c5a9.jpeg">
<h2>Nic Cage</h2>
<p>I am not a demon. I am a lizard, a shark, a heat-seeking panther. I want to be Bob Denver on acid playing the accordion.</p>
</div>
<a class="item item-icon-left" href="{{ item.url }}" ng-repeat="item in urlItems" ng-class="{ active: item.isActive}">
<i class="icon {{ item.icon }}"></i>
{{ item.text }}
</a>
<input type="text" placeholder="text input">
<div class="item">
<ion-slide-box show-pager="false">
<ion-slide>
<div class="box blue">
<h1>BLUE {{slideBox.slideIndex}}</h1>
</div>
</ion-slide>
<ion-slide>
<div class="box yellow">
<h1>YELLOW {{slideBox.slideIndex}}</h1>
</div>
</ion-slide>
<ion-slide>
<div class="box pink"><h1>PINK {{slideBox.slideIndex}}</h1></div>
</ion-slide>
</ion-slide-box>
</div>
</ion-list>
</ion-content>
</ion-side-menu-content>
<ion-side-menu side="left">
Left menu!
</ion-side-menu>
</ion-side-menus>
<script>
angular.module('navTest', ['ionic'])
.controller('TestCtrl', function($scope, $timeout, $ionicSideMenuDelegate) {
$scope.toggleLeft = function() {
$ionicSideMenuDelegate.toggleLeft();
};
// Build Mock Data
$scope.items = [
{ from: 'Ben', face: 'https://pbs.twimg.com/profile_images/378800000571933189/278e8e1b7871a115b95fc550cd07af40.png', text: 'Whoa, whoa, whoa. There’s still plenty of meat on that bone. Now you take this home, throw it in a pot, add some broth, a potato. Baby, you\'ve got a stew going.' },
{ from: 'Adam', face: 'https://pbs.twimg.com/profile_images/2927292174/25b170ee2e3044fd936ad1319bc4b82d_bigger.jpeg', text: 'It Ain\'t Easy Being Cheesy' },
{ from: 'Tim', face: 'https://pbs.twimg.com/profile_images/378800000290028838/ee3303b02223f25cb0f9b082b55b2eeb.jpeg', text: 'Baxter! You know I don\'t speak spanish!' },
{ from: 'Brody', face: 'https://pbs.twimg.com/profile_images/378800000138067018/554c103ebf37c2ba3b923b8deea46b0d.jpeg', text: 'Sounds like some sort of marmalade' },
{ from: 'Peter', face: 'https://pbs.twimg.com/profile_images/378800000238071493/08f76337bdc91b1e1e73a9d55c57a451.jpeg', text: 'A cooked goose for everyone!' },
{ from: 'Max', face: 'https://pbs.twimg.com/profile_images/430001754747305984/qa5DFLgU.jpeg', text: 'Yes my dear man, more beans. oooohh' },
{ from: 'Andy', face: 'https://pbs.twimg.com/profile_images/423294834229522433/BSlEOBYt.jpeg', text: 'I did it all for her' },
{ from: 'Melissa', face: 'https://pbs.twimg.com/profile_images/412451928816111616/VZ3_md1N.jpeg', text: 'I think I want my money back' }
];
// List Toggles
$scope.editBtnText = 'Edit';
$scope.toggleDelete = function() {
$scope.isDeletingItems = !$scope.isDeletingItems;
$scope.isReorderingItems = false;
$scope.editBtnText = ($scope.isDeletingItems ? 'Done' : 'Edit');
};
$scope.reorderBtnText = 'Reorder';
$scope.toggleReorder = function() {
$scope.isReorderingItems = !$scope.isReorderingItems;
$scope.isDeletingItems = false;
$scope.reorderBtnText = ($scope.isReorderingItems ? 'Done' : 'Reorder');
};
$scope.itemClick = function() {
console.info('itemClick');
document.getElementById('click-notify').style.display = 'block';
setTimeout(function(){
document.getElementById('click-notify').style.display = 'none';
}, 500);
};
// Item Methods/Properties
$scope.deleteItem = function(item, index) {
console.log('onDelete from the "item" directive on-delete attribute. Lets not delete this item today ok!', item, index);
};
$scope.deleteListItem = function(item, index) {
console.log('onDelete from the "list" on-delete attribute', item, index);
$scope.items.splice(index, 1);
};
$scope.onReorder = function(el, start, end) {
console.log('On reorder', el, start, end);
};
$scope.optionButtons1 = [
{
text: 'Edit',
onTap: function(item, button) { alert(button.text + ' Button: ' + item.text) }
},
{
text: 'Share',
type: 'button-balanced',
onTap: function(item, button) { alert(button.text + ' Button: ' + item.text) }
}
];
$scope.optionButtons2 = [
{
text: 'Cancel',
onTap: function() { alert('CANCEL!') }
},
{
text: 'Submit',
onTap: function() { alert('SUBMIT!') }
}
];
$scope.urlItems = [
{ text: 'Biography', icon: 'ion-person', url: 'http://en.wikipedia.org/wiki/Nicolas_Cage' },
{ text: 'Fan Club', icon: 'ion-star', url: 'http://cagealot.com/', isActive: true }
];
});
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment