/** * Created with IntelliJ IDEA. * User: zet * Date: 13-1-10 * Time: 下午5:46 * To change this template use File | Settings | File Templates. */ /** * 字符串和日期工具 */ (function (window, document) { String.prototype.Trim = function () { return this.replace(/(^\s*)|(\s*$)/g, ""); }; String.prototype.getBytesCount = function (str) { if (str == null) { return 0; } else { return str.replace(/[^\x00-\xff]/g, "**").length; } }; Date.prototype.nextDate = function () { return new Date(this.getTime() + 86400000); }; Date.prototype.getMyDay = function () { var temp = this.getDay(); switch (temp) { case 0: return "週日"; case 1: return "週一"; case 2: return "週二"; case 3: return "週三"; case 4: return "週四"; case 5: return "週五"; case 6: return "週六"; default: return ''; } }; Date.prototype.getMyMonth = function () { return (this.getMonth() + 1) + '月'; }; Date.prototype.toMyString = function () { var month = this.getMonth() + 1; return this.getFullYear() + '-' + (month >= 10 ? month : ('0' + month)) + '-' + this.getDate(); }; })(window, document); /** * 獲取地理位置 */ (function(window, document) { window.Drore = window.Drore || {}; var nav = navigator; Drore.Location = Drore.Location || null; Drore.getLocation = function(cb) { var pos = null; if (nav.geolocation) { nav.geolocation.getCurrentPosition(function(position) { pos = { lat: position.coords.latitude, lon: position.coords.longitude } cb(pos); }, function() { console.log('千島湖旅遊客戶端提示您:獲取您的位置信息失敗!'); cb(pos); }, { timeout: 3000 }); } else { alert('您的瀏覽器不支持定位!'); cb(pos); } }; })(window, document); /** * ajax and html help function */ (function(window, document) { window.Drore = window.Drore || {}; var head = document.getElementsByTagName('head')[0], i, imgCache = document.createElement('img'); Drore.importJs = function(url, cb, charset) { var s = document.createElement("script"); s.src = url; if (charset) { s.charset = charset } s.onload = s.onreadystatechange = function() { if (!this.readyState || this.readyState == 'loaded' || this.readyState == 'complete') { s.onload = s.onreadystatechange = null; this.parentNode.removeChild(this); if (cb) { cb(true) } }; }; s.onerror = function() { this.onload = this.onerror = null; this.parentNode.removeChild(this); if (cb) { cb(false) } }; head.appendChild(s) }; Drore.importCSS = function(url) { var link = document.createElement('link'); link.setAttribute('rel', 'stylesheet'); link.setAttribute('type', 'text/css'); link.setAttribute('href', url); head.appendChild(link) }; Drore.importMap = function(cb) { this.importCSS(window.Config.Map.cssUrl) this.importJs(window.Config.Map.jsUrl, cb); }; Drore._paras = (function() { var url = window.location.href, start = url.indexOf("?") + 1, paras = {}; if (start !== 0) { var queryString = url.substring(start); var paraNames = queryString.split("&"); var arr = [], i = 0; for (; i < paraNames.length; i++) { arr = paraNames[i].split("="); if (i === paraNames.length - 1) { var sIndex = arr[1].indexOf("#"); if (sIndex !== -1) { arr[1] = arr[1].substring(0, sIndex); } } paras[arr[0]] = arr[1] } } return paras })(); Drore.getParameter = function(pName) { return Drore._paras[pName]; }; Drore.getReqParams = function(paramObj) { var arr = new Array(); for (i in paramObj) { arr.push(i + '=' + paramObj[i]); } return arr.join('&'); }; Drore.loadImg = function(targetDom, url) { if (url.indexOf("undefined")!=-1) { targetDom.src = Config.ImgLazyLoading.errorUrl; } else { var img = imgCache.cloneNode(true); targetDom.src = Config.ImgLazyLoading.loadingUrl; img.src = url + "_192X0_70.jpg"; img.onload = function() { targetDom.src = url + "_192X0_70.jpg"; img.onload = null; img.onerror = null; img = null; } img.onerror = function() { targetDom.src = url; img.onload = null; img.onerror = null; img = null; } } }; Drore.loadBigImg = function(targetDom, url) { var img = imgCache.cloneNode(true); targetDom.src = Config.ImgLazyLoading.loadingUrl; img.src = url; img.onload = function() { targetDom.src = url; img.onload = null; img.onerror = null; img = null; } img.onerror = function() { targetDom.src = Config.ImgLazyLoading.errorUrl; img.onload = null; img.onerror = null; img = null; } }; })(window, document); /** * 本地緩存 */ (function(window) { window.Drore = window.Drore || {}; window.Drore.storage = { set: function(key, value) { window.localStorage.setItem(key, value); }, get: function(key) { return window.localStorage.getItem(key); } }; })(window); /** * dom 操做 */ (function(document, window) { window.Drore = window.Drore || {}; Drore.$ = function (id) { return "string" == typeof id ? document.getElementByI(id) : id; }; })(document, window); /** * Config * * !!!! * 若是前端頁面和服務器部署在不一樣的域名下,那麼Safari瀏覽器登陸和註冊就會出錯!! */ (function() { window.Config = { Map: { cssUrl: 'http://api.map.baidu.com/res/14/bmap.css', jsUrl: 'http://api.map.baidu.com/getscript?v=1.4&key=&services=&t=20130219081854' }, APIUrl: { host: 'http://api.weyoo.cn', // host: 'http://192.168.16.239', // port: '8080', port: "80", imageHost: 'http://img.weyoo.cn', //首頁廣告 indexAd: function(paramObj) { return this.host + ':' + this.port + '/advert/detail.htm?' + Drore.getReqParams(paramObj); }, //酒店列表 hotelUrl: function(paramObj) { return this.host + ':' + this.port + '/hotel/list.htm?' + Drore.getReqParams(paramObj); }, //沒房型的酒店信息 hotelInfo: function(paramObj) { return this.host + ':' + this.port + '/hotel/detail.htm?' + Drore.getReqParams(paramObj); }, //酒店預訂 hotelBook: function(paramObj) { return this.host + ':' + this.port + '/hotel/book.htm?' + Drore.getReqParams(paramObj); }, //酒店預訂支付 hotelBookPay: function(paramObj) { return this.host + ':' + this.port + '/hotel/book_pay.htm?' + Drore.getReqParams(paramObj); }, //訂單支付 pay: function(paramObj) { return this.host + ':' + this.port + '/pay/pay_order.htm?' + Drore.getReqParams(paramObj); }, //有房型的酒店信息 hotelDetail: function(paramObj) { return this.host + ':' + this.port + '/hotel/room.htm?' + Drore.getReqParams(paramObj); }, //酒店評價提交 hotelCommentSubmit: function(paramObj) { return this.host + ':' + this.port + '/comment/save_hotel.htm?' + Drore.getReqParams(paramObj); }, //酒店房型評價提交 RoomCommentSubmit: function(paramObj) { return this.host + ':' + this.port + '/comment/save_hotel_room.htm?' + Drore.getReqParams(paramObj); }, //景區列表 viewUrl: function(paramObj) { return this.host + ':' + this.port + '/scenic/list.htm?' + Drore.getReqParams(paramObj); }, //景點詳情 pointDetail: function(paramObj) { return this.host + ':' + this.port + '/scenic/pointdetail.htm?' + Drore.getReqParams(paramObj); }, // 景點列表 pointList: function(paramObj) { return this.host + ':' + this.port + '/scenic/pointlist.htm?' + Drore.getReqParams(paramObj); }, //景區詳情 viewDetail: function(paramObj) { return this.host + ':' + this.port + '/scenic/detail.htm?' + Drore.getReqParams(paramObj); }, //景點評價提交 pointCommentSubmit: function(paramObj) { return this.host + ':' + this.port + '/comment/save_scenic_point.htm?' + Drore.getReqParams(paramObj); }, //景點評論列表 pointCommentList: function(paramObj) { return this.host + ':' + this.port + '/comment/scenic_point_list.htm?' + Drore.getReqParams(paramObj); }, // 景區評論提交 scenicCommentSubmit: function(paramObj) { return this.host + ':' + this.port + '/comment/save_scenic.htm?' + Drore.getReqParams(paramObj); }, //美食列表 cateringUrl: function(paramObj) { return this.host + ':' + this.port + '/provider/list.htm?' + Drore.getReqParams(paramObj); }, //娛樂列表 recreatUrl: function(paramObj) { return this.host + ':' + this.port + '/provider/list.htm?' + Drore.getReqParams(paramObj); }, //商家詳情 providerDetail: function(paramObj) { return this.host + ':' + this.port + '/provider/detail.htm?' + Drore.getReqParams(paramObj); }, //特產店列表 specialtyUrl: function(paramObj) { return this.host + ':' + this.port + '/provider/list.htm?' + Drore.getReqParams(paramObj); }, //商品類別列表 goodsTypeList: function(paramObj) { return this.host + ':' + this.port + '/goods_type/list.htm?' + Drore.getReqParams(paramObj); }, //商品類別詳情 goodsTypeDetail: function(paramObj) { return this.host + ':' + this.port + '/goods_type/detail.htm?' + Drore.getReqParams(paramObj); }, //商品列表 goodsUrl: function(paramObj) { return this.host + ':' + this.port + '/goods/list.htm?' + Drore.getReqParams(paramObj); }, //商品預訂 goodsBook: function(paramObj) { return this.host + ':' + this.port + '/goods/book.htm?' + Drore.getReqParams(paramObj); }, // 門票詳情 ticketsDetail: function(paramObj) { return this.host + ':' + this.port + '/scenic/ticketdetail.htm?' + Drore.getReqParams(paramObj); }, // 門票預訂 ticketsBook: function(paramObj) { return this.host + ':' + this.port + '/scenic/book.htm?' + Drore.getReqParams(paramObj); }, // 訂單詳情 bookDetail: function(paramObj) { return this.host + ':' + this.port + '/order/view.htm?' + Drore.getReqParams(paramObj); }, // 取消訂單 cancelOrder: function(paramObj){ return this.host + ':' + this.port + '/order/cancel.htm?' + Drore.getReqParams(paramObj); }, // 刪除訂單 delOrder: function(paramObj){ return this.host + ':' + this.port + '/order/delete.htm?' + Drore.getReqParams(paramObj); }, //商品詳情 goodsDetail: function(paramObj) { return this.host + ':' + this.port + '/goods/detail.htm?' + Drore.getReqParams(paramObj); }, //商品評價提交 goodsCommentSubmit: function(paramObj) { return this.host + ':' + this.port + '/comment/save_goods.htm?' + Drore.getReqParams(paramObj); }, //商家評價提交 shopCommentSubmit: function(paramObj) { return this.host + ':' + this.port + '/comment/save_provider.htm?' + Drore.getReqParams(paramObj); }, //商家類別 shopType: function(paramObj) { return this.host + ':' + this.port + '/provider/type.htm?' + Drore.getReqParams(paramObj); }, //註冊 registerUrl: function(paramObj) { return this.host + ':' + this.port + '/mem/reg.htm?' + Drore.getReqParams(paramObj); }, // 註冊請求驗證碼 registerCodeRequest: function(paramObj) { return this.host + ':' + this.port + '/mem/reg_get_code.htm?' + Drore.getReqParams(paramObj); }, //驗證驗證碼 codeValidate: function(paramObj) { return this.host + ':' + this.port + '/mem/code_validate.htm?' + Drore.getReqParams(paramObj); }, //登錄 loginUrl: function(paramObj) { return this.host + ':' + this.port + '/mem/login.htm?' + Drore.getReqParams(paramObj); }, // 重置密碼請求驗證碼 resetCodeRequest: function(paramObj) { return this.host + ':' + this.port + '/mem/password_reset_code.htm?' + Drore.getReqParams(paramObj); }, // 重置密碼校驗驗證碼 resetCodeValidate: function(paramObj) { return this.host + ':' + this.port + '/mem/password_code_validate.htm?' + Drore.getReqParams(paramObj); }, // 重置密碼 resetPassword: function(paramObj) { return this.host + ':' + this.port + '/mem/password_reset.htm?' + Drore.getReqParams(paramObj); }, //交通 trafficUrl: function(paramObj) { return this.host + ':' + this.port + '/serv/traffic_type.htm?' + Drore.getReqParams(paramObj); }, //交通列表 trafficList: function(paramObj) { return this.host + ':' + this.port + '/serv/traffic_list.htm?' + Drore.getReqParams(paramObj); }, //交通詳情 trafficDetail: function(paramObj) { return this.host + ':' + this.port + '/serv/traffic_detail.htm?' + Drore.getReqParams(paramObj); }, //便民信息類別 bianminIndex: function(paramObj) { return this.host + ':' + this.port + '/serv/conv_type.htm?' + Drore.getReqParams(paramObj); }, //便民信息列表 bianminList: function(paramObj) { return this.host + ':' + this.port + '/serv/conv_list.htm?' + Drore.getReqParams(paramObj); }, // 便民信息詳情 bianminDetail: function(paramObj) { return this.host + ':' + this.port + '/serv/conv_detail.htm?' + Drore.getReqParams(paramObj); }, //用戶中心-我的資料查詢 getUserInfo: function(paramObj) { return this.host + ':' + this.port + '/mem/self_info.htm?' + Drore.getReqParams(paramObj); }, //用戶中心-修改密碼 pwdUpdate: function(paramObj) { return this.host + ':' + this.port + '/mem/password_update.htm?' + Drore.getReqParams(paramObj); }, //用戶中心-頭像修改 headImgUpdate: function(paramObj) { return this.host + ':' + this.port + '/mem/update_head_img.htm?' + Drore.getReqParams(paramObj); }, //用戶中心-背景牆設置 setBackground: function(paramObj) { return this.host + ':' + this.port + '/mem/set_bground_wall.htm?' + Drore.getReqParams(paramObj); }, //用戶中心-註銷登陸 logout: function(paramObj) { return this.host + ':' + this.port + '/mem/logout.htm?' + Drore.getReqParams(paramObj); }, //用戶中心-我的資料更新 setUserInfo: function(paramObj) { return this.host + ':' + this.port + '/mem/update_self_info.htm?' + Drore.getReqParams(paramObj); }, //用戶中心-評論列表 getCommentList: function(paramObj) { return this.host + ':' + this.port + '/comment/self_list.htm?' + Drore.getReqParams(paramObj); }, //用戶中心-刪除評論 deleteComment: function(paramObj) { return this.host + ':' + this.port + '/comment/delete.htm?' + Drore.getReqParams(paramObj); }, //用戶中心-個人諮詢列表 getMyHelpList: function(paramObj) { return this.host + ':' + this.port + '/serviceform/my_help_list.htm?' + Drore.getReqParams(paramObj); }, //用戶中心-個人諮詢列表 getMyComplaintList: function(paramObj) { return this.host + ':' + this.port + '/serviceform/my_complaint_list.htm?' + Drore.getReqParams(paramObj); }, //用戶中心-諮詢\投訴刪除 deleteService: function(paramObj) { return this.host + ':' + this.port + '/serviceform/delete.htm?' + Drore.getReqParams(paramObj); }, //用戶中心-訂單列表 getOrderList: function(paramObj) { return this.host + ':' + this.port + '/order/my_order.htm?' + Drore.getReqParams(paramObj); }, // 用戶中心-他人相冊列表 getAlbumList: function(paramObj) { return this.host + ':' + this.port + '/mem/album/list.htm?' + Drore.getReqParams(paramObj); }, // 用戶中心-個人相冊列表 getMyAlbumList: function(paramObj) { return this.host + ':' + this.port + '/mem/album/self.htm?' + Drore.getReqParams(paramObj); }, // 用戶中心-相冊圖片列表 getPhotoList: function(paramObj) { return this.host + ':' + this.port + '/mem/photo/list.htm?' + Drore.getReqParams(paramObj); }, // 用戶中心-相冊圖片上傳 photoUpload: function(paramObj) { return this.host + ':' + this.port + '/mem/photo/upload_img.htm?' + Drore.getReqParams(paramObj); }, // 用戶中心-更新圖片信息 photoUpdate: function(paramObj) { return this.host + ':' + this.port + '/mem/photo/update.htm?' + Drore.getReqParams(paramObj); }, // 用戶中心-相冊圖片刪除 photoDelete: function(paramObj) { return this.host + ':' + this.port + '/mem/photo/delete.htm?' + Drore.getReqParams(paramObj); }, //賣家評論列表(景區,酒店,商家) commentList: function(paramObj) { return this.host + ':' + this.port + '/comment/seller_list.htm?' + Drore.getReqParams(paramObj); }, //酒店房型評論列表 roomCommentList: function(paramObj) { return this.host + ':' + this.port + '/comment/room_list.htm?' + Drore.getReqParams(paramObj); }, //商品評論列表 goodsCommentList: function(paramObj) { return this.host + ':' + this.port + '/comment/goods_list.htm?' + Drore.getReqParams(paramObj); }, //評分項配置查詢 getScoreSetting: function(paramObj) { return this.host + ':' + this.port + '/comment/get_score_setting.htm?' + Drore.getReqParams(paramObj); }, //攻略列表 getGuideList: function(paramObj) { return this.host + ':' + this.port + '/guide/list.htm?' + Drore.getReqParams(paramObj); }, //攻略詳情 getGuideDetail: function(paramObj) { return this.host + ':' + this.port + '/guide/detail.htm?' + Drore.getReqParams(paramObj); }, //諮詢列表 getHelpList: function(paramObj) { return this.host + ':' + this.port + '/serviceform/help_list.htm?' + Drore.getReqParams(paramObj); }, //投訴列表 getComplaintList: function(paramObj) { return this.host + ':' + this.port + '/serviceform/complaint_list.htm?' + Drore.getReqParams(paramObj); }, //諮詢\投訴保存 serviceSave: function(paramObj) { return this.host + ':' + this.port + '/serviceform/save.htm?' + Drore.getReqParams(paramObj); }, //諮詢\投訴詳情 getServiceDetail: function(paramObj) { return this.host + ':' + this.port + '/serviceform/detail.htm?' + Drore.getReqParams(paramObj); }, //會員資料查詢 getUserInfoById: function(paramObj) { return this.host + ':' + this.port + '/mem/info_detail.htm?' + Drore.getReqParams(paramObj); }, //便民信息 getConvenienceList: function(paramObj) { return this.host + ':' + this.port + '/serv/conv_list.htm?' + Drore.getReqParams(paramObj); }, // 新聞資訊列表 newsList: function(paramObj) { return this.host + ':' + '/article/arti_list.htm?' + Drore.getReqParams(paramObj); }, // 新聞資訊詳情 newsDetail: function(paramObj){ return this.host + ':' + '/article/detail.htm?' + Drore.getReqParams(paramObj); }, // 特點菜列表 specialDish: function(paramObj){ return this.host + ':' + '/provider/dish_list.htm?' + Drore.getReqParams(paramObj); }, // 特點菜詳情 specialDishDetail: function(paramObj){ return this.host + ':' + '/provider/dish_detail.htm?' + Drore.getReqParams(paramObj); }, // 休閒點贊 xiuxianZan: function(paramObj){ return this.host + ':' + '/scenic/view.htm?' + Drore.getReqParams(paramObj); }, // 特產點贊 specialZan: function(paramObj){ return this.host + ':' + '/goods_type/view.htm?' + Drore.getReqParams(paramObj); } }, ImgLazyLoading: { loadingUrl: '', //'/img/loading.gif', errorUrl: '/img/default.png' } } })(); /** * 登錄及異常處理 */ (function(window, document) { window.Drore = window.Drore || {}; window.Drore.Validate = { phone: /^1[3|4|5|8][0-9]{9}$/, password: /^[a-z0-9A-Z_]{6,12}$/, name: /^[\u4e00-\u9fa5\w]{2,10}$/ }; //異常處理 Drore.exception = function(type) { switch (type) { case 2: alert("網絡問題,請稍候再試!"); break; case 3: alert("網絡問題,請稍候再試!"); break; case 4: if (confirm("您還未登陸,是否先登陸!")) { Drore.pointLogin(); } break; } } //記錄當前url並指向登陸 Drore.pointLogin = function() { var url = location.href, requestURINo = "requestURINo" + Math.random(); Drore.storage.set(requestURINo, url); location.assign("/user/login.html?requestURINo=" + requestURINo); } })(window, document);