mirror of
https://github.com/ionic-team/ionic-framework.git
synced 2026-03-13 10:22:08 +08:00
Closes #1024. BREAKING CHANGE: ion-list syntax has changed in favor of simplicity & flexibility. Relevant documentation: [ionList](http://ionicframework.com/docs/api/directive/ionList), [ionItem](http://ionicframework.com/docs/api/directive/ionItem), [ionOptionButton](http://ionicframework.com/docs/api/directive/ionOptionButton), [ionReorderButton](http://ionicframework.com/docs/api/directive/ionReorderButton), [ionDeleteButton](http://ionicframework.com/docs/api/directive/ionDeleteButton), [$ionicListDelegate](http://ionicframework.com/docs/api/service/$ionicListDelegate). To migrate, change your code from this: ```html <ion-list option-buttons="[{text:'hello',type:'button-positive',onTap:tap()}]" on-delete="onDelete(el)" delete-icon="ion-minus-circled" can-delete="true" show-delete="shouldShowDelete" on-reorder="onReorder(el, startIndex, toIndex)" reorder-icon="ion-navicon" can-reorder="true" show-reorder="shouldShowReorder"> <ion-item ng-repeat="item in items"> {{item}} </ion-item> </ion-list> ``` To this: ```html <ion-list show-delete="shouldShowDelete" show-reorder="shouldShowReorder"> <ion-item ng-repeat="item in items"> {{item}} <ion-delete-button class="ion-minus-circled" ng-click="onDelete(item)"> </ion-delete-button> <ion-reorder-button class="ion-navicon" ng-click="onReorder(item, $fromIndex, $toIndex)"> </ion-reorder-button> <ion-option-button class="button-positive" ng-click="tap()"> Hello </ion-option-button> </ion-item> </ion-list> ```
247 lines
8.6 KiB
HTML
247 lines
8.6 KiB
HTML
<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="../../../../dist/css/ionic.css">
|
||
<script src="../../../../dist/js/ionic.bundle.js"></script>
|
||
<style>
|
||
#click-notify {
|
||
position: absolute;
|
||
top: 100px;
|
||
left: 40%;
|
||
z-index: 9997;
|
||
display: none;
|
||
padding: 8px;
|
||
background: red;
|
||
color: white;
|
||
}
|
||
#mousemove-notify {
|
||
position: absolute;
|
||
top: 140px;
|
||
left: 40%;
|
||
z-index: 9998;
|
||
display: none;
|
||
padding: 8px;
|
||
background: orange;
|
||
}
|
||
#touchmove-notify {
|
||
position: absolute;
|
||
top: 180px;
|
||
left: 40%;
|
||
z-index: 9999;
|
||
display: none;
|
||
padding: 8px;
|
||
background: yellow;
|
||
}
|
||
</style>
|
||
</head>
|
||
<body ng-controller="TestCtrl">
|
||
<div id="click-notify">CLICK!</div>
|
||
<div id="mousemove-notify">Mouse Move!</div>
|
||
<div id="touchmove-notify">Touch Move!</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>
|
||
</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">
|
||
<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-option-button class="button-positive">Hello!</ion-option-button>
|
||
<ion-delete-button ng-click="items.splice($index, 1)" class="ion-minus-circled"></ion-delete-button>
|
||
<ion-reorder-button class="ion-navicon" on-reorder="onReorder(item, $fromIndex, $toIndex)"></ion-reorder-button>
|
||
</ion-item>
|
||
|
||
<ion-item>
|
||
<p>
|
||
<ion-toggle ng-model="showOption">Show Option?</ion-toggle>
|
||
</p>
|
||
<ion-option-button ng-if="showOption">Hello!</ion-option-button>
|
||
</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-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(item) {
|
||
var el = document.getElementById('click-notify');
|
||
el.style.display = 'block';
|
||
el.innerText = 'Click! ' + item.from;
|
||
|
||
setTimeout(function(){
|
||
document.getElementById('click-notify').style.display = 'none';
|
||
}, 300);
|
||
};
|
||
|
||
// 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(item, fromIndex, toIndex) {
|
||
console.log('On reorder', item, fromIndex, toIndex);
|
||
$scope.items.splice(fromIndex, 1);
|
||
$scope.items.splice(toIndex, 0, item);
|
||
console.log($scope.items);
|
||
};
|
||
|
||
$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 }
|
||
];
|
||
|
||
});
|
||
|
||
var mouseTimerId;
|
||
var mouseMoveCount = 0;
|
||
function onMouseMove(e) {
|
||
clearTimeout(mouseTimerId);
|
||
mouseTimerId = setTimeout(function(){
|
||
var el = document.getElementById('mousemove-notify');
|
||
el.style.display = 'block';
|
||
mouseMoveCount++;
|
||
el.innerText = 'Mouse Move! ' + mouseMoveCount;
|
||
clearTimeout(mouseTimerId);
|
||
mouseTimerId = setTimeout(function(){
|
||
el.style.display = 'none';
|
||
}, 1000);
|
||
}, 0);
|
||
}
|
||
|
||
var touchTimerId;
|
||
var touchMoveCount = 0;
|
||
function onTouchMove(e) {
|
||
clearTimeout(touchTimerId);
|
||
touchTimerId = setTimeout(function(){
|
||
var el = document.getElementById('touchmove-notify');
|
||
el.style.display = 'block';
|
||
touchMoveCount++;
|
||
el.innerText = 'Touch Move! ' + touchMoveCount;
|
||
clearTimeout(touchTimerId);
|
||
touchTimerId = setTimeout(function(){
|
||
el.style.display = 'none';
|
||
}, 1000);
|
||
}, 0);
|
||
}
|
||
|
||
document.addEventListener('touchmove', onTouchMove, false);
|
||
document.addEventListener('mousemove', onMouseMove, false);
|
||
</script>
|
||
</body>
|
||
</html>
|
||
|