Last active
April 20, 2017 07:38
-
-
Save L3au/5d2c921eba04c4013ebb3354be8f6dee to your computer and use it in GitHub Desktop.
pages/item/index.js
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
import './index.less' | |
import qs from 'querystring' | |
import { throttle } from 'lodash' | |
import Menu from 'compoents/menu' | |
import ItemTpl from './tpl/item.html?tpl' | |
class App { | |
constructor () { | |
this.menu = new Menu() | |
this.init() | |
} | |
init () { | |
this.bindEvents() | |
this.loadItems() | |
} | |
toggleMenu () { | |
this.menu.toggle() | |
} | |
loadItems () { | |
const listEl = $('js-list') | |
$.ajax(url).then((ret) => { | |
listEl.append(ItemTpl.render(ret)) | |
}) | |
} | |
bindEvents () { | |
const el = $(document) | |
const EVENTS = { | |
'.js-mask': { | |
touchmove: (e) => { | |
e.preventDefault() | |
}, | |
click: () => { | |
this.toggleMenu() | |
} | |
}, | |
'.js-load-more': { | |
click: (e) => { | |
const target = $(e.currentTarget) | |
target.parent().remove() | |
this.loadItems() | |
} | |
} | |
} | |
$.each(EVENTS, (selector, events) => { | |
$.each(events, (type, handler) => { | |
el.on(type, selector, handler) | |
}) | |
}) | |
} | |
} | |
new App() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment