-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
c321c7b
commit 3927a5c
Showing
11 changed files
with
329 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
declare const wp: any; | ||
|
||
class Image implements Field { | ||
imageContainer: HTMLElement|null; | ||
image: HTMLInputElement|null; | ||
button: HTMLButtonElement|null; | ||
constructor(private overlayInstance: OverlayInterface) { | ||
this.imageContainer = this.overlayInstance.getOverlay()?.querySelector('[data-js-field-edit-image]') ?? null; | ||
this.button = this.getContainer()?.querySelector('[data-js-field-edit-image-button]') ?? null; | ||
this.image = this.getContainer()?.querySelector('input') ?? null; | ||
this.setButtonListener(); | ||
} | ||
|
||
private setButtonListener(): void { | ||
this.button?.addEventListener('click', () => { | ||
if (!wp) { | ||
return; | ||
} | ||
|
||
const mediaUploader = wp.media({ | ||
title: 'Select Image', | ||
button: { | ||
text: 'Use this image' | ||
}, | ||
multiple: false | ||
}); | ||
|
||
mediaUploader.on('select', () => { | ||
const imageUrl = mediaUploader.state().get('selection').first().toJSON().url; | ||
this.setValue(imageUrl); | ||
}); | ||
|
||
mediaUploader.open(); | ||
}); | ||
} | ||
|
||
public getContainer(): HTMLElement|null { | ||
return this.imageContainer; | ||
} | ||
|
||
public getField(): HTMLInputElement|null { | ||
return this.image; | ||
} | ||
|
||
public setValue(value: string): void { | ||
if (!this.getField()) { | ||
return; | ||
} | ||
|
||
this.getField()!.value = value; | ||
} | ||
|
||
public getValue(): string { | ||
if (!this.getField()) { | ||
return ''; | ||
} | ||
|
||
return this.getField()!.value; | ||
} | ||
|
||
public showField(): void { | ||
if (!this.getContainer()) { | ||
return; | ||
} | ||
|
||
this.getContainer()!.classList.add('is-visible'); | ||
} | ||
|
||
public hideField(): void { | ||
if (!this.getContainer()) { | ||
return; | ||
} | ||
|
||
this.getContainer()!.classList.remove('is-visible'); | ||
} | ||
} | ||
|
||
export default Image; |
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
73 changes: 73 additions & 0 deletions
73
source/js/options/createImageOverlay/edit/editImageOverlayData.ts
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,73 @@ | ||
class EditImageOverlayData implements EditImageOverlayDataInterface, Editable { | ||
constructor( | ||
private imageOverlayData: ImageOverlayDataInterface, | ||
private editInstance: EditInterface, | ||
private overlayInstance: OverlayInterface, | ||
private titleInstance: Field, | ||
private layerInstance: Field, | ||
private imageInstance: Field | ||
) { | ||
// this.option = document.createElement('option'); | ||
// this.option.value = this.imageOverlayData.getId(); | ||
// this.layerInstance.getField()?.appendChild(this.option); | ||
} | ||
|
||
public edit(): void { | ||
this.editInstance.setActiveEditable(this); | ||
this.showFields(); | ||
} | ||
|
||
private setDefaultFieldValues(): void { | ||
// this.titleInstance.setValue(this.imageOverlayData.getTitle()); | ||
// this.colorInstance.setValue(this.imageOverlayData.getColor()); | ||
// this.layerInstance.setValue(this.imageOverlayData.getLayerGroup()); | ||
// this.iconInstance.setValue(this.imageOverlayData.getIcon()); | ||
} | ||
|
||
public save() { | ||
// if (this.imageOverlayData.getId() === this.layerInstance.getValue()) { | ||
// alert('Cannot set the layer group to itself'); | ||
// return; | ||
// } | ||
|
||
// this.imageOverlayData.setTitle(this.titleInstance.getValue()); | ||
// this.imageOverlayData.setColor(this.colorInstance.getValue()); | ||
// this.imageOverlayData.setLayerGroup(this.layerInstance.getValue()); | ||
// this.imageOverlayData.setIcon(this.iconInstance.getValue()); | ||
// this.imageOverlayData.updateLayerGroup(); | ||
// this.editInstance.setActiveEditable(null); | ||
// this.hideFields(); | ||
} | ||
|
||
public setOptionTitle(title: string) { | ||
// this.option.text = this.imageOverlayData.getTitle(); | ||
} | ||
|
||
public cancel() { | ||
// this.editInstance.setActiveEditable(null); | ||
// this.hideFields(); | ||
} | ||
|
||
public delete() { | ||
// this.imageOverlayData.deleteLayerGroup(); | ||
// this.editInstance.setActiveEditable(null); | ||
// this.option.remove(); | ||
// this.hideFields(); | ||
} | ||
|
||
public showFields() { | ||
this.layerInstance.showField(); | ||
this.titleInstance.showField(); | ||
this.imageInstance.showField(); | ||
this.overlayInstance.showOverlay(); | ||
} | ||
|
||
public hideFields() { | ||
this.layerInstance.hideField(); | ||
this.titleInstance.hideField(); | ||
this.imageInstance.hideField(); | ||
this.overlayInstance.hideOverlay(); | ||
} | ||
} | ||
|
||
export default EditImageOverlayData; |
25 changes: 25 additions & 0 deletions
25
source/js/options/createImageOverlay/edit/editImageOverlayDataFactory.ts
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,25 @@ | ||
import EditImageOverlayData from "./editImageOverlayData"; | ||
|
||
class EditImageOverlayFactory { | ||
constructor( | ||
private editInstance: EditInterface, | ||
private overlayInstance: OverlayInterface, | ||
private titleInstance: Field, | ||
private layerInstance: Field, | ||
private imageInstance: Field | ||
) { | ||
} | ||
|
||
public create(imageOverlayDataInstance: ImageOverlayDataInterface): EditImageOverlayDataInterface { | ||
return new EditImageOverlayData( | ||
imageOverlayDataInstance, | ||
this.editInstance, | ||
this.overlayInstance, | ||
this.titleInstance, | ||
this.layerInstance, | ||
this.imageInstance | ||
); | ||
} | ||
} | ||
|
||
export default EditImageOverlayFactory; |
3 changes: 3 additions & 0 deletions
3
source/js/options/createImageOverlay/edit/editImageOverlayDataInterface.d.ts
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,3 @@ | ||
interface EditImageOverlayDataInterface { | ||
edit(): void; | ||
} |
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,37 @@ | ||
import { CreateImageOverlayInterface } from "../../../OpenStreetMap/js/features/createImageOverlay/createImageOverlayInterface"; | ||
import { CreateRectangleInterface } from "../../../OpenStreetMap/js/features/createRectangle/createRectangleInterface"; | ||
import { MapInterface } from "../../../OpenStreetMap/js/mapInterface"; | ||
import EditImageOverlayFactory from "./edit/editImageOverlayDataFactory"; | ||
|
||
class ImageOverlayData implements ImageOverlayDataInterface { | ||
private editor: EditImageOverlayDataInterface; | ||
constructor( | ||
private mapInstance: MapInterface, | ||
private createImageOverlayInstance: CreateImageOverlayInterface, | ||
private createRectangle: CreateRectangleInterface, | ||
private editImageOverlayFactoryInstance: EditImageOverlayFactory | ||
) { | ||
this.editor = this.editImageOverlayFactoryInstance.create(this); | ||
} | ||
|
||
public createImageOverlay(): void {} | ||
public editImageOverlay(): void { | ||
this.editor.edit(); | ||
} | ||
|
||
public setTitle(title: string): void {} | ||
public getTitle(): string { | ||
return ''; | ||
} | ||
public getLayerGroup(): string { | ||
return ''; | ||
} | ||
public setLayerGroup(layerGroup: string): void {} | ||
public updateImageOverlay(): void {} | ||
public deleteImageOverlay(): void {} | ||
public getId(): string { | ||
return ''; | ||
} | ||
} | ||
|
||
export default ImageOverlayData; |
11 changes: 11 additions & 0 deletions
11
source/js/options/createImageOverlay/imageOverlayDataInterface.d.ts
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,11 @@ | ||
interface ImageOverlayDataInterface { | ||
createImageOverlay(): void; | ||
editImageOverlay(): void; | ||
getId(): string; | ||
setTitle(title: string): void; | ||
getTitle(): string; | ||
getLayerGroup(): string; | ||
setLayerGroup(layerGroup: string): void; | ||
updateImageOverlay(): void; | ||
deleteImageOverlay(): void; | ||
} |
26 changes: 26 additions & 0 deletions
26
source/js/options/createImageOverlay/imageOverlayFactory.ts
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,26 @@ | ||
import { CreateImageOverlayInterface } from "../../../OpenStreetMap/js/features/createImageOverlay/createImageOverlayInterface"; | ||
import { CreateRectangleInterface } from "../../../OpenStreetMap/js/features/createRectangle/createRectangleInterface"; | ||
import { MapInterface } from "../../../OpenStreetMap/js/mapInterface"; | ||
import EditImageOverlayFactory from "./edit/editImageOverlayDataFactory"; | ||
import ImageOverlayData from "./imageOverlayData"; | ||
|
||
class ImageOverlayFactory implements ImageOverlayFactoryInterface { | ||
constructor( | ||
private mapInstance: MapInterface, | ||
private createImageOverlayInstance: CreateImageOverlayInterface, | ||
private createRectangle: CreateRectangleInterface, | ||
private editImageOverlayFactoryInstance: EditImageOverlayFactory, | ||
) { | ||
|
||
} | ||
public create(): ImageOverlayDataInterface { | ||
return new ImageOverlayData( | ||
this.mapInstance, | ||
this.createImageOverlayInstance, | ||
this.createRectangle, | ||
this.editImageOverlayFactoryInstance, | ||
); | ||
} | ||
} | ||
|
||
export default ImageOverlayFactory; |
3 changes: 3 additions & 0 deletions
3
source/js/options/createImageOverlay/imageOverlayFactoryInterface.d.ts
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,3 @@ | ||
interface ImageOverlayFactoryInterface { | ||
create(): ImageOverlayDataInterface; | ||
} |
28 changes: 28 additions & 0 deletions
28
source/js/options/createImageOverlay/optionCreateImageOverlay.ts
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,28 @@ | ||
class OptionCreateImageOverlay implements OptionFeature { | ||
protected condition: string = 'create_image_overlay'; | ||
|
||
constructor( | ||
private container: HTMLElement, | ||
private handleSelectedInstance: HandleSelectedInterface, | ||
private imageOverlayFactoryInstance: ImageOverlayFactoryInterface | ||
) { | ||
this.addListener(); | ||
} | ||
|
||
private addListener(): void { | ||
|
||
this.container.querySelector(`[data-js-value="${this.condition}"]`)?.addEventListener('click', (e) => { | ||
e.preventDefault(); | ||
const imageOverlayData = this.imageOverlayFactoryInstance.create(); | ||
imageOverlayData.editImageOverlay(); | ||
|
||
this.handleSelectedInstance.clearSelected(); | ||
}); | ||
} | ||
|
||
public checkCondition(value: string): boolean { | ||
return value === this.condition; | ||
} | ||
} | ||
|
||
export default OptionCreateImageOverlay; |
Oops, something went wrong.