This repository was archived by the owner on Jan 9, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.common.coffee
More file actions
54 lines (47 loc) · 1.43 KB
/
app.common.coffee
File metadata and controls
54 lines (47 loc) · 1.43 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# Зависит от:
# jquery
$ = jQuery
window.app ?= {}
(->
# config
app.config ?= {}
app.config.debug = true
app.log = ->
if !app.config.debug
return
# msg = '[jquery.form] ' + Array.prototype.join.call(arguments, '')
if window.console && window.console.log
window.console.log arguments
else if window.opera && window.opera.postError
window.opera.postError arguments
return
# кнопка показать ещё
class app.MoreLoader
# отправляет ?page=X
# ждет json: {'html': 'html block', 'pagination': {'next': 3}}
page_num: 2
constructor: (container, btn, url) ->
@url = url
@$container = $ container
@$btn = $ btn
if !@$container or !@$btn
return
@$btn.on 'click', (ev) =>
ev.preventDefault()
@load()
load: ->
self = @
$.ajax
type: 'get'
url: self.url
data: {page: self.page_num}
dataType: 'json'
success: (data) ->
self.$container.append data.html
if data.pagination.next
self.page_num = data.pagination.next
else
self.$btn.hide()
return
return
)()