Skip to content

Commit 527d47d

Browse files
committed
解决原型方法作用域的问题
1 parent ff57a8e commit 527d47d

File tree

2 files changed

+22
-23
lines changed

2 files changed

+22
-23
lines changed

bower.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "angular-wtpbox",
3-
"version": "0.0.16",
3+
"version": "0.0.17",
44
"main": "src/pbox.js",
55
"dependencies": {
66
"angular": "~1.2.25",

src/pbox.js

Lines changed: 21 additions & 22 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")
@@ -239,18 +239,15 @@
239239
}
240240

241241
function BoxModal(options, $target) {
242-
var _resultDeferred = $q.defer();
243-
var _openedDeferred = $q.defer();
244-
var _self = this;
245242
this._id = new Date().getTime() + Math.random().toString(36).substr(2);
246-
this.resultDeferred = _resultDeferred;
247-
this.openedDeferred = _openedDeferred;
248-
this.result = _resultDeferred.promise;
249-
this.opened = _openedDeferred.promise;
243+
this.resultDeferred = $q.defer();
244+
this.openedDeferred = $q.defer();
245+
this.result = this.resultDeferred.promise;
246+
this.opened = this.openedDeferred.promise;
250247
this._options = options;
251248
this._pboxElement = null;
252249
this._$target = $target;
253-
$target.data(globalOptions.boxInstanceName, _self);
250+
$target.data(globalOptions.boxInstanceName, this);
254251

255252
BoxModal.prototype._remove = function () {
256253
this._$target.removeData(globalOptions.boxInstanceName);
@@ -259,6 +256,7 @@
259256
};
260257

261258
BoxModal.prototype._bindEvents = function () {
259+
var _self = this;
262260
if (_self._options.autoClose) {
263261
_self._pboxElement.bind("mousedown.pbox", function (e) {
264262
e.stopPropagation();
@@ -297,6 +295,7 @@
297295
};
298296

299297
BoxModal.prototype.open = function (tpl, scope) {
298+
var _self = this;
300299
this._pboxElement = angular.element('<div class="pbox"></div>');
301300
this._pboxElement.html(tpl);
302301
this._$target.addClass(this._options.openClass);

0 commit comments

Comments
 (0)