Skip to content

Commit

Permalink
Working on emoji window, managed to make a template
Browse files Browse the repository at this point in the history
  • Loading branch information
unimonkiez committed Apr 13, 2016
1 parent 2b484ec commit 6308779
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 13 deletions.
2 changes: 1 addition & 1 deletion .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@
"no-trailing-spaces": 2,
"no-underscore-dangle": 0,
"no-unneeded-ternary": 2,
"object-curly-spacing": [2, "never"],
"object-curly-spacing": [2, "always"],
"one-var": 0,
"operator-assignment": 0,
"operator-linebreak": [2, "after"],
Expand Down
69 changes: 58 additions & 11 deletions src/emoji-window.js
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;
1 change: 0 additions & 1 deletion webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ module.exports = {
preLoaders: [
{
test: /\.json$/,
exclude: /node_modules/,
loader: 'json'
}
],
Expand Down

0 comments on commit 6308779

Please sign in to comment.