Skip to content
This repository was archived by the owner on Dec 4, 2017. It is now read-only.

Commit 5d376c7

Browse files
committed
docs(cookbook - jquery plugins)
tweak ignore fix array core shim e2e Jesus' edits s s
1 parent e0aecb3 commit 5d376c7

File tree

16 files changed

+330
-0
lines changed

16 files changed

+330
-0
lines changed
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
'use strict';
2+
3+
import { browser, element, by } from 'protractor';
4+
5+
/* tslint:disable:quotemark */
6+
describe('Drag and Drop', function () {
7+
8+
beforeAll(function () {
9+
browser.get('');
10+
});
11+
12+
it('should drag hero to assignment', function () {
13+
14+
let assignment1 = element.all(by.css('.assignment')).get(0);
15+
16+
let hero1 = element.all(by.css('.hero')).get(0);
17+
18+
browser.actions()
19+
.dragAndDrop(hero1 as any as webdriver.WebElement,
20+
assignment1 as any as webdriver.WebElement)
21+
.perform();
22+
23+
let heroAssignment = element.all(by.xpath('//div[text()="Help Granny cross the street"]/following-sibling::ul/li[text()="Mr. Nice"]'));
24+
expect(heroAssignment.count()).toBe(1);
25+
26+
let doneButton = element(by.xpath('//div[@data-hero="Mr. Nice"]/div/button'));
27+
28+
// Remove Mr. Nice
29+
doneButton.click().then(function(){
30+
let remainingHeroes = element.all(by.css('.hero'));
31+
expect(remainingHeroes.count()).toBe(3);
32+
});
33+
});
34+
});
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
**/*.js
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
// #docregion
2+
import { Component } from '@angular/core';
3+
4+
@Component({
5+
selector: 'my-app',
6+
template: `
7+
<div id="hero-wrapper">
8+
<h2>Hero Assignments</h2>
9+
<div *ngFor="let assignment of assignments">
10+
<cb-assignment [title]="assignment"></cb-assignment>
11+
</div>
12+
<div class="heroList">
13+
<div *ngFor="let hero of heroes">
14+
<cb-hero (remove)="removeHero($event)" [name]="hero"></cb-hero>
15+
</div>
16+
</div>
17+
</div>
18+
`
19+
})
20+
export class AppComponent {
21+
heroes = ['Mr. Nice',
22+
'Bombasto',
23+
'Celeritas',
24+
'Tornado'];
25+
26+
assignments = ['Help Granny cross the street',
27+
'Rescue village from dragon(s)',
28+
'Rescue princess from tower'];
29+
30+
removeHero(heroToRemove: string): void {
31+
this.heroes = this.heroes.filter(hero => hero !== heroToRemove);
32+
}
33+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import { NgModule } from '@angular/core';
2+
import { BrowserModule } from '@angular/platform-browser';
3+
4+
import { AppComponent } from './app.component';
5+
import { HeroAssignmentComponent } from './hero-assignment.component';
6+
import { HeroComponent } from './hero.component';
7+
8+
@NgModule({
9+
imports: [ BrowserModule ],
10+
declarations: [ AppComponent, HeroAssignmentComponent, HeroComponent ],
11+
bootstrap: [ AppComponent ]
12+
})
13+
export class AppModule {}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<!-- #docregion -->
2+
<div #assignment class="assignment" [ngClass]="{selected: heroDropped}">
3+
<div>{{title}}</div>
4+
<ul>
5+
<li *ngFor="let hero of assignedHeroes">{{hero}}</li>
6+
</ul>
7+
</div>
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
// #docregion
2+
import { Component, Input, AfterViewInit, ViewChild, ElementRef } from '@angular/core';
3+
4+
declare var jQuery: any;
5+
6+
@Component({
7+
selector: 'cb-assignment',
8+
templateUrl: 'app/hero-assignment.component.html'
9+
})
10+
export class HeroAssignmentComponent implements AfterViewInit {
11+
@Input() title: string;
12+
@ViewChild('assignment') assignment: ElementRef;
13+
14+
assignedHeroes: string[] = [];
15+
16+
// #docregion add-plugin
17+
ngAfterViewInit(): void {
18+
jQuery(this.assignment.nativeElement).droppable({drop : (event: any, ui: any) => {
19+
let heroName = ui.draggable.data('hero');
20+
if (this.assignedHeroes.indexOf(heroName) === -1) {
21+
this.assignedHeroes = [...this.assignedHeroes, heroName];
22+
}
23+
}});
24+
}
25+
// #enddocregion add-plugin
26+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<!-- #docregion -->
2+
<div #hero class="hero" [attr.data-hero]="name">
3+
{{name}}
4+
<div><button (click)="done()">Done</button></div>
5+
</div>
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
// #docregion
2+
import { Component, Input, Output, AfterViewInit, ViewChild, ElementRef, EventEmitter } from '@angular/core';
3+
4+
// #docregion declare-jquery
5+
declare var jQuery: any;
6+
// #enddocregion declare-jquery
7+
@Component({
8+
selector: 'cb-hero',
9+
templateUrl: 'app/hero.component.html'
10+
})
11+
export class HeroComponent implements AfterViewInit {
12+
@Input() name: string;
13+
@Output() remove = new EventEmitter<string>();
14+
@ViewChild('hero') hero: ElementRef;
15+
16+
// #docregion add-plugin
17+
ngAfterViewInit(): void {
18+
jQuery(this.hero.nativeElement).draggable({revert: 'invalid'});
19+
}
20+
// #enddocregion add-plugin
21+
22+
done(): void {
23+
this.remove.emit(this.name);
24+
}
25+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import { platformBrowserDynamic } from '@angular/platform-browser-dynamic';
2+
3+
import { AppModule } from './app.module';
4+
5+
platformBrowserDynamic().bootstrapModule(AppModule);

public/docs/_examples/cb-jquery-plugin/ts/example-config.json

Whitespace-only changes.

0 commit comments

Comments
 (0)