FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
Backbone.JS-Example/js/editor.js at master · ianqueue/Backbone.JS-Example · GitHub
ianqueue
/
Backbone.JS-Example
Public
Notifications
You must be signed in to change notification settings
Fork
0
Star
1
Code
Issues
0
Pull requests
0
Actions
Projects
Wiki
Security and quality
0
Insights
Additional navigation options
Code
Issues
Pull requests
Actions
Projects
Wiki
Security and quality
Insights
Expand file tree
Breadcrumbs
Backbone.JS-Example
/
js
/
editor.js
Copy path
More file actions
More file actions
Latest commit
History
History
History
160 lines (115 loc) · 4.64 KB
Breadcrumbs
Backbone.JS-Example
/
js
/
editor.js
Copy path
File metadata and controls
160 lines (115 loc) · 4.64 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
// load the application once the DOM is ready
$
(
function
(
)
{
// -- Question Collection (History)
var
questionHistory
=
new
(
Backbone
.
Collection
.
extend
(
{
model
:
Question
,
// a collection of question Model objects
initialize
:
function
(
)
{
this
.
records
=
this
.
localStorage
.
records
;
this
.
bind
(
'add'
,
function
(
)
{
console
.
dir
(
this
.
localStorage
.
findAll
(
)
)
;
console
.
log
(
this
.
localStorage
)
;
}
,
this
)
;
}
,
localStorage
:
new
Store
(
'questionHistory'
)
,
// our localStorage object reference
// grab the current question object or the nth order question in the queue
getCurrent
:
function
(
order
)
{
if
(
order
)
{
return
this
.
localStorage
.
findAll
(
)
[
order
-
1
]
;
}
else
{
var
allQuestions
=
this
.
localStorage
.
findAll
(
)
;
return
(
this
.
current
)
?
this
.
current
:
allQuestions
[
allQuestions
.
length
-
1
]
;
}
}
,
// get the next order number in the collection history
nextOrder
:
function
(
)
{
if
(
!
this
.
records
.
length
)
return
0
;
return
this
.
records
.
length
;
}
,
// get the previous question model to the current question in the collection
previous
:
function
(
question
)
{
this
.
current
=
this
.
localStorage
.
findAll
(
)
[
question
.
order
-
1
]
;
return
this
.
current
;
}
}
)
)
;
// -- Question Model
var
Question
=
new
Backbone
.
Model
.
extend
(
{
// default attributes for a question content item
defaults
:
function
(
)
{
return
{
text
:
''
,
order
:
questionHistory
.
nextOrder
(
)
}
;
}
}
)
;
// -- Editor View
var
EditorView
=
new
(
Backbone
.
View
.
extend
(
{
el
:
$
(
"#questionEditor"
)
,
// common practice to tie a Backbone.View to an el (how the widget comes together)
collection
:
questionHistory
,
// tie in our collection for reference
//
template
:
function
(
data
)
{
return
Mustache
.
render
(
$
(
'#question-template'
)
.
html
(
)
,
data
)
;
}
,
//
events
:
{
'click .store-question'
:
'storeQuestion'
,
'keyup #editor-input'
:
'showTooltip'
,
'click .previous-question'
:
'renderPrevious'
}
,
//
initialize
:
function
(
)
{
this
.
input
=
this
.
$
(
"#editor-input"
)
;
this
.
collection
.
bind
(
'add'
,
this
.
renderCurrent
,
this
)
;
}
,
renderCurrent
:
function
(
order
)
{
//console.log('Backbone.View.renderCurrent()');
if
(
$
.
type
(
order
)
===
'string'
)
{
var
currentQuestion
=
questionHistory
.
getCurrent
(
order
)
;
}
else
{
var
currentQuestion
=
questionHistory
.
getCurrent
(
)
;
}
$
(
'#questionContent'
)
.
html
(
this
.
template
(
currentQuestion
)
)
;
}
,
renderPrevious
:
function
(
)
{
//console.log('renderPrevious()');
var
currentQuestion
=
questionHistory
.
getCurrent
(
)
;
var
previousQuestion
=
questionHistory
.
previous
(
currentQuestion
)
;
$
(
'#questionContent'
)
.
html
(
this
.
template
(
previousQuestion
)
)
;
}
,
//
storeQuestion
:
function
(
)
{
//console.log('Backbone.View.storeQuestion()');
var
text
=
this
.
input
.
val
(
)
;
if
(
!
text
)
return
;
questionHistory
.
create
(
{
text
:
text
,
order
:
questionHistory
.
nextOrder
(
)
}
)
;
}
,
//
showTooltip
:
function
(
e
)
{
/*
var tooltip = $(".ui-tooltip-top");
var val = this.input.val();
tooltip.fadeOut();
if (this.tooltipTimeout) {
clearTimeout(this.tooltipTimeout);
}
if (val == '' || val == this.input.attr('placeholder')) return;
var show = function() {
tooltip.show().fadeIn();
};
this.tooltipTimeout = _.delay(show, 1000);
*/
}
}
)
)
;
// -- Editor Router
var
EditorRouter
=
new
(
Backbone
.
Router
.
extend
(
{
routes
:
{
'editor'
:
'editor'
,
// #editor // event: 'route:editor'
'editor/v:version'
:
'editor'
// #editor/v7 // event: 'route:editor'
}
,
// /editor and /editor/v# routes call render in the view
editor
:
function
(
version
)
{
EditorView
.
renderCurrent
(
version
)
;
}
}
)
)
;
// start monitoring hashchange events & dispatching routes
Backbone
.
history
.
start
(
)
;
}
)
;
Back
|
FazBrowse Home
|
New Git URL