37 lines
1.2 KiB
JavaScript
37 lines
1.2 KiB
JavaScript
|
define(function(require, exports) {
|
|||
|
var $html = '<div id="citySelector"><div class="allCityList"><ul class="city-recently-used"><li class="selected">常用</li><li>A-E</li><li>F-J</li><li>K-O</li><li>P-T</li><li>U-Z</li></ul><div class="common"><p>常用城市</p><dl class="commonCityList"></dl></div><ul class="cityList"></ul><div class="cityPager"><button class="city-prev" disabled="disabled">上一页</button><button class="city-next">下一页</button></div></div></div>';
|
|||
|
var selector;
|
|||
|
var divCity;
|
|||
|
|
|||
|
var CitySelector = function(options) {
|
|||
|
var that = this;
|
|||
|
|
|||
|
that.showPopup = function(ele) {
|
|||
|
|
|||
|
var offset = ele.offset();
|
|||
|
divCity.css({ left: offset.left + "px", top: (offset.top + ele.height()) + "px" });
|
|||
|
divCity.addClass("open");
|
|||
|
};
|
|||
|
that.hidePopup = function() {
|
|||
|
divCity.removeClass("open");
|
|||
|
};
|
|||
|
|
|||
|
return this;
|
|||
|
};
|
|||
|
|
|||
|
exports.init = function(eleSelector, args) {
|
|||
|
$("body").append($html);
|
|||
|
divCity = $("#citySelector");
|
|||
|
|
|||
|
args = $.extend({}, args);
|
|||
|
|
|||
|
selector = new CitySelector(args);
|
|||
|
|
|||
|
|
|||
|
$(document).on("focus", eleSelector, function () {
|
|||
|
selector.showPopup($(this));
|
|||
|
}).on("blur", eleSelector, function () {
|
|||
|
selector.hidePopup($(this));
|
|||
|
});
|
|||
|
};
|
|||
|
});
|