common.js
4.45 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
define(function( require, exports, module ) {
/*
引入包
*/
var _Base = require( 'base' );
require( 'underscore' );
$(function(){
//select 模型
$( '.m-select select' ).on('change',function(){
$( this ).parent().find( '.select-text' ).text( $( this ).find( 'option:selected' ).text() );
});
/* 搜索 */
//搜索切换
$( '.h-search' ).click(function(){
$( '.s-page' ).css({'display':'block'});
});
//取消搜索、返回
$( '.s-page .icon-back' ).click(function(){
$( '.s-page' ).css({'display':'none'});
});
//搜索类型选择
$( '.search-type-box' ).click(function(){
$( '.dropdown-items' ).css({'display':'block'});
});
$( '.dropdown-items li' ).click(function(){
$( '.search-type-box' ).html( $( this ).text() );
$( '.dropdown-items' ).css({'display':'none'});
});
//悬浮工具条
var timer = null;
$( '.m-bar' ).on( 'click' , function(){
clearTimeout( timer );
if( !$( this ).hasClass( 'open' ) ){
$( '.m-bar-bg' ).css( 'display' , 'block' );
$( this ).addClass( 'open' ).removeClass( 'close' );
}else{
$( this ).removeClass( 'open' ).addClass( 'close' );
timer = setTimeout(function(){
$( '.m-bar-bg' ).css( 'display' , 'none' );
} , 300 );
}
});
//页面切换效果
$( '.transition-btn' ).on( 'click' , function(){
$( $( this ).attr( 'elem' ) ).addClass( 'show' );
// $( '.transition-content' ).css( 'display' , 'block' );
});
$( '.transition-close' ).on( 'click' , function(){
$( $( this ).attr( 'elem' ) ).removeClass( 'show' );
// setTimeout(function(){
// // $( '.transition-content' ).css( 'display' , 'none' );
// },300);
});
/* app download */
var androidIs = false;
// ios
var ios = {
Url: "",
downloadUrl: ""
};
//android
var android = {};
android = {
Url: "intent://m.ml.com#Intent;scheme=milanoo;package=com.milanoo.store;end;",
downloadUrl: "http://m.milanoo.com/downloadapp/index.html"
};
var appInfoFn = function(){
return{
Url: androidIs ? android.Url : ios.Url,
downloadUrl: androidIs ? android.downloadUrl : ios.downloadUrl
};
};
var app = {
init:function(){
if( app.getcookie( 'applink' ) == '' && $( '.to-app-box' ).length > 0 ){
$( '.to-app-box' ).animate({ bottom: '0' }, 500 );
app.appInfo = appInfoFn();
document.getElementById("applink").onclick = app.applink( app.appInfo.downloadUrl );
app.close();
app.applink();
}
},
close: function(){
$( '.app-close' ).click( function(){
$( '.to-app-box' ).animate({ bottom: '-100%' }, 500 );
app.setcookie( 3600 );
});
},
applink:function( fail ){
return function(){
var clickedAt = +new Date;
// During tests on 3g/3gs this timeout fires immediately if less than 500ms.
window.location = app.appInfo.Url ;
if(window.location !== app.appInfo.Url){
setTimeout(function(){
// To avoid failing on return to MobileSafari, ensure freshness!
if (+new Date - clickedAt < 2000){
window.location = fail;
app.close();
}
}, 500);
}
};
},
setcookie:function( seconds ){
var date = new Date();
date.setTime( date.getTime()+( seconds*1000 ) );
document.cookie="applink=yes;path=/;expires="+date.toGMTString();
},
getcookie:function( name ){
var search = name + "="
var returnvalue = "";
if (document.cookie.length > 0) {
offset = document.cookie.indexOf(search)
if (offset != -1) {
// if cookie exists
offset += search.length
// set index of beginning of value
end = document.cookie.indexOf(";", offset);
// set index of end of cookie value
if (end == -1)
end = document.cookie.length;
returnvalue=unescape(document.cookie.substring(offset, end))
}
}
return returnvalue;
}
};
var u = navigator.userAgent ;
if ( /*u.match(/(iPhone|iPod|iPad);?/i) || */u.indexOf('Android') > -1 ) {
// if( u.indexOf('Android') > -1){
androidIs = true;
//}
app.init();
}
});
});