123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396 |
- angular.module('push')
- .directive('backImg', function () {
- return function (scope, element, attrs) {
- attrs.$observe('backImg', function (value) {
- element.css({
- 'background-image': 'url(' + value + ')',
- 'background-size': '100% 100%',
- 'background-position': 'center'
- });
- });
- };
- })
- .directive('myfocus', function ($timeout, $parse) {
- return {
- link: function (scope, element, attrs) {
- var model = $parse(attrs.myfocus);
- scope.$watch(model, function (value) {
- if (value === true) {
- $timeout(function () {
- element[0].focus();
- });
- } else if (value === false) {
- $timeout(function () {
- element[0].blur();
- });
- }
- });
- }
- };
- })
- .directive('selectUniversity', function () {
- return {
- restrict: 'EA',
- replace: true,
- transclude: true,
- scope: false,
- template: '<input type="text" placeholder="请填写所属院校" readonly="readonly" ng-model="universityname" style="margin-right: 30px" ng-click="showUniversity()">',
- controller: function ($scope, $ionicModal, $http, CommentService) {
- $scope.universityname = "";
- //接收高校选择数据
- var reciveuniversity = $scope.$on("recuniversity", function (event, data) {
- $scope.universityname = data;
- });
- //初始化高校数据
- this.$onInit = function () {
- CommentService.getUniversityList().then(function (response) {
- $scope.universitylist = response.universityList;
- }, function () {
- });
- $ionicModal.fromTemplateUrl('./modules/common/views/selectUniversity.html', {
- scope: $scope,
- animation: 'slide-in-up'
- }).then(function (modal) {
- $scope.selUni = modal;
- })
- };
- //打开高校列表弹窗
- $scope.showUniversity = function () {
- $scope.selUni.show();
- };
- //关闭高校列表弹窗
- $scope.backModel = function () {
- $scope.selUni.hide();
- };
- //选择高校
- $scope.saveUniversity = function (university) {
- $scope.universityname = university.universityname;
- var tempobj = {
- id: university.universityid,
- name: university.universityname
- };
- $scope.$emit('university', tempobj);
- $scope.selUni.hide();
- };
- $scope.$on('$destroy', function () {
- $scope.selUni.hide();
- reciveuniversity();
- });
- }
- };
- })
- .directive('hmsPctSelect', function () {
- var TAG = 'hmsPCTSelectDirective';
- return {
- restrict: 'EA',
- scope: {
- default: '=defaultdata'
- },
- replace: true,
- transclude: true,
- template: '<input type="text" id="activitySchedule_location" placeholder="请选择省/市/区/街道" readonly="readonly" ng-model="registplace" ng-click="toSetDefaultPosition();">',
- controller: function ($scope, ConfigService, $ionicModal, $http, $ionicSlideBoxDelegate, $timeout, $rootScope, $ionicScrollDelegate) {
- var selectedAddress = {};
- $scope.registplace = "";
- var addressData;
- var areaid = "";
- //接收城市选择数据
- var reciveregplace = $scope.$on("recregistplace", function (event, data) {
- $scope.registplace = data;
- });
- this.$onInit = function () {
- selectedAddress = {};
- $scope.selectedAddress = {};
- // $on、$emit和$broadcast使得event、data在controller之间的传递变的简单。
- // $emit:子传父 传递event与data
- // $broadcast:父传子 child controller传递event与data
- // $on:监听或接收数据。。用于接收event与data
- var url = ConfigService.server + "getRegionsList.action?level=0";
- $http.get(url).success(function (res) {
- addressData = res;
- $scope.provincesData = addressData['86'];
- }).error(function (err) {
- console.log('area_datas err = ' + angular.toJson(err));
- });
- $ionicModal.fromTemplateUrl('./modules/common/views/selectCity.html', {
- scope: $scope,
- animation: 'slide-in-up'
- }).then(function (modal) {
- $scope.PCTModal = modal;
- })
- };
- $scope.lockSlide = function () {
- $ionicSlideBoxDelegate.$getByHandle('PCTSelectDelegate').enableSlide(false);
- };
- $scope.$watch('default', function (newValue) {
- if (newValue) {
- $scope.selectedAddress = newValue;
- }
- });
- $scope.toSetDefaultPosition = function () {
- $scope.showBackBtn = false;
- $ionicSlideBoxDelegate.$getByHandle('PCTSelectDelegate').slide(0);
- $ionicScrollDelegate.$getByHandle('PCTSelectProvince').scrollTop();
- $scope.PCTModal.show();
- };
- //选择省
- $scope.chooseProvince = function (selectedProvince) {
- var selectedProvinceIndex;
- angular.forEach($scope.provincesData, function (item, index) {
- if (item === selectedProvince) {
- selectedProvinceIndex = index;
- }
- });
- selectedAddress = {};
- $scope.showBackBtn = true;
- areaid = selectedProvinceIndex;
- $scope.citiesData = addressData['' + selectedProvinceIndex + ''];
- $ionicSlideBoxDelegate.$getByHandle('PCTSelectDelegate').next();
- $ionicSlideBoxDelegate.$getByHandle('PCTSelectDelegate').update();
- $ionicScrollDelegate.$getByHandle('PCTSelectCity').scrollTop();
- selectedAddress.province = selectedProvince;
- $scope.registplace = selectedProvince;
- var tempobj = {
- areaid: areaid,
- registplace: $scope.registplace
- };
- $scope.$emit('registplace', tempobj);
- };
- //选择市
- $scope.chooseCity = function (selectedCity) {
- var selectedCityIndex;
- angular.forEach($scope.citiesData, function (item, index) {
- if (item === selectedCity) {
- selectedCityIndex = index;
- }
- });
- areaid = selectedCityIndex;
- $scope.townData = addressData['' + selectedCityIndex + ''];
- selectedAddress.city = selectedCity;
- $scope.registplace = $scope.registplace + selectedAddress.city;
- var tempobj = {
- areaid: areaid,
- registplace: $scope.registplace
- };
- $scope.$emit('registplace', tempobj);
- if (!$scope.townData) {
- selectedAddress.town = '';
- $scope.selectedAddress = selectedAddress;
- $rootScope.$broadcast('PCTSELECT_SUCCESS', {result: $scope.selectedAddress});
- $timeout(function () {
- $scope.PCTModal.hide();
- }, 200);
- } else {
- $ionicSlideBoxDelegate.$getByHandle('PCTSelectDelegate').next();
- $ionicSlideBoxDelegate.$getByHandle('PCTSelectDelegate').update();
- $ionicScrollDelegate.$getByHandle('PCTSelectTown').scrollTop();
- }
- };
- //选择县
- $scope.chooseTown = function (selectedTown) {
- var selectedTownIndex;
- angular.forEach($scope.townData, function (item, index) {
- if (item === selectedTown) {
- selectedTownIndex = index;
- }
- });
- areaid = selectedTownIndex;
- $scope.streetData = addressData['' + selectedTownIndex + ''];
- selectedAddress.town = selectedTown;
- $scope.registplace = $scope.registplace + selectedAddress.town;
- var tempobj = {
- areaid: areaid,
- registplace: $scope.registplace
- };
- $scope.$emit('registplace', tempobj);
- if (!$scope.streetData) {
- selectedAddress.street = '';
- $scope.selectedAddress = selectedAddress;
- $rootScope.$broadcast('PCTSELECT_SUCCESS', {result: $scope.selectedAddress});
- $timeout(function () {
- $scope.PCTModal.hide();
- }, 200);
- } else {
- $ionicSlideBoxDelegate.$getByHandle('PCTSelectDelegate').next();
- $ionicSlideBoxDelegate.$getByHandle('PCTSelectDelegate').update();
- $ionicScrollDelegate.$getByHandle('PCTSelectStreet').scrollTop();
- }
- };
- //选择街道
- $scope.chooseStreet = function (selectedStreet) {
- var selectedStreetIndex;
- angular.forEach($scope.streetData, function (item, index) {
- if (item === selectedStreet) {
- selectedStreetIndex = index;
- }
- });
- areaid = selectedStreetIndex;
- selectedAddress.street = selectedStreet;
- $scope.registplace = $scope.registplace + selectedAddress.street;
- var tempobj = {
- areaid: areaid,
- registplace: $scope.registplace
- };
- $scope.$emit('registplace', tempobj);
- $scope.selectedAddress = selectedAddress;
- $rootScope.$broadcast('PCTSELECT_SUCCESS', {result: $scope.selectedAddress});
- $timeout(function () {
- $scope.PCTModal.hide();
- }, 200);
- };
- //slide返回上一级
- $scope.goBackSlide = function () {
- var currentIndex = $ionicSlideBoxDelegate.$getByHandle('PCTSelectDelegate').currentIndex();
- if (currentIndex > 0) {
- $ionicSlideBoxDelegate.$getByHandle('PCTSelectDelegate').previous();
- }
- if (currentIndex === 1) {
- $scope.showBackBtn = false;
- }
- };
- $scope.cancelSelect = function () {
- $scope.PCTModal.hide();
- };
- $scope.$on('$destroy', function () {
- $scope.PCTModal.remove();
- reciveregplace();
- });
- }
- };
- })
- .directive('slideScroll', function () {
- return {
- restrict: 'AE',
- link: function (scope, element, attr) {
- var itsWatch = scope.$watch("its", function (newvalue, oldvalue) {
- itsWatch();
- var i = 0; //element是ul
- var length = element[0].children.length;
- console.log(length);
- setInterval(function () {
- // if (i == length / 2) {
- if (i > length-1 ) {
- i = 0;//初始位置
- element[0].style.top = "0px";
- }
- // var topscorll = -(i * 60);
- var topscorll = -(i * 40);
- feeltoTop(topscorll);
- i++;
- }, 2500);
- //向上滚动
- function feeltoTop(topscorll) {//console.log(topscorll):topscorll是top值
- var buchang = -10;
- var feelTimer = setInterval(function () {
- element[0].style.top = parseInt(element[0].style.top) + buchang + "px";
- if (topscorll == -100) {
- i = 0;
- }
- if (parseInt(element[0].style.top) <= topscorll) {
- element[0].style.top = topscorll + "px";
- window.clearInterval(feelTimer);
- }
- }, 100);
- }
- })
- }
- }
- })
- .directive('keyboardshow', function($rootScope, $ionicPlatform, $timeout) {
- return {
- restrict: 'A',
- link: function(scope, element) {
- window.addEventListener('native.keyboardshow',function (e){
- // var hHeight=e.keyboardHeight;
- // console.log(hHeight);
- // if(hHeight==271){
- // e.keyboardHeight=271;
- // }else if(hHeight<=271){
- // e.keyboardHeight=271;
- // }
- // $timeout(function(){
- // if (device.platform != "Android") {
- // angular.element(element).css({
- // 'bottom':e.keyboardHeight + 'px'
- // });
- // }else{
- // angular.element(element).css({
- // 'bottom':e.keyboardHeight +30+ 'px'
- // });
- // }
- // },50);
- $timeout(function(){
- if (device.platform != "Android") {
- angular.element(element).css({
- 'bottom':0 + 'px'
- });
- }else{
- angular.element(element).css({
- 'bottom':30+ 'px'
- });
- }
- },50);
- });
- window.addEventListener('native.keyboardhide',function (e){
- angular.element(element).css({
- 'bottom':0
- });
- cordova.plugins.Keyboard.isVisible = true;
- $timeout(function() {
- cordova.plugins.Keyboard.isVisible = false;
- }, 50);
- });
- }
- };
- })
- .directive('foucusshow', function ($ionicScrollDelegate, $window, $timeout, $ionicPosition) {
- return {
- restrict: 'A',
- scope: false,
- link: function (scope, element) {
- if (scope.app&&device.platform == "Android") {
- window.addEventListener('native.keyboardshow',function (e){
- var wHeigth=window.innerHeight;
- var eHeight=wHeigth-e.keyboardHeight;
- var top = $ionicScrollDelegate.getScrollPosition().top;
- var eleTop = ($ionicPosition.offset(element).top);
- var realTop = eleTop + top;
- $timeout(function () {
- if (eleTop<=eHeight) {
- $ionicScrollDelegate.$getByHandle('mainScroll').scrollTo(0,realTop);
- $ionicScrollDelegate.$getByHandle('mainScroll').resize();
- } else {
- try {
- var aim = $(".commonScrollForm .scroll");
- aim.css('transform', 'translate3d(0px,' + '-' + realTop + 'px, 0px) scale(1)');
- aim.css('height', '230%');
- $timeout(function () {
- element[0].focus();
- }, 10)
- } catch (e) {
- }
- }
- }, 50)
- });
- }
- }
- }
- });
|