-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Working on emoji window, managed to make a template
- Loading branch information
1 parent
2b484ec
commit 6308779
Showing
3 changed files
with
59 additions
and
13 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
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 |
---|---|---|
@@ -1,16 +1,63 @@ | ||
import emojiData from 'emoji-data/emoji.json'; | ||
import { IMAGE_SET } from './constant'; | ||
import getImageSetTemplate from './get-image-set-template'; | ||
|
||
const existingWindowSets = {}; | ||
let existingWindowImageSetsWrapper; | ||
const existingWindowImageSets = {}; | ||
export default class EmojiWindow { | ||
constructor({ | ||
position: { | ||
el, | ||
x, | ||
y | ||
} = {} | ||
static getTopLeft({ | ||
el, x, y | ||
} = {}) { | ||
const left = x !== undefined ? x : (el.offsetLeft + el.clientWidth); | ||
const top = y !== undefined ? y : (el.offsetTop + el.clientHeight); | ||
console.log(emojiData); | ||
if (__DEV__ && el === undefined && (x === undefined || y === undefined)) { | ||
throw new Error('Must provide `position` with `x` and `y`, or `el` to open from.'); | ||
} | ||
let left = x; | ||
let top = y; | ||
if (left === undefined) { | ||
left = el.offsetLeft + el.clientWidth; | ||
} | ||
if (top === undefined) { | ||
top = el.offsetTop + el.clientHeight; | ||
} | ||
return { | ||
left, | ||
top | ||
}; | ||
} | ||
static getWindowImageSetByImageSet(imageSet) { | ||
const existingWindowImageSet = existingWindowImageSets[imageSet]; | ||
// If windowImageSet exists on object, return it, | ||
// If not, create it | ||
// Only one imageSet should be present | ||
return existingWindowImageSet !== undefined ? existingWindowImageSet : EmojiWindow.createWindowImageSet(imageSet); | ||
} | ||
static createWindowImageSet(imageSet) { | ||
const windowImageSet = document.createElement('div'); | ||
existingWindowImageSets[imageSet] = windowImageSet; | ||
|
||
const imageSetTemplate = getImageSetTemplate(imageSet); | ||
windowImageSet.innerHTML = imageSetTemplate; | ||
|
||
const windowImageSetsWrapper = EmojiWindow.getWindowImageSetsWrapper(); | ||
windowImageSetsWrapper.appendChild(windowImageSet); | ||
|
||
return windowImageSet; | ||
} | ||
static getWindowImageSetsWrapper() { | ||
if (existingWindowImageSetsWrapper === undefined) { | ||
existingWindowImageSetsWrapper = document.createElement('div'); | ||
document.body.appendChild(existingWindowImageSetsWrapper); | ||
} | ||
return existingWindowImageSetsWrapper; | ||
} | ||
constructor({ imageSet = IMAGE_SET.APPLE, position } = {}) { | ||
if (__DEV__) { | ||
if (Object.keys(IMAGE_SET).map(key => IMAGE_SET[key]).indexOf(imageSet) === -1) { | ||
throw new Error('`imageSet` should have one of `EmojiWindow.IMAGE_SET` values, got ${imageSet}.'); | ||
} | ||
} | ||
const { left, top } = EmojiWindow.getTopLeft(position); | ||
const windowImageSet = EmojiWindow.getWindowImageSetByImageSet(imageSet); | ||
} | ||
} | ||
// EmojiWindow static properties | ||
EmojiWindow.IMAGE_SET = IMAGE_SET; |
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 |
---|---|---|
|
@@ -43,7 +43,6 @@ module.exports = { | |
preLoaders: [ | ||
{ | ||
test: /\.json$/, | ||
exclude: /node_modules/, | ||
loader: 'json' | ||
} | ||
], | ||
|