@@ -667,27 +667,27 @@ define(function(require) {
667
667
}
668
668
}
669
669
670
- function initializeNewNode ( node , context ) {
670
+ function initializeNewNode ( view ) {
671
+ var node = view . model ;
671
672
var metadata = node . attr ( 'metadata' ) ;
672
- var view = context . paper . findViewByModel ( node ) ;
673
673
if ( metadata ) {
674
- var isPalette = view && ( context . graph . attributes . type === joint . shapes . flo . PALETTE_TYPE ) ;
675
-
674
+ var paper = view . paper ;
675
+ var isPalette = paper . model . get ( 'type' ) === joint . shapes . flo . PALETTE_TYPE ;
676
676
if ( metadata . name === 'tap' ) {
677
- refreshVisuals ( node , 'props/name' , context . paper ) ;
677
+ refreshVisuals ( node , 'props/name' , paper ) ;
678
678
} else if ( metadata . name === 'destination' ) {
679
- refreshVisuals ( node , 'props/name' , context . paper ) ;
679
+ refreshVisuals ( node , 'props/name' , paper ) ;
680
680
} else {
681
- refreshVisuals ( node , 'node-name' , context . paper ) ;
681
+ refreshVisuals ( node , 'node-name' , paper ) ;
682
682
}
683
683
684
684
if ( ! isPalette ) {
685
- refreshVisuals ( node , 'stream-name' , context . paper ) ;
685
+ refreshVisuals ( node , 'stream-name' , paper ) ;
686
686
}
687
687
688
688
// Attach angular style tooltip to a app view
689
689
if ( view ) {
690
- if ( context . graph . attributes . type === joint . shapes . flo . CANVAS_TYPE ) {
690
+ if ( paper . model . attributes . type === joint . shapes . flo . CANVAS_TYPE ) {
691
691
attachCanvasAppTooltip ( view ) ;
692
692
} else if ( isPalette ) {
693
693
attachPaletteAppTooltip ( view ) ;
@@ -697,72 +697,64 @@ define(function(require) {
697
697
}
698
698
699
699
/**
700
- * Sets some initialization data on the decoration Joint JS model element
700
+ * Sets some initialization data on the decoration Joint JS view object
701
701
*
702
- * @param decoration Joint JS model object for decoration
703
- * @param context The context of the object (corresponding Joint JS graph and paper objects)
702
+ * @param view Joint JS view object for decoration
704
703
*/
705
- function initializeNewDecoration ( decoration , context ) {
706
- // Find the Joint JS view object giveb the model. View object should exist by now.
707
- var view = context . paper . findViewByModel ( decoration ) ;
704
+ function initializeNewDecoration ( view ) {
708
705
// Attach angular-bootstrap-ui tooltip to error marker
709
- if ( view && decoration . attr ( './kind' ) === 'error' ) {
706
+ if ( view . model . attr ( './kind' ) === 'error' ) {
710
707
attachErrorMarkerTooltip ( view ) ;
711
708
}
712
709
}
713
710
714
711
/**
715
- * Sets some initialization data on the handle Joint JS model element
712
+ * Sets some initialization data on the handle Joint JS view object
716
713
*
717
- * @param handle Joint JS model object for handle
718
- * @param context The context of the object (corresponding Joint JS graph and paper objects)
714
+ * @param view Joint JS view object for handle
719
715
*/
720
- function initializeNewHandle ( handle , context ) {
721
- // Find the Joint JS view object giveb the model. View object should exist by now.
722
- var view = context . paper . findViewByModel ( handle ) ;
723
- if ( view ) {
716
+ function initializeNewHandle ( view ) {
717
+ var handle = view . model ;
718
+ // Attach angular-bootstrap-ui tooltip to handles
724
719
725
- // Attach angular-bootstrap-ui tooltip to handles
720
+ // For some reason angular-bootstrap-ui 0.13.4 tooltip app doesn't detect mouseleave for handles
721
+ // Therefore we track mouselave (or mouseout in Joint JS terms) and hide tooltip ourselves
722
+ var scope = $rootScope . $new ( true ) ;
723
+ scope . disabled = false ;
726
724
727
- // For some reason angular-bootstrap-ui 0.13.4 tooltip app doesn't detect mouseleave for handles
728
- // Therefore we track mouselave (or mouseout in Joint JS terms) and hide tooltip ourselves
729
- var scope = $rootScope . $new ( true ) ;
725
+ // Enable tooltip when the mouse is over the shape
726
+ view . on ( 'cell:mouseover' , function ( ) {
727
+ // Enable tooltip
730
728
scope . disabled = false ;
729
+ // Occurs outside of angular digest cycle, so trigger angular listeners update
730
+ scope . $digest ( ) ;
731
+ } ) ;
731
732
732
- // Enable tooltip when the mouse is over the shape
733
- view . on ( 'cell:mouseover' , function ( ) {
734
- // Enable tooltip
735
- scope . disabled = false ;
736
- // Occurs outside of angular digest cycle, so trigger angular listeners update
737
- scope . $digest ( ) ;
738
- } ) ;
739
-
740
- // Hide tooltip if mouse pointer has left the shape. Angular 0.13.4 fails to detect it for handles properly :-(
741
- view . on ( 'cell:mouseout' , function ( ) {
742
- // Disable tooltip
743
- scope . disabled = true ;
744
- // Occurs outside of angular digest cycle, so trigger angular listeners update
745
- scope . $digest ( ) ;
746
- } ) ;
733
+ // Hide tooltip if mouse pointer has left the shape. Angular 0.13.4 fails to detect it for handles properly :-(
734
+ view . on ( 'cell:mouseout' , function ( ) {
735
+ // Disable tooltip
736
+ scope . disabled = true ;
737
+ // Occurs outside of angular digest cycle, so trigger angular listeners update
738
+ scope . $digest ( ) ;
739
+ } ) ;
747
740
748
- // Hide tooltip if handle has been clicked.
749
- // The 'cell:pointerup' event is important! None of the others work properly
750
- view . on ( 'cell:pointerup' , function ( ) {
751
- // Disable tooltip
752
- scope . disabled = true ;
753
- // Occurs outside of angular digest cycle, so trigger angular listeners update
754
- scope . $digest ( ) ;
755
- } ) ;
741
+ // Hide tooltip if handle has been clicked.
742
+ // The 'cell:pointerup' event is important! None of the others work properly
743
+ view . on ( 'cell:pointerup' , function ( ) {
744
+ // Disable tooltip
745
+ scope . disabled = true ;
746
+ // Occurs outside of angular digest cycle, so trigger angular listeners update
747
+ scope . $digest ( ) ;
748
+ } ) ;
756
749
757
- if ( handle . attr ( './kind' ) === 'remove' ) {
758
- attachBootstrapTextTooltip ( view . el , scope , 'Remove Element' , 'bottom' , 500 ) ;
759
- // All DOM modifications should be in place now. Let angular compile the DOM element to fuse scope and HTML
760
- $compile ( view . el ) ( scope ) ;
761
- } else if ( handle . attr ( './kind' ) === 'properties' ) {
762
- attachBootstrapTextTooltip ( view . el , scope , 'Edit Properties' , 'bottom' , 500 ) ;
763
- // All DOM modifications should be in place now. Let angular compile the DOM element to fuse scope and HTML
764
- $compile ( view . el ) ( scope ) ;
765
- }
750
+ if ( handle . attr ( './kind' ) === 'remove' ) {
751
+ attachBootstrapTextTooltip ( view . el , scope , 'Remove Element' , 'bottom' , 500 ) ;
752
+ // All DOM modifications should be in place now. Let angular compile the DOM element to fuse scope and HTML
753
+ $compile ( view . el ) ( scope ) ;
754
+ } else if ( handle . attr ( './kind' ) === 'properties' ) {
755
+ attachBootstrapTextTooltip ( view . el , scope , 'Edit Properties' , 'bottom' , 500 ) ;
756
+ // All DOM modifications should be in place now. Let angular compile the DOM element to fuse scope and HTML
757
+ $compile ( view . el ) ( scope ) ;
766
758
}
767
759
}
768
760
@@ -808,6 +800,26 @@ define(function(require) {
808
800
} ) ;
809
801
}
810
802
803
+ function getNodeView ( ) {
804
+ return joint . dia . ElementView . extend ( {
805
+ options : joint . util . deepSupplement ( {
806
+ } , joint . dia . ElementView . prototype . options ) ,
807
+
808
+ render : function ( ) {
809
+ joint . dia . ElementView . prototype . render . apply ( this , arguments ) ;
810
+ var type = this . model . get ( 'type' ) ;
811
+ if ( type === joint . shapes . flo . NODE_TYPE ) {
812
+ initializeNewNode ( this ) ;
813
+ } else if ( type === joint . shapes . flo . DECORATION_TYPE ) {
814
+ initializeNewDecoration ( this ) ;
815
+ } else if ( type === joint . shapes . flo . HANDLE_TYPE ) {
816
+ initializeNewHandle ( this ) ;
817
+ }
818
+ }
819
+
820
+ } ) ;
821
+ }
822
+
811
823
function handleLinkSourceChanged ( link , paper ) {
812
824
var graph = paper . model ;
813
825
var newSourceId = link . get ( 'source' ) . id ;
@@ -979,10 +991,8 @@ define(function(require) {
979
991
'createLink' : createLink ,
980
992
'createHandle' : createHandle ,
981
993
'createDecoration' : createDecoration ,
982
- 'initializeNewNode' : initializeNewNode ,
983
- 'initializeNewDecoration' : initializeNewDecoration ,
984
- 'initializeNewHandle' : initializeNewHandle ,
985
994
'getLinkView' : getLinkView ,
995
+ 'getNodeView' : getNodeView ,
986
996
'layout' : layout ,
987
997
'initializeNewLink' : initializeNewLink ,
988
998
'handleLinkEvent' : handleLinkEvent ,
0 commit comments