139139 . provider ( "$pbox" , [ function ( ) {
140140 // The default options for all popboxs.
141141 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' ,
148148 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 : { }
153154 } ;
154155
155156 var globalOptions = {
156- triggerClass : "pbox-trigger" ,
157+ triggerClass : "pbox-trigger" ,
157158 boxInstanceName : "boxInstance"
158159 } ;
159160
162163 } ;
163164
164165 var util = {
165- hasClass : function ( element , className ) {
166+ hasClass : function ( element , className ) {
166167 return element . hasClass ( className ) || element . parents ( "." + className ) . length > 0 ;
167168 } ,
168169 hasClasses : function ( element , classes ) {
175176 } ) ;
176177 return result ;
177178 } ,
178- getTarget : function ( event ) {
179+ getTarget : function ( event ) {
179180 var $target = angular . element ( event . target ) ;
180181 if ( ! $target ) {
181182 throw new Error ( "The event" )
206207 "$wtPosition" ,
207208 function ( $http , $document , $compile , $rootScope , $controller , $templateCache , $q , $injector , $timeout , $wtPosition ) {
208209
209- var $pbox = { openedElement : null } , $body = angular . element ( document . body ) ;
210+ var $pbox = { } , $body = angular . element ( document . body ) ;
210211
211212 function getTemplatePromise ( options ) {
212213 return options . template ? $q . when ( options . template ) :
246247 } ;
247248
248249 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' ) ) {
268257 return ;
269258 }
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+ }
273275 } ;
274276
275277 BoxModal . prototype . open = function ( tpl , scope ) {
276278 this . _pboxElement = angular . element ( '<div class="pbox"></div>' ) ;
277279 this . _pboxElement . html ( tpl ) ;
278280 this . _$target . addClass ( this . _options . openClass ) ;
279- //$pbox.openedElement = this._pboxElement;
280281 $compile ( this . _pboxElement ) ( scope ) ;
281282 $body . append ( this . _pboxElement ) ;
282283 $timeout ( function ( ) {
283284 $wtPosition . calculatePos ( _self . _options , $target , _self . _pboxElement ) ;
284285 _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 ) ;
286294 } ;
287295
288296 BoxModal . prototype . close = function ( result ) {
289297 this . _remove ( ) ;
290- $document . unbind ( "click .pbox" + this . _id ) ;
298+ $document . unbind ( "mousedown .pbox" + this . _id ) ;
291299 _resultDeferred . resolve ( result ) ;
292300 } ;
293301
331339 templateAndResolvePromise . then ( function resolveSuccess ( tplAndVars ) {
332340
333341 var boxScope = ( options . scope || $rootScope ) . $new ( ) ;
334- boxScope . $close = function ( result ) {
342+ boxScope . $close = function ( result ) {
335343 pboxInstance . close ( result ) ;
336344 } ;
337- boxScope . $dismiss = function ( ) {
345+ boxScope . $dismiss = function ( ) {
338346 pboxInstance . dismiss ( ) ;
339347 } ;
340348
376384 }
377385 ] ;
378386 } ] ) ;
379- } ) ( ) ;
387+ } ) ( ) ;
0 commit comments