Skip to content

Instantly share code, notes, and snippets.

@L3au
Last active April 20, 2017 07:38
Show Gist options
  • Save L3au/5d2c921eba04c4013ebb3354be8f6dee to your computer and use it in GitHub Desktop.
Save L3au/5d2c921eba04c4013ebb3354be8f6dee to your computer and use it in GitHub Desktop.
pages/item/index.js
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