@@ -547,11 +547,33 @@ Blaze._toText = function (htmljs, parentView, textMode) {
547547 return HTML . toText ( Blaze . _expand ( htmljs , parentView ) , textMode ) ;
548548} ;
549549
550- Blaze . getCurrentData = function ( ) {
551- var theWith = Blaze . getCurrentView ( 'with' ) ;
550+ Blaze . data = function ( elementOrView ) {
551+ var theWith ;
552+ if ( ! elementOrView ) {
553+ theWith = Blaze . getCurrentView ( 'with' ) ;
554+ } else if ( elementOrView instanceof Blaze . View ) {
555+ var view = elementOrView ;
556+ theWith = ( view . name === 'with' ? view :
557+ Blaze . getParentView ( view , 'with' ) ) ;
558+ } else if ( typeof elementOrView . nodeType === 'number' ) {
559+ if ( elementOrView . nodeType !== 1 )
560+ throw new Error ( "Expected DOM element" ) ;
561+ theWith = Blaze . getElementView ( elementOrView , 'with' ) ;
562+ } else {
563+ throw new Error ( "Expected DOM element or View" ) ;
564+ }
565+
552566 return theWith ? theWith . dataVar . get ( ) : null ;
553567} ;
554568
569+ // For back-compat
570+ Blaze . getElementData = function ( element ) {
571+ if ( element . nodeType !== 1 )
572+ throw new Error ( "Expected DOM element" ) ;
573+
574+ return Blaze . data ( element ) ;
575+ } ;
576+
555577// Gets the current view or its nearest ancestor of name
556578// `name`.
557579Blaze . getCurrentView = function ( name ) {
@@ -607,16 +629,6 @@ Blaze.getElementView = function (elem, name) {
607629 }
608630} ;
609631
610- Blaze . getElementData = function ( elem ) {
611- var theWith = Blaze . getElementView ( elem , 'with' ) ;
612- return theWith ? theWith . dataVar . get ( ) : null ;
613- } ;
614-
615- Blaze . getViewData = function ( view ) {
616- var theWith = Blaze . getParentView ( view , 'with' ) ;
617- return theWith ? theWith . dataVar . get ( ) : null ;
618- } ;
619-
620632Blaze . _addEventMap = function ( view , eventMap , thisInHandler ) {
621633 thisInHandler = ( thisInHandler || null ) ;
622634 var handles = [ ] ;
0 commit comments