Skip to content

Commit 0b5efb9

Browse files
author
zhenshuai
committed
add esc key press
1 parent a9e199a commit 0b5efb9

File tree

1 file changed

+28
-14
lines changed

1 file changed

+28
-14
lines changed

src/pbox.js

Lines changed: 28 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -150,23 +150,23 @@
150150
.provider("$pbox", [function () {
151151
// The default options for all popboxs.
152152
var defaultOptions = {
153-
placement: 'bottom',
154-
align: null, //居什么对齐 left,right,bottom,top
155-
animation: false,//是否有动画
156-
delay: 0, //延迟多长时间弹出
157-
arrow: false,
158-
openClass: 'pbox-open',
153+
placement : 'bottom',
154+
align : null, //居什么对齐 left,right,bottom,top
155+
animation : false,//是否有动画
156+
delay : 0, //延迟多长时间弹出
157+
arrow : false,
158+
openClass : 'pbox-open',
159159
closeClass: 'pbox-close',
160-
autoClose: true, //点击其他区域自动关闭,当点击触发弹出框的元素或者弹出框内部元素时不关闭,
160+
autoClose : true, //点击其他区域自动关闭,当点击触发弹出框的元素或者弹出框内部元素时不关闭,
161161
forceClose: false,//autoClose为true时起作用,点击触发弹出框的元素也关闭
162-
offset: 1, //位移位置
163-
autoAdapt: true, //是否自动计算上下,左右的高度或者宽度,当 placement 为 bottom,top的时候为true,自动调整 placement
164-
watch: false,//watch 弹出框的宽高,当有变化的时候重新计算位置
165-
resolve: {}
162+
offset : 1, //位移位置
163+
autoAdapt : true, //是否自动计算上下,左右的高度或者宽度,当 placement 为 bottom,top的时候为true,自动调整 placement
164+
watch : false,//watch 弹出框的宽高,当有变化的时候重新计算位置
165+
resolve : {}
166166
};
167167

168168
var globalOptions = {
169-
triggerClass: "pbox-trigger",
169+
triggerClass : "pbox-trigger",
170170
boxInstanceName: "boxInstance"
171171
};
172172

@@ -175,7 +175,7 @@
175175
};
176176

177177
var util = {
178-
hasClass: function (element, className) {
178+
hasClass : function (element, className) {
179179
return element.hasClass(className) || element.parents("." + className).length > 0;
180180
},
181181
hasClasses: function (element, classes) {
@@ -188,7 +188,7 @@
188188
});
189189
return result;
190190
},
191-
getTarget: function (event) {
191+
getTarget : function (event) {
192192
var $target = angular.element(event.target);
193193
if (!$target) {
194194
throw new Error("The event")
@@ -283,6 +283,16 @@
283283
}
284284
_self.close();
285285
});
286+
287+
_self._pboxElement.bind("keydown.pbox", function (e) {
288+
e.stopPropagation();
289+
});
290+
$document.bind("keydown.pbox" + _self._id, function (evt) {
291+
if (evt.which == 27) {
292+
evt.preventDefault();
293+
_self.close();
294+
}
295+
});
286296
}
287297
};
288298

@@ -315,13 +325,17 @@
315325
this._scope && this._scope.$destroy();
316326
this._scope = null;
317327
$document.unbind("mousedown.pbox" + this._id);
328+
$document.unbind("keydown.pbox" + this._id);
318329
_resultDeferred.resolve(result);
319330
};
320331

321332
BoxModal.prototype.dismiss = function (reason) {
322333
this._remove();
334+
this.$watch && this.$watch();
323335
this._scope && this._scope.$destroy();
324336
this._scope = null;
337+
$document.unbind("mousedown.pbox" + this._id);
338+
$document.unbind("keydown.pbox" + this._id);
325339
_resultDeferred.reject(reason);
326340
}
327341
}

0 commit comments

Comments
 (0)