11/**
22 * AngularStrap - Twitter Bootstrap directives for AngularJS
3- * @version v0.6.6 - 2013-02-23
3+ * @version v0.7.0 - 2013-03-11
44 * @link http://mgcrea.github.com/angular-strap
55 * @author Olivier Louvignes <[email protected] > 66 * @license MIT License, http://www.opensource.org/licenses/MIT
@@ -77,20 +77,30 @@ angular.module('$strap.directives')
7777
7878 var parentArray = attrs . ngRepeat && attrs . ngRepeat . split ( ' in ' ) . pop ( ) ;
7979
80- element . on ( 'close' , function ( ev ) { console . warn ( 'close!' ) ;
80+ element . on ( 'close' , function ( ev ) {
8181 var removeElement ;
8282
8383 if ( parentArray ) { // ngRepeat, remove from parent array
8484 ev . preventDefault ( ) ;
8585
8686 element . removeClass ( 'in' ) ;
87- console . warn ( scope . $parent ) ;
8887
8988 removeElement = function ( ) {
9089 element . trigger ( 'closed' ) ;
9190 if ( scope . $parent ) {
9291 scope . $parent . $apply ( function ( ) {
93- scope . $parent [ parentArray ] . splice ( scope . $index , 1 ) ;
92+ var path = parentArray . split ( '.' ) ;
93+ var curr = scope . $parent ;
94+
95+ for ( var i = 0 ; i < path . length ; ++ i ) {
96+ if ( curr ) {
97+ curr = curr [ path [ i ] ] ;
98+ }
99+ }
100+
101+ if ( curr ) {
102+ curr . splice ( scope . $index , 1 ) ;
103+ }
94104 } ) ;
95105 }
96106 } ;
@@ -293,33 +303,31 @@ angular.module('$strap.directives')
293303. directive ( 'bsButtonSelect' , [ '$parse' , '$timeout' , function ( $parse , $timeout ) {
294304 'use strict' ;
295305
296- var isTouch = 'ontouchstart' in window ;
297-
298306 return {
299307 restrict : 'A' ,
300308 require : '?ngModel' ,
301- link : function postLink ( scope , element , attr , ctrl ) {
309+ link : function postLink ( scope , element , attrs , ctrl ) {
302310
303- var getter = $parse ( attr . bsButtonSelect ) ,
311+ var getter = $parse ( attrs . bsButtonSelect ) ,
304312 setter = getter . assign ;
305313
306314 // Bind ngModelController
307315 if ( ctrl ) {
308- element . text ( scope . $eval ( attr . ngModel ) ) ;
316+ element . text ( scope . $eval ( attrs . ngModel ) ) ;
309317 // Watch model for changes
310- scope . $watch ( attr . ngModel , function ( newValue , oldValue ) {
318+ scope . $watch ( attrs . ngModel , function ( newValue , oldValue ) {
311319 element . text ( newValue ) ;
312320 } ) ;
313321 }
314322
315-
316323 // Click handling
317324 var values , value , index , newValue ;
318- element . on ( isTouch ? 'touchstart.bsButtonSelect.data-api' : ' click.bsButtonSelect.data-api ', function ( ev ) {
325+ element . bind ( ' click', function ( ev ) {
319326 values = getter ( scope ) ;
320- value = ctrl ? scope . $eval ( attr . ngModel ) : element . text ( ) ;
327+ value = ctrl ? scope . $eval ( attrs . ngModel ) : element . text ( ) ;
321328 index = values . indexOf ( value ) ;
322329 newValue = index > values . length - 2 ? values [ 0 ] : values [ index + 1 ] ;
330+ console . warn ( values , newValue ) ;
323331
324332 scope . $apply ( function ( ) {
325333 element . text ( newValue ) ;
@@ -330,6 +338,7 @@ angular.module('$strap.directives')
330338 } ) ;
331339 }
332340 } ;
341+
333342} ] ) ;
334343
335344// https://github.com/eternicode/bootstrap-datepicker
@@ -429,6 +438,7 @@ angular.module('$strap.directives')
429438 element . attr ( 'data-toggle' , 'datepicker' ) ;
430439 element . datepicker ( {
431440 autoclose : true ,
441+ forceParse : attrs . forceParse || false ,
432442 language : attrs . language || 'en'
433443 } ) ;
434444
@@ -518,7 +528,7 @@ angular.module('$strap.directives')
518528 }
519529
520530 // Build modal object
521- var id = getter ( scope ) . replace ( '.html' , '' ) . replace ( / \/ / g , '-' ) . replace ( / \. / g, '-' ) + '-' + scope . $id ;
531+ var id = getter ( scope ) . replace ( '.html' , '' ) . replace ( / [ \/ | \. | : ] / g, "-" ) + '-' + scope . $id ;
522532 var $modal = $ ( '<div class="modal hide" tabindex="-1"></div>' )
523533 . attr ( 'id' , id )
524534 . attr ( 'data-backdrop' , attr . backdrop || true )
@@ -689,6 +699,39 @@ angular.module('$strap.directives')
689699
690700} ] ) ;
691701
702+ angular . module ( '$strap.directives' )
703+
704+ . directive ( 'bsTabs' , [ '$parse' , '$compile' , function ( $parse , $compile ) {
705+ 'use strict' ;
706+
707+ return {
708+ restrict : 'A' ,
709+ link : function postLink ( scope , iElement , iAttrs , controller ) {
710+
711+ var tabs = [ '<ul class="nav nav-tabs">' , '</ul>' ] ;
712+ var panes = [ '<div class="tab-content">' , '</div>' ] ;
713+
714+ iElement . find ( '[data-tab]' ) . each ( function ( index ) {
715+ var $this = angular . element ( this ) ,
716+ id = 'tab-' + scope . $id + '-' + index ,
717+ active = $this . hasClass ( 'active' ) ,
718+ fade = $this . hasClass ( 'fade' ) ,
719+ title = scope . $eval ( $this . data ( 'tab' ) ) ;
720+ tabs . splice ( index + 1 , 0 , '<li' + ( active ? ' class="active"' : '' ) + '><a href="#' + id + '" data-toggle="tab">' + title + '</a></li>' ) ;
721+ panes . splice ( index + 1 , 0 , '<div class="tab-pane ' + $this . attr ( 'class' ) + ( fade && active ? ' in' : '' ) + '" id="' + id + '">' + this . innerHTML + '</div>' ) ;
722+ } ) ;
723+
724+ iElement . html ( tabs . join ( '' ) + panes . join ( '' ) ) ;
725+
726+ // Compile tab-content
727+ $compile ( iElement . children ( 'div.tab-content' ) ) ( scope ) ;
728+ }
729+
730+ } ;
731+
732+ } ] ) ;
733+
734+
692735// https://github.com/jdewit/bootstrap-timepicker
693736// https://github.com/kla/bootstrap-timepicker
694737
@@ -891,7 +934,7 @@ angular.module('$strap.directives')
891934 if ( attrs . minLength === "0" ) {
892935 setTimeout ( function ( ) { // Push to the event loop to make sure element.typeahead is defined (breaks tests otherwise)
893936 element . on ( 'focus' , function ( ) {
894- setTimeout ( element . typeahead . bind ( element , 'lookup' ) , 200 ) ;
937+ element . val ( ) . length === 0 && setTimeout ( element . typeahead . bind ( element , 'lookup' ) , 200 ) ;
895938 } ) ;
896939 } ) ;
897940 }
0 commit comments