139
139
. provider ( "$pbox" , [ function ( ) {
140
140
// The default options for all popboxs.
141
141
var defaultOptions = {
142
- placement : 'bottom' ,
143
- align : null ,
144
- animation : false ,
145
- popupDelay : 0 ,
146
- arrow : false ,
147
- openClass : 'pbox-open' ,
142
+ placement : 'bottom' ,
143
+ align : null , //居什么对齐 left,right,bottom,top
144
+ animation : false , //是否有动画
145
+ delay : 0 , //延迟多长时间弹出
146
+ arrow : false ,
147
+ openClass : 'pbox-open' ,
148
148
closeClass : 'pbox-close' ,
149
- autoClose : true ,
150
- offset : 1 ,
151
- autoAdapt : true ,
152
- resolve : { }
149
+ autoClose : true , //点击其他区域自动关闭
150
+ offset : 1 , //位移位置
151
+ autoAdapt : true , //是否自动计算上下,左右的高度或者宽度,当 placement 为 bottom,top的时候为true,自动调整 placement
152
+ watch : false , //watch 弹出框的宽高,当有变化的时候重新计算位置
153
+ resolve : { }
153
154
} ;
154
155
155
156
var globalOptions = {
156
- triggerClass : "pbox-trigger" ,
157
+ triggerClass : "pbox-trigger" ,
157
158
boxInstanceName : "boxInstance"
158
159
} ;
159
160
162
163
} ;
163
164
164
165
var util = {
165
- hasClass : function ( element , className ) {
166
+ hasClass : function ( element , className ) {
166
167
return element . hasClass ( className ) || element . parents ( "." + className ) . length > 0 ;
167
168
} ,
168
169
hasClasses : function ( element , classes ) {
175
176
} ) ;
176
177
return result ;
177
178
} ,
178
- getTarget : function ( event ) {
179
+ getTarget : function ( event ) {
179
180
var $target = angular . element ( event . target ) ;
180
181
if ( ! $target ) {
181
182
throw new Error ( "The event" )
206
207
"$wtPosition" ,
207
208
function ( $http , $document , $compile , $rootScope , $controller , $templateCache , $q , $injector , $timeout , $wtPosition ) {
208
209
209
- var $pbox = { openedElement : null } , $body = angular . element ( document . body ) ;
210
+ var $pbox = { } , $body = angular . element ( document . body ) ;
210
211
211
212
function getTemplatePromise ( options ) {
212
213
return options . template ? $q . when ( options . template ) :
246
247
} ;
247
248
248
249
BoxModal . prototype . _bindEvents = function ( ) {
249
- var _self = this ;
250
- _self . _pboxElement . bind ( "mousedown.pbox" , function ( e ) {
251
- e . stopPropagation ( ) ;
252
- } ) ;
253
- $document . bind ( "mousedown.pbox" + this . _id , function ( e ) {
254
- var _eTarget = angular . element ( e . target ) ;
255
- if ( util . hasClass ( _eTarget , 'pbox' ) ) {
256
- return ;
257
- }
258
- if ( util . hasClass ( _eTarget , globalOptions . triggerClass ) ) {
259
- var isResult = false ;
260
- var _target = util . getTarget ( e ) ;
261
- if ( _target && _target . data ( globalOptions . boxInstanceName ) ) {
262
- var instance = _target . data ( globalOptions . boxInstanceName ) ;
263
- if ( instance === _self ) {
264
- isResult = true ;
265
- }
266
- }
267
- if ( isResult ) {
250
+ if ( _self . _options . autoClose ) {
251
+ _self . _pboxElement . bind ( "mousedown.pbox" , function ( e ) {
252
+ e . stopPropagation ( ) ;
253
+ } ) ;
254
+ $document . bind ( "mousedown.pbox" + _self . _id , function ( e ) {
255
+ var _eTarget = angular . element ( e . target ) ;
256
+ if ( util . hasClass ( _eTarget , 'pbox' ) ) {
268
257
return ;
269
258
}
270
- }
271
- _self . close ( ) ;
272
- } ) ;
259
+ if ( util . hasClass ( _eTarget , globalOptions . triggerClass ) ) {
260
+ var isResult = false ;
261
+ var _target = util . getTarget ( e ) ;
262
+ if ( _target && _target . data ( globalOptions . boxInstanceName ) ) {
263
+ var instance = _target . data ( globalOptions . boxInstanceName ) ;
264
+ if ( instance === _self ) {
265
+ isResult = true ;
266
+ }
267
+ }
268
+ if ( isResult ) {
269
+ return ;
270
+ }
271
+ }
272
+ _self . close ( ) ;
273
+ } ) ;
274
+ }
273
275
} ;
274
276
275
277
BoxModal . prototype . open = function ( tpl , scope ) {
276
278
this . _pboxElement = angular . element ( '<div class="pbox"></div>' ) ;
277
279
this . _pboxElement . html ( tpl ) ;
278
280
this . _$target . addClass ( this . _options . openClass ) ;
279
- //$pbox.openedElement = this._pboxElement;
280
281
$compile ( this . _pboxElement ) ( scope ) ;
281
282
$body . append ( this . _pboxElement ) ;
282
283
$timeout ( function ( ) {
283
284
$wtPosition . calculatePos ( _self . _options , $target , _self . _pboxElement ) ;
284
285
_self . _bindEvents ( ) ;
285
- } ) ;
286
+ if ( _self . _options . watch ) {
287
+ scope . $watch ( function ( ) {
288
+ return _self . _pboxElement . width ( ) + "," + _self . _pboxElement . height ( )
289
+ } , function ( ) {
290
+ $wtPosition . calculatePos ( _self . _options , $target , _self . _pboxElement ) ;
291
+ } )
292
+ }
293
+ } , this . _options . delay ) ;
286
294
} ;
287
295
288
296
BoxModal . prototype . close = function ( result ) {
289
297
this . _remove ( ) ;
290
- $document . unbind ( "click .pbox" + this . _id ) ;
298
+ $document . unbind ( "mousedown .pbox" + this . _id ) ;
291
299
_resultDeferred . resolve ( result ) ;
292
300
} ;
293
301
331
339
templateAndResolvePromise . then ( function resolveSuccess ( tplAndVars ) {
332
340
333
341
var boxScope = ( options . scope || $rootScope ) . $new ( ) ;
334
- boxScope . $close = function ( result ) {
342
+ boxScope . $close = function ( result ) {
335
343
pboxInstance . close ( result ) ;
336
344
} ;
337
- boxScope . $dismiss = function ( ) {
345
+ boxScope . $dismiss = function ( ) {
338
346
pboxInstance . dismiss ( ) ;
339
347
} ;
340
348
376
384
}
377
385
] ;
378
386
} ] ) ;
379
- } ) ( ) ;
387
+ } ) ( ) ;
0 commit comments