Skip to content

Commit bbc791a

Browse files
committed
upgrade 0.0.4
1 parent c9dfd3f commit bbc791a

File tree

2 files changed

+21
-19
lines changed

2 files changed

+21
-19
lines changed

sample/index.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,9 +103,9 @@
103103
}
104104
});
105105
pbox.result.then(function (result) {
106-
alert("close,result:" + result);
106+
//alert("close,result:" + result);
107107
}, function () {
108-
alert("dismiss");
108+
//alert("dismiss");
109109
});
110110
};
111111
}]);

src/pbox.js

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@
6767
case "left":
6868
right = ~~(docOuterWidth - elementLeft + options.offset);
6969
if (right + boxWidth + options.offset > docOuterWidth) {
70-
right = 0;
70+
right = undefined;
7171
left = ~~(elementLeft + elementOuterWidth + options.offset);
7272
}
7373
if (options.align === "top") {
@@ -88,7 +88,7 @@
8888
case "right":
8989
left = elementLeft + elementOuterWidth + options.offset;
9090
if (left + boxWidth + options.offset > docOuterWidth) {
91-
left = 0;
91+
left = undefined;
9292
right = docOuterWidth - elementLeft + options.offset;
9393
}
9494
if (options.align === "top") {
@@ -223,7 +223,7 @@
223223
return promisesArr;
224224
}
225225

226-
function PBoxModal(options, $target) {
226+
function BoxModal(options, $target) {
227227
var _resultDeferred = $q.defer();
228228
var _openedDeferred = $q.defer();
229229
var _self = this;
@@ -238,13 +238,13 @@
238238

239239
$target.data(globalOptions.boxInstanceName, this);
240240

241-
PBoxModal.prototype._remove = function () {
241+
BoxModal.prototype._remove = function () {
242242
_self._$target.removeData(globalOptions.boxInstanceName);
243243
_self._$target.removeClass(this._options.openClass);
244244
_self._pboxElement.remove();
245245
};
246246

247-
PBoxModal.prototype._bindEvents = function () {
247+
BoxModal.prototype._bindEvents = function () {
248248
$document.bind("mousedown.pbox", function (e) {
249249
var _eTarget = angular.element(e.target);
250250
if (util.hasClass(_eTarget, 'pbox')) {
@@ -268,7 +268,7 @@
268268
});
269269
};
270270

271-
PBoxModal.prototype.open = function (tpl, scope) {
271+
BoxModal.prototype.open = function (tpl, scope) {
272272
_self._pboxElement = angular.element('<div class="pbox"></div>');
273273
_self._pboxElement.html(tpl);
274274
_self._$target.addClass(_self._options.openClass);
@@ -280,12 +280,12 @@
280280
_self._bindEvents();
281281
};
282282

283-
PBoxModal.prototype.close = function (result) {
283+
BoxModal.prototype.close = function (result) {
284284
_self._remove();
285285
_resultDeferred.resolve(result);
286286
};
287287

288-
PBoxModal.prototype.dismiss = function (reason) {
288+
BoxModal.prototype.dismiss = function (reason) {
289289
_self._remove();
290290
_resultDeferred.reject(reason);
291291
}
@@ -310,40 +310,42 @@
310310
options.placement = $target.data("placement") ? $target.data("placement") : options.placement;
311311
options.align = $target.data("align") ? $target.data("align") : options.align;
312312
if ($target.data(globalOptions.boxInstanceName)) {
313-
return $target.data(globalOptions.boxInstanceName).close();
313+
$target.data(globalOptions.boxInstanceName).close();
314+
//fix click error when user result.then();
315+
return {result: $q.defer().promise};
314316
}
315317

316-
var pboxInstance = new PBoxModal(options, $target);
318+
var pboxInstance = new BoxModal(options, $target);
317319

318320
var templateAndResolvePromise =
319321
$q.all([getTemplatePromise(options)].concat(getResolvePromises(options.resolve)));
320322

321323
templateAndResolvePromise.then(function resolveSuccess(tplAndVars) {
322324

323-
var pboxScope = (options.scope || $rootScope).$new();
324-
pboxScope.$close = pboxInstance.close;
325-
pboxScope.$dismiss = pboxInstance.dismiss;
325+
var boxScope = (options.scope || $rootScope).$new();
326+
boxScope.$close = pboxInstance.close;
327+
boxScope.$dismiss = pboxInstance.dismiss;
326328

327329
var ctrlInstance, ctrlLocals = {};
328330
var resolveIter = 1;
329331

330332
//controllers
331333
if (options.controller) {
332-
ctrlLocals.$scope = pboxScope;
334+
ctrlLocals.$scope = boxScope;
333335
ctrlLocals.$pboxInstance = pboxInstance;
334-
pboxScope.$pboxInstance = pboxInstance;
336+
boxScope.$pboxInstance = pboxInstance;
335337
angular.forEach(options.resolve, function (value, key) {
336338
ctrlLocals[key] = tplAndVars[resolveIter++];
337339
});
338340

339341
ctrlInstance = $controller(options.controller, ctrlLocals);
340342
pboxInstance.ctrlInstance = ctrlInstance;
341343
if (options.controllerAs) {
342-
pboxScope[options.controllerAs] = ctrlInstance;
344+
boxScope[options.controllerAs] = ctrlInstance;
343345
}
344346
}
345347

346-
pboxInstance.open(tplAndVars[0], pboxScope);
348+
pboxInstance.open(tplAndVars[0], boxScope);
347349

348350
}, function resolveError(reason) {
349351
pboxInstance.resultDeferred.reject(reason);

0 commit comments

Comments
 (0)