Skip to content

Commit

Permalink
Fixed #388
Browse files Browse the repository at this point in the history
  • Loading branch information
Çağatay Çivici committed May 23, 2016
1 parent f51c8f2 commit 1029f8a
Show file tree
Hide file tree
Showing 155 changed files with 467 additions and 544 deletions.
3 changes: 2 additions & 1 deletion components/api/menumodel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ export interface MenuItem {
label?: string;
icon?: string;
command?: (event?: any) => void;
url?: any;
url?: string;
routerLink?: any;
eventEmitter?: EventEmitter<any>;
items?: MenuItem[];
}
28 changes: 10 additions & 18 deletions components/breadcrumb/breadcrumb.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import {Component,Input,OnDestroy,EventEmitter} from '@angular/core';
import {MenuItem} from '../api/menumodel';
import {Location} from '@angular/common';
import {Router} from '@angular/router-deprecated';
import {Router} from '@angular/router';

@Component({
selector: 'p-breadcrumb',
Expand All @@ -11,7 +11,7 @@ import {Router} from '@angular/router-deprecated';
<li class="fa fa-home"></li>
<template ngFor let-item let-end="last" [ngForOf]="model">
<li role="menuitem">
<a [href]="getItemUrl(item)" class="ui-menuitem-link" (click)="itemClick($event, item)">
<a [href]="item.url||'#'" class="ui-menuitem-link" (click)="itemClick($event, item)">
<span class="ui-menuitem-text">{{item.label}}</span>
</a>
</li>
Expand All @@ -29,9 +29,13 @@ export class Breadcrumb implements OnDestroy {

@Input() styleClass: string;

constructor(private router: Router, private location: Location) {}
constructor(private router: Router) {}

itemClick(event, item: MenuItem) {
if(!item.url||item.routerLink) {
event.preventDefault();
}

if(item.command) {
if(!item.eventEmitter) {
item.eventEmitter = new EventEmitter();
Expand All @@ -41,23 +45,11 @@ export class Breadcrumb implements OnDestroy {
item.eventEmitter.emit(event);
}

if(!item.url) {
event.preventDefault();
}
}

getItemUrl(item: MenuItem): string {
if(item.url) {
if(Array.isArray(item.url))
return this.location.prepareExternalUrl(this.router.generate(item.url).toLinkUrl());
else
return item.url;
}
else {
return '#';
if(item.routerLink) {
this.router.navigate(item.routerLink);
}
}

ngOnDestroy() {
if(this.model) {
for(let item of this.model) {
Expand Down
27 changes: 9 additions & 18 deletions components/contextmenu/contextmenu.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import {Component,ElementRef,AfterViewInit,OnDestroy,Input,Output,Renderer,Event
import {DomHandler} from '../dom/domhandler';
import {MenuItem} from '../api/menumodel';
import {Location} from '@angular/common';
import {Router} from '@angular/router-deprecated';
import {Router} from '@angular/router';

@Component({
selector: 'p-contextMenuSub',
Expand All @@ -12,7 +12,7 @@ import {Router} from '@angular/router-deprecated';
<template ngFor let-child [ngForOf]="(root ? item : item.items)">
<li #item [ngClass]="{'ui-menuitem ui-widget ui-corner-all':true,'ui-menu-parent':child.items,'ui-menuitem-active':item==activeItem}"
(mouseenter)="onItemMouseEnter($event, item)" (mouseleave)="onItemMouseLeave($event, item)">
<a #link [href]="getItemUrl(child)" class="ui-menuitem-link ui-corner-all" [ngClass]="{'ui-state-hover':link==activeLink}" (click)="itemClick($event, child)">
<a #link [href]="child.url||'#'" class="ui-menuitem-link ui-corner-all" [ngClass]="{'ui-state-hover':link==activeLink}" (click)="itemClick($event, child)">
<span class="ui-submenu-icon fa fa-fw fa-caret-right" *ngIf="child.items"></span>
<span class="ui-menuitem-icon fa fa-fw" *ngIf="child.icon" [ngClass]="child.icon"></span>
<span class="ui-menuitem-text">{{child.label}}</span>
Expand All @@ -31,7 +31,7 @@ export class ContextMenuSub {

@Input() root: boolean;

constructor(private domHandler: DomHandler, private router: Router, private location: Location) {}
constructor(private domHandler: DomHandler, private router: Router) {}

activeItem: any;

Expand All @@ -56,6 +56,10 @@ export class ContextMenuSub {
}

itemClick(event, item: MenuItem) {
if(!item.url||item.routerLink) {
event.preventDefault();
}

if(item.command) {
if(!item.eventEmitter) {
item.eventEmitter = new EventEmitter();
Expand All @@ -65,28 +69,15 @@ export class ContextMenuSub {
item.eventEmitter.emit(event);
}

if(!item.url) {
event.preventDefault();
if(item.routerLink) {
this.router.navigate(item.routerLink);
}
}

listClick(event) {
this.activeItem = null;
this.activeLink = null;
}

getItemUrl(item: MenuItem): string {
if(item.url) {
if(Array.isArray(item.url))
return this.location.prepareExternalUrl(this.router.generate(item.url).toLinkUrl());
else
return item.url;
}
else {
return '#';
}
}

}

@Component({
Expand Down
27 changes: 9 additions & 18 deletions components/megamenu/megamenu.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import {Component,ElementRef,AfterViewInit,OnDestroy,Input,Output,Renderer,Event
import {DomHandler} from '../dom/domhandler';
import {MenuItem} from '../api/menumodel';
import {Location} from '@angular/common';
import {Router} from '@angular/router-deprecated';
import {Router} from '@angular/router';

@Component({
selector: 'p-megaMenu',
Expand All @@ -27,7 +27,7 @@ import {Router} from '@angular/router-deprecated';
<ul class="ui-menu-list ui-helper-reset">
<li class="ui-widget-header ui-corner-all"><h3>{{submenu.label}}</h3></li>
<li *ngFor="let item of submenu.items" class="ui-menuitem ui-widget ui-corner-all">
<a #link [href]="getItemUrl(item)" class="ui-menuitem-link ui-corner-all" [ngClass]="{'ui-state-hover':link==hoveredItem}"
<a #link [href]="item.url||'#'" class="ui-menuitem-link ui-corner-all" [ngClass]="{'ui-state-hover':link==hoveredItem}"
(mouseenter)="hoveredItem=$event.target" (mouseleave)="hoveredItem=null" (click)="itemClick($event, item)">
<span class="ui-menuitem-icon fa fa-fw" *ngIf="item.icon" [ngClass]="item.icon"></span>
<span class="ui-menuitem-text">{{item.label}}</span>
Expand Down Expand Up @@ -61,7 +61,7 @@ export class MegaMenu implements OnDestroy {

activeLink: any;

constructor(private el: ElementRef, private domHandler: DomHandler, private renderer: Renderer, private router: Router, private location: Location) {}
constructor(private el: ElementRef, private domHandler: DomHandler, private renderer: Renderer, private router: Router) {}

onItemMouseEnter(event, item) {
this.activeItem = item;
Expand All @@ -87,6 +87,10 @@ export class MegaMenu implements OnDestroy {
}

itemClick(event, item: MenuItem) {
if(!item.url||item.routerLink) {
event.preventDefault();
}

if(item.command) {
if(!item.eventEmitter) {
item.eventEmitter = new EventEmitter();
Expand All @@ -96,8 +100,8 @@ export class MegaMenu implements OnDestroy {
item.eventEmitter.emit(event);
}

if(!item.url) {
event.preventDefault();
if(item.routerLink) {
this.router.navigate(item.routerLink);
}

this.activeItem = null;
Expand Down Expand Up @@ -151,17 +155,4 @@ export class MegaMenu implements OnDestroy {

return columnClass;
}

getItemUrl(item: MenuItem): string {
if(item.url) {
if(Array.isArray(item.url))
return this.location.prepareExternalUrl(this.router.generate(item.url).toLinkUrl());
else
return item.url;
}
else {
return '#';
}
}

}
30 changes: 10 additions & 20 deletions components/menu/menu.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import {Component,ElementRef,AfterViewInit,OnDestroy,Input,Output,Renderer,EventEmitter} from '@angular/core';
import {DomHandler} from '../dom/domhandler';
import {MenuItem} from '../api/menumodel';
import {Location} from '@angular/common';
import {Router} from '@angular/router-deprecated';
import {Router} from '@angular/router';

@Component({
selector: 'p-menu',
Expand All @@ -13,7 +12,7 @@ import {Router} from '@angular/router-deprecated';
<template ngFor let-submenu [ngForOf]="model" *ngIf="hasSubMenu()">
<li class="ui-widget-header ui-corner-all"><h3>{{submenu.label}}</h3></li>
<li *ngFor="let item of submenu.items" class="ui-menuitem ui-widget ui-corner-all">
<a #link [href]="getItemUrl(item)" class="ui-menuitem-link ui-corner-all" [ngClass]="{'ui-state-hover':link==hoveredItem}"
<a #link [href]="item.url||'#'" class="ui-menuitem-link ui-corner-all" [ngClass]="{'ui-state-hover':link==hoveredItem}"
(mouseenter)="hoveredItem=$event.target" (mouseleave)="hoveredItem=null" (click)="itemClick($event, item)">
<span class="ui-menuitem-icon fa fa-fw" *ngIf="item.icon" [ngClass]="item.icon"></span>
<span class="ui-menuitem-text">{{item.label}}</span>
Expand All @@ -22,7 +21,7 @@ import {Router} from '@angular/router-deprecated';
</template>
<template ngFor let-item [ngForOf]="model" *ngIf="!hasSubMenu()">
<li class="ui-menuitem ui-widget ui-corner-all">
<a #link [href]="getItemUrl(item)" class="ui-menuitem-link ui-corner-all" [ngClass]="{'ui-state-hover':link==hoveredItem}"
<a #link [href]="item.url||'#'" class="ui-menuitem-link ui-corner-all" [ngClass]="{'ui-state-hover':link==hoveredItem}"
(mouseenter)="hoveredItem=$event.target" (mouseleave)="hoveredItem=null" (click)="itemClick($event, item)">
<span class="ui-menuitem-icon fa fa-fw" *ngIf="item.icon" [ngClass]="item.icon"></span>
<span class="ui-menuitem-text">{{item.label}}</span>
Expand Down Expand Up @@ -50,7 +49,7 @@ export class Menu implements AfterViewInit,OnDestroy {

preventDocumentDefault: any;

constructor(private el: ElementRef, private domHandler: DomHandler, private renderer: Renderer, private router: Router, private location: Location) {}
constructor(private el: ElementRef, private domHandler: DomHandler, private renderer: Renderer, private router: Router) {}

ngAfterViewInit() {
this.container = this.el.nativeElement.children[0];
Expand Down Expand Up @@ -85,6 +84,10 @@ export class Menu implements AfterViewInit,OnDestroy {
}

itemClick(event, item: MenuItem) {
if(!item.url||item.routerLink) {
event.preventDefault();
}

if(item.command) {
if(!item.eventEmitter) {
item.eventEmitter = new EventEmitter();
Expand All @@ -98,8 +101,8 @@ export class Menu implements AfterViewInit,OnDestroy {
this.hide();
}

if(!item.url) {
event.preventDefault();
if(item.routerLink) {
this.router.navigate(item.routerLink);
}
}

Expand Down Expand Up @@ -137,17 +140,4 @@ export class Menu implements AfterViewInit,OnDestroy {
}
}
}

getItemUrl(item: MenuItem): string {
if(item.url) {
if(Array.isArray(item.url))
return this.location.prepareExternalUrl(this.router.generate(item.url).toLinkUrl());
else
return item.url;
}
else {
return '#';
}
}

}
30 changes: 11 additions & 19 deletions components/menubar/menubar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import {Component,ElementRef,AfterViewInit,OnDestroy,Input,Output,Renderer,Event
import {DomHandler} from '../dom/domhandler';
import {MenuItem} from '../api/menumodel';
import {Location} from '@angular/common';
import {Router} from '@angular/router-deprecated';
import {Router} from '@angular/router';

@Component({
selector: 'p-menubarSub',
Expand All @@ -12,7 +12,7 @@ import {Router} from '@angular/router-deprecated';
<template ngFor let-child [ngForOf]="(root ? item : item.items)">
<li #item [ngClass]="{'ui-menuitem ui-widget ui-corner-all':true,'ui-menu-parent':child.items,'ui-menuitem-active':item==activeItem}"
(mouseenter)="onItemMouseEnter($event, item)" (mouseleave)="onItemMouseLeave($event, item)">
<a #link [href]="getItemUrl(child)" class="ui-menuitem-link ui-corner-all" [ngClass]="{'ui-state-hover':link==activeLink}" (click)="itemClick($event, child)">
<a #link [href]="child.url||'#'" class="ui-menuitem-link ui-corner-all" [ngClass]="{'ui-state-hover':link==activeLink}" (click)="itemClick($event, child)">
<span class="ui-submenu-icon fa fa-fw" *ngIf="child.items" [ngClass]="{'fa-caret-down':root,'fa-caret-right':!root}"></span>
<span class="ui-menuitem-icon fa fa-fw" *ngIf="child.icon" [ngClass]="child.icon"></span>
<span class="ui-menuitem-text">{{child.label}}</span>
Expand All @@ -31,7 +31,7 @@ export class MenubarSub {

@Input() root: boolean;

constructor(private domHandler: DomHandler, private router: Router, private location: Location) {}
constructor(private domHandler: DomHandler, private router: Router) {}

activeItem: any;

Expand Down Expand Up @@ -62,6 +62,10 @@ export class MenubarSub {
}

itemClick(event, item: MenuItem) {
if(!item.url||item.routerLink) {
event.preventDefault();
}

if(item.command) {
if(!item.eventEmitter) {
item.eventEmitter = new EventEmitter();
Expand All @@ -70,27 +74,15 @@ export class MenubarSub {

item.eventEmitter.emit(event);
}
if(!item.url) {
event.preventDefault();

if(item.routerLink) {
this.router.navigate(item.routerLink);
}

this.activeItem = null;
this.activeLink = null;
}

getItemUrl(item: MenuItem): string {
if(item.url) {
if(Array.isArray(item.url))
return this.location.prepareExternalUrl(this.router.generate(item.url).toLinkUrl());
else
return item.url;
}
else {
return '#';
}
}


listClick(event) {
this.activeItem = null;
this.activeLink = null;
Expand Down
Loading

0 comments on commit 1029f8a

Please sign in to comment.