Created
August 23, 2016 08:30
-
-
Save area73/6c6addf38019762b3afe8adcc8775609 to your computer and use it in GitHub Desktop.
typewriter
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(function () { | |
'use strict'; | |
angular | |
.module('poke.botes') | |
.controller('PokeBoteCrearController', PokeBoteCrearController); | |
PokeBoteCrearController.$inject = ['motion', '$http', '$state', '$scope', '$interval', '$parse' ]; | |
/* @ngInject */ | |
function PokeBoteCrearController(motion, $http, $state, $scope, $interval, $parse) { | |
/* jshint validthis: true */ | |
var vm = angular.extend(this, { | |
// TODO: add Mehtods & properties to this controller | |
botes:[], | |
navigate: navigate, | |
activate: activate, | |
typeLetter:typeLetter, | |
phrases:[], | |
resetFields:resetFields, | |
phIndex:0, | |
idx:0, | |
timer:null, | |
content:'', | |
title: 'PokeBoteCrearController' | |
}); | |
activate(); | |
vm.phrases = [ | |
{txt:'Viaje de Ecuador a Punta Cana' , field:'text1'}, | |
{txt:'750 €', field:'text2'}, | |
{txt:'27', field:'text3'}, | |
{txt:'mayo', field:'text4'}, | |
{txt:'2016', field:'text5'} | |
]; | |
vm.content = vm.phrases[vm.phIndex].txt; | |
resetFields(); | |
// typeLetter(); | |
//////////////// | |
function resetFields(){ | |
angular.forEach(vm.phrases, function(item, key){ | |
var model = $parse(vm.phrases[key].field); | |
// Assigns a value to it | |
model.assign($scope, ''); | |
}); | |
} | |
function typeLetter() { | |
if(vm.idx < vm.content.length){ | |
var model = $parse(vm.phrases[vm.phIndex].field); | |
model.assign($scope, vm.content.substring(0, vm.idx)); | |
vm.idx++; | |
} else { | |
// si hay mas frases | |
if (vm.phIndex < vm.phrases.length-1 ) { | |
vm.idx = 0; | |
++vm.phIndex; | |
vm.content = vm.phrases[vm.phIndex].txt; | |
} else { | |
$interval.cancel(vm.timer); | |
// typeLetter(); | |
} | |
} | |
$scope.safeApply(); | |
} | |
vm.timer = $interval(function(){ | |
typeLetter(); | |
}, 100); | |
$scope.safeApply = function(fn) { | |
var phase = this.$root.$$phase; | |
if (phase == '$apply' || phase == '$digest') { | |
if (fn && (typeof(fn) === 'function')) { | |
fn(); | |
} | |
} else { | |
this.$apply(fn); | |
} | |
} | |
function navigate(boteId) { | |
// $state.go('app.pokeReclamo', { boteId: boteId }); | |
} | |
function activate() { | |
motion.showItems(); | |
motion.ink(); | |
} | |
} | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment