Conflicts:
	dist/css/ionic-scoped.css
This commit is contained in:
Max Lynch
2013-10-21 11:36:49 -05:00
42 changed files with 3807 additions and 6346 deletions

View File

@ -8,28 +8,21 @@ angular.module('ionic.ui.toggle', [])
replace: true,
require: '?ngModel',
scope: true,
template: '<div class="toggle">' +
' <input type="checkbox">'+
' <div class="track">' +
' <div class="handle"></div>' +
' </div>' +
'</div>',
template: '<div class="toggle"><input type="checkbox"><div class="handle"></div></div>',
link: function($scope, $element, $attr, ngModel) {
var checkbox, track, handle;
var checkbox, handle;
if(!ngModel) { return; }
checkbox = $element.children().eq(0);
track = $element.children().eq(1);
handle = track.children().eq(0);
if(!checkbox.length || !track.length || !handle.length) { return; }
if(!checkbox.length || !handle.length) { return; }
$scope.toggle = new ionic.views.Toggle({
el: $element[0],
checkbox: checkbox[0],
track: track[0],
handle: handle[0]
});

View File

@ -18,12 +18,11 @@
var opts = {
el: el,
checkbox: el.querySelector("input[type='checkbox']"),
track: el.querySelector(".track"),
handle: el.querySelector(".handle")
};
// validate its a well formed toggle with the required pieces
if(!opts.checkbox || !opts.track || !opts.handle) return;
if(!opts.checkbox || !opts.handle) return;
// initialize an instance of a Toggle
el.component = new ionic.views.Toggle(opts);

View File

@ -4,20 +4,8 @@
ionic.views.Toggle = function(opts) {
this.el = opts.el;
this.checkbox = opts.checkbox;
this.track = opts.track;
this.handle = opts.handle;
this.openPercent = -1;
/*
// remember that this element, and all its children are apart of a component
// and assign the component instance to each element so the lookups
// only has to go through this process just once
this.el.isComponent = true;
this.track.component = this;
this.track.isComponent = true;
this.handle.component = this;
this.handle.isComponent = true;
*/
};
ionic.views.Toggle.prototype = {
@ -27,8 +15,8 @@
},
drag: function(e) {
var slidePageLeft = this.track.offsetLeft + (this.handle.offsetWidth / 2);
var slidePageRight = this.track.offsetLeft + this.track.offsetWidth - (this.handle.offsetWidth / 2);
var slidePageLeft = this.checkbox.offsetLeft + (this.handle.offsetWidth / 2);
var slidePageRight = this.checkbox.offsetLeft + this.checkbox.offsetWidth - (this.handle.offsetWidth / 2);
if(e.pageX >= slidePageRight - 4) {
this.val(true);
@ -49,7 +37,7 @@
} else if(openPercent === 100) {
this.val(true);
} else {
var openPixel = Math.round( (openPercent / 100) * this.track.offsetWidth - (this.handle.offsetWidth) );
var openPixel = Math.round( (openPercent / 100) * this.checkbox.offsetWidth - (this.handle.offsetWidth) );
openPixel = (openPixel < 1 ? 0 : openPixel);
this.handle.style.webkitTransform = 'translate3d(' + openPixel + 'px,0,0)';
}