-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
TopMenu: Add bead TopMenuSortingBead to give user ability to sort if …
…needed (reference #40)
- Loading branch information
1 parent
d20154e
commit 467731d
Showing
4 changed files
with
67 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
40 changes: 40 additions & 0 deletions
40
...e/src/net/apacheRoyaleTemplatedApp/classes/topMenu/components/beads/TopMenuSortingBead.as
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
package classes.topMenu.components.beads | ||
{ | ||
import org.apache.royale.core.IBead; | ||
import org.apache.royale.core.IStrand; | ||
import classes.topMenu.model.TopMenuVO; | ||
import org.apache.royale.core.Bead; | ||
|
||
public class TopMenuSortingBead extends Bead | ||
{ | ||
public function TopMenuSortingBead() | ||
{ | ||
super(); | ||
} | ||
|
||
override public function set strand(value:IStrand):void | ||
{ | ||
super.strand = value; | ||
} | ||
|
||
public function eq(a:TopMenuVO, b:TopMenuVO):int | ||
{ | ||
// Nodes with children come first | ||
if (a.children.length > 0 && b.children.length == 0) return -1; | ||
if (a.children.length == 0 && b.children.length > 0) return 1; | ||
|
||
// Then sort by label | ||
if (a.label < b.label) return -1; | ||
if (a.label > b.label) return 1; | ||
return 0; | ||
} | ||
|
||
public function sortMenu(menu:Array):void | ||
{ | ||
if (menu && menu.length > 0) | ||
{ | ||
menu.sort(eq); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters