@@ -150,7 +150,7 @@ Node.prototype.drop = function() {
150150 }
151151
152152 if ( ! this . isRoot ( ) ) {
153- this . parent . _dropNode ( this ) ;
153+ this . parent . _removeNode ( this ) ;
154154 this . parent = null ;
155155 }
156156} ;
@@ -163,8 +163,8 @@ Node.prototype.drop = function() {
163163Node . prototype . moveAfter = function ( node ) {
164164 if ( this . isRoot ( ) ) return ;
165165
166- this . parent . _dropNode ( this ) ;
167- node . parent . _addNode ( this , node . getPos ( ) + 1 ) ;
166+ this . _move ( node . parent , node . getPos ( ) + 1 ) ;
167+
168168 return this ;
169169} ;
170170
@@ -179,9 +179,9 @@ Node.prototype.moveAtBegin = function(target) {
179179 if ( target === undefined ) {
180180 target = this . parent ;
181181 }
182-
183- this . parent . _dropNode ( this ) ;
184- target . _addNode ( this , 0 ) ;
182+
183+ this . _move ( target , 0 ) ;
184+
185185 return this ;
186186} ;
187187
@@ -196,12 +196,26 @@ Node.prototype.moveAtEnd = function(target) {
196196 if ( target === undefined ) {
197197 target = this . parent ;
198198 }
199-
200- this . parent . _dropNode ( this ) ;
201- target . _addNode ( this , target . length ( ) ) ;
199+
200+ this . _move ( target , target . length ( ) ) ;
201+
202202 return this ;
203203} ;
204204
205+ /**
206+ * Move itself at specific position of Group
207+ * @param {Group }
208+ * @param {int }
209+ */
210+ Node . prototype . _move = function ( group , index ) {
211+ this . parent . _removeNode ( this ) ;
212+ group . _appendNode ( this , index , false ) ;
213+
214+ if ( this . model !== null ) {
215+ this . model . trigger ( 'move' , this , group , index ) ;
216+ }
217+ } ;
218+
205219
206220// GROUP CLASS
207221// ===============================
@@ -256,17 +270,18 @@ Group.prototype.length = function() {
256270 * Add a Node at specified index
257271 * @param {Node }
258272 * @param {int,optional }
273+ * @param {boolean,optional }
259274 * @return {Node } the inserted node
260275 */
261- Group . prototype . _addNode = function ( node , index ) {
276+ Group . prototype . _appendNode = function ( node , index , trigger ) {
262277 if ( index === undefined ) {
263278 index = this . length ( ) ;
264279 }
265280
266281 this . rules . splice ( index , 0 , node ) ;
267282 node . parent = this ;
268283
269- if ( this . model !== null ) {
284+ if ( trigger && this . model !== null ) {
270285 this . model . trigger ( 'add' , node , index ) ;
271286 }
272287
@@ -280,7 +295,7 @@ Group.prototype._addNode = function(node, index) {
280295 * @return {Group } the inserted group
281296 */
282297Group . prototype . addGroup = function ( $el , index ) {
283- return this . _addNode ( new Group ( this , $el ) , index ) ;
298+ return this . _appendNode ( new Group ( this , $el ) , index , true ) ;
284299} ;
285300
286301/**
@@ -290,15 +305,15 @@ Group.prototype.addGroup = function($el, index) {
290305 * @return {Rule } the inserted rule
291306 */
292307Group . prototype . addRule = function ( $el , index ) {
293- return this . _addNode ( new Rule ( this , $el ) , index ) ;
308+ return this . _appendNode ( new Rule ( this , $el ) , index , true ) ;
294309} ;
295310
296311/**
297312 * Delete a specific Node
298313 * @param {Node }
299314 * @return {Group } self
300315 */
301- Group . prototype . _dropNode = function ( node ) {
316+ Group . prototype . _removeNode = function ( node ) {
302317 var index = this . getNodePos ( node ) ;
303318 if ( index !== - 1 ) {
304319 node . parent = null ;
0 commit comments