11/*!
22 * ui-select
33 * http://github.com/angular-ui/ui-select
4- * Version: 0.14.5 - 2016-02-18T20:39:22.471Z
4+ * Version: 0.14.6 - 2016-02-18T21:01:36.893Z
55 * License: MIT
66 */
77
@@ -268,6 +268,7 @@ uis.controller('uiSelectCtrl',
268268 ctrl . searchEnabled = uiSelectConfig . searchEnabled ;
269269 ctrl . sortable = uiSelectConfig . sortable ;
270270 ctrl . refreshDelay = uiSelectConfig . refreshDelay ;
271+ ctrl . paste = uiSelectConfig . paste ;
271272
272273 ctrl . removeSelected = false ; //If selected item(s) should be removed from dropdown list
273274 ctrl . closeOnSelect = true ; //Initialized inside uiSelect directive link function
@@ -592,7 +593,7 @@ uis.controller('uiSelectCtrl',
592593 // create new item on the fly if we don't already have one;
593594 // use tagging function if we have one
594595 if ( ctrl . tagging . fct !== undefined && typeof item === 'string' ) {
595- item = ctrl . tagging . fct ( ctrl . search ) ;
596+ item = ctrl . tagging . fct ( item ) ;
596597 if ( ! item ) return ;
597598 // if item type is 'string', apply the tagging label
598599 } else if ( typeof item === 'string' ) {
@@ -788,20 +789,38 @@ uis.controller('uiSelectCtrl',
788789
789790 } ) ;
790791
791- // If tagging try to split by tokens and add items
792792 ctrl . searchInput . on ( 'paste' , function ( e ) {
793- var data = e . originalEvent . clipboardData . getData ( 'text/plain' ) ;
794- if ( data && data . length > 0 && ctrl . taggingTokens . isActivated ) {
795- // split by first token only
796- var separator = KEY . toSeparator ( ctrl . taggingTokens . tokens [ 0 ] ) ;
797- var items = data . split ( separator ) ;
798- if ( items && items . length > 0 ) {
793+ var data ;
794+
795+ if ( window . clipboardData && window . clipboardData . getData ) { // IE
796+ data = window . clipboardData . getData ( 'Text' ) ;
797+ } else {
798+ data = ( e . originalEvent || e ) . clipboardData . getData ( 'text/plain' ) ;
799+ }
800+
801+ // Prepend the current input field text to the paste buffer.
802+ data = ctrl . search + data ;
803+
804+ if ( data && data . length > 0 ) {
805+ // If tagging try to split by tokens and add items
806+ if ( ctrl . taggingTokens . isActivated ) {
807+ var separator = KEY . toSeparator ( ctrl . taggingTokens . tokens [ 0 ] ) ;
808+ var items = data . split ( separator || ctrl . taggingTokens . tokens [ 0 ] ) ; // split by first token only
809+ if ( items && items . length > 0 ) {
799810 var oldsearch = ctrl . search ;
800- angular . forEach ( items , function ( item ) {
801- ctrl . search = item ;
802- ctrl . select ( item , true ) ;
803- } ) ;
804- ctrl . search = oldsearch ;
811+ angular . forEach ( items , function ( item ) {
812+ var newItem = ctrl . tagging . fct ? ctrl . tagging . fct ( item ) : item ;
813+ if ( newItem ) {
814+ ctrl . select ( newItem , true ) ;
815+ }
816+ } ) ;
817+ ctrl . search = oldsearch || EMPTY_SEARCH ;
818+ e . preventDefault ( ) ;
819+ e . stopPropagation ( ) ;
820+ }
821+ } else if ( ctrl . paste ) {
822+ ctrl . paste ( data ) ;
823+ ctrl . search = EMPTY_SEARCH ;
805824 e . preventDefault ( ) ;
806825 e . stopPropagation ( ) ;
807826 }
@@ -941,6 +960,10 @@ uis.directive('uiSelect',
941960 $select . resetSearchInput = resetSearchInput !== undefined ? resetSearchInput : true ;
942961 } ) ;
943962
963+ attrs . $observe ( 'paste' , function ( ) {
964+ $select . paste = scope . $eval ( attrs . paste ) ;
965+ } ) ;
966+
944967 attrs . $observe ( 'tagging' , function ( ) {
945968 if ( attrs . tagging !== undefined )
946969 {
@@ -1778,37 +1801,37 @@ uis.directive('uiSelectSingle', ['$timeout','$compile', function($timeout, $comp
17781801// Make multiple matches sortable
17791802uis . directive ( 'uiSelectSort' , [ '$timeout' , 'uiSelectConfig' , 'uiSelectMinErr' , function ( $timeout , uiSelectConfig , uiSelectMinErr ) {
17801803 return {
1781- require : '^uiSelect' ,
1804+ require : '^^ uiSelect' ,
17821805 link : function ( scope , element , attrs , $select ) {
17831806 if ( scope [ attrs . uiSelectSort ] === null ) {
1784- throw uiSelectMinErr ( 'sort' , " Expected a list to sort" ) ;
1807+ throw uiSelectMinErr ( 'sort' , ' Expected a list to sort' ) ;
17851808 }
17861809
17871810 var options = angular . extend ( {
17881811 axis : 'horizontal'
17891812 } ,
17901813 scope . $eval ( attrs . uiSelectSortOptions ) ) ;
17911814
1792- var axis = options . axis ,
1793- draggingClassName = 'dragging' ,
1794- droppingClassName = 'dropping' ,
1795- droppingBeforeClassName = 'dropping-before' ,
1796- droppingAfterClassName = 'dropping-after' ;
1815+ var axis = options . axis ;
1816+ var draggingClassName = 'dragging' ;
1817+ var droppingClassName = 'dropping' ;
1818+ var droppingBeforeClassName = 'dropping-before' ;
1819+ var droppingAfterClassName = 'dropping-after' ;
17971820
17981821 scope . $watch ( function ( ) {
17991822 return $select . sortable ;
1800- } , function ( n ) {
1801- if ( n ) {
1823+ } , function ( newValue ) {
1824+ if ( newValue ) {
18021825 element . attr ( 'draggable' , true ) ;
18031826 } else {
18041827 element . removeAttr ( 'draggable' ) ;
18051828 }
18061829 } ) ;
18071830
1808- element . on ( 'dragstart' , function ( e ) {
1831+ element . on ( 'dragstart' , function ( event ) {
18091832 element . addClass ( draggingClassName ) ;
18101833
1811- ( e . dataTransfer || e . originalEvent . dataTransfer ) . setData ( 'text/plain' , scope . $index ) ;
1834+ ( event . dataTransfer || event . originalEvent . dataTransfer ) . setData ( 'text/plain' , scope . $index ) ;
18121835 } ) ;
18131836
18141837 element . on ( 'dragend' , function ( ) {
@@ -1820,10 +1843,10 @@ uis.directive('uiSelectSort', ['$timeout', 'uiSelectConfig', 'uiSelectMinErr', f
18201843 this . splice ( to , 0 , this . splice ( from , 1 ) [ 0 ] ) ;
18211844 } ;
18221845
1823- var dragOverHandler = function ( e ) {
1824- e . preventDefault ( ) ;
1846+ var dragOverHandler = function ( event ) {
1847+ event . preventDefault ( ) ;
18251848
1826- var offset = axis === 'vertical' ? e . offsetY || e . layerY || ( e . originalEvent ? e . originalEvent . offsetY : 0 ) : e . offsetX || e . layerX || ( e . originalEvent ? e . originalEvent . offsetX : 0 ) ;
1849+ var offset = axis === 'vertical' ? event . offsetY || event . layerY || ( event . originalEvent ? event . originalEvent . offsetY : 0 ) : event . offsetX || event . layerX || ( event . originalEvent ? event . originalEvent . offsetX : 0 ) ;
18271850
18281851 if ( offset < ( this [ axis === 'vertical' ? 'offsetHeight' : 'offsetWidth' ] / 2 ) ) {
18291852 element . removeClass ( droppingAfterClassName ) ;
@@ -1837,10 +1860,10 @@ uis.directive('uiSelectSort', ['$timeout', 'uiSelectConfig', 'uiSelectMinErr', f
18371860
18381861 var dropTimeout ;
18391862
1840- var dropHandler = function ( e ) {
1841- e . preventDefault ( ) ;
1863+ var dropHandler = function ( event ) {
1864+ event . preventDefault ( ) ;
18421865
1843- var droppedItemIndex = parseInt ( ( e . dataTransfer || e . originalEvent . dataTransfer ) . getData ( 'text/plain' ) , 10 ) ;
1866+ var droppedItemIndex = parseInt ( ( event . dataTransfer || event . originalEvent . dataTransfer ) . getData ( 'text/plain' ) , 10 ) ;
18441867
18451868 // prevent event firing multiple times in firefox
18461869 $timeout . cancel ( dropTimeout ) ;
@@ -1850,9 +1873,9 @@ uis.directive('uiSelectSort', ['$timeout', 'uiSelectConfig', 'uiSelectMinErr', f
18501873 } ;
18511874
18521875 var _dropHandler = function ( droppedItemIndex ) {
1853- var theList = scope . $eval ( attrs . uiSelectSort ) ,
1854- itemToMove = theList [ droppedItemIndex ] ,
1855- newIndex = null ;
1876+ var theList = scope . $eval ( attrs . uiSelectSort ) ;
1877+ var itemToMove = theList [ droppedItemIndex ] ;
1878+ var newIndex = null ;
18561879
18571880 if ( element . hasClass ( droppingBeforeClassName ) ) {
18581881 if ( droppedItemIndex < scope . $index ) {
@@ -1897,8 +1920,8 @@ uis.directive('uiSelectSort', ['$timeout', 'uiSelectConfig', 'uiSelectMinErr', f
18971920 element . on ( 'drop' , dropHandler ) ;
18981921 } ) ;
18991922
1900- element . on ( 'dragleave' , function ( e ) {
1901- if ( e . target != element ) {
1923+ element . on ( 'dragleave' , function ( event ) {
1924+ if ( event . target != element ) {
19021925 return ;
19031926 }
19041927 element . removeClass ( droppingClassName ) ;
0 commit comments