Skip to content
Toggle navigation
Toggle navigation
This project
Loading...
Sign in
brainfood
/
solr-frontend
Go to a project
Toggle navigation
Toggle navigation pinning
Projects
Groups
Snippets
Help
Project
Activity
Repository
Graphs
Network
Create a new issue
Commits
Issue Boards
Files
Commits
Network
Compare
Branches
Tags
bd7f86a9
authored
2016-02-09 12:24:21 -0600
by
Adam Heath
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
Move preventDefault and stepFalse into Util.
1 parent
49158a45
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
49 additions
and
14 deletions
src/scripts/solr/model/Pagination.js
src/scripts/solr/model/Util.js
src/scripts/solr/model/Util.spec.js
src/scripts/solr/model/Pagination.js
View file @
bd7f86a
define
(
function
(
require
)
{
'use strict'
;
var
Backbone
=
require
(
'backbone'
);
var
Util
=
require
(
'./Util'
);
function
preventDefault
(
e
)
{
if
(
e
)
{
e
.
preventDefault
();
}
}
function
stepFalse
(
e
)
{
preventDefault
(
e
);
return
false
;
}
var
Pagination
=
Backbone
.
Model
.
extend
({
defaults
:
function
defaults
()
{
return
{
...
...
@@ -120,21 +112,21 @@ define(function(require) {
var
next
,
previous
;
if
(
hasNext
)
{
next
=
_
.
bind
(
function
(
e
)
{
preventDefault
(
e
);
Util
.
preventDefault
(
e
);
this
.
set
(
'currentPage'
,
this
.
get
(
'currentPage'
)
+
pageCount
);
return
false
;
},
this
);
}
else
{
next
=
stepFalse
;
next
=
Util
.
stepFalse
;
}
if
(
hasPrevious
)
{
previous
=
_
.
bind
(
function
(
e
)
{
preventDefault
(
e
);
Util
.
preventDefault
(
e
);
this
.
set
(
'currentPage'
,
this
.
get
(
'currentPage'
)
-
pageCount
);
return
false
;
},
this
);
}
else
{
previous
=
stepFalse
;
previous
=
Util
.
stepFalse
;
}
this
.
set
(
nextName
,
next
);
this
.
set
(
previousName
,
previous
);
...
...
src/scripts/solr/model/Util.js
View file @
bd7f86a
...
...
@@ -14,7 +14,17 @@ define(function(require) {
return
result
;
}
function
preventDefault
(
e
)
{
if
(
e
)
{
e
.
preventDefault
();
}
}
return
{
preventDefault
:
preventDefault
,
stepFalse
:
function
stepFalse
(
e
)
{
preventDefault
(
e
);
return
false
;
},
getField
:
function
getField
(
obj
,
key
)
{
return
obj
[
key
];
},
...
...
src/scripts/solr/model/Util.spec.js
View file @
bd7f86a
...
...
@@ -33,6 +33,8 @@ define(function(require) {
keys
[
key
]
=
true
;
});
expect
(
keys
).
toEqual
({
preventDefault
:
true
,
stepFalse
:
true
,
getField
:
true
,
setField
:
true
,
getItemKeyAccessor
:
true
,
...
...
@@ -41,11 +43,42 @@ define(function(require) {
});
});
describe
(
'methods'
,
function
()
{
var
pojo
,
bb
,
emptyBB
;
var
e
,
pojo
,
bb
,
emptyBB
;
beforeEach
(
function
()
{
pojo
=
{
a
:
1
,
b
:
2
,
key
:
'TheKey'
};
bb
=
new
BaseModel
(
pojo
);
emptyBB
=
new
SubModel
();
e
=
{
preventDefault
:
jasmine
.
createSpy
(
'preventDefault'
)};
});
it
(
'preventDefault(null)'
,
function
()
{
var
r
=
Util
.
preventDefault
(
null
);
expect
(
r
).
toBe
(
undefined
);
expect
(
e
.
preventDefault
).
not
.
toHaveBeenCalled
();
});
it
(
'preventDefault(undefined)'
,
function
()
{
var
r
=
Util
.
preventDefault
(
undefined
);
expect
(
r
).
toBe
(
undefined
);
expect
(
e
.
preventDefault
).
not
.
toHaveBeenCalled
();
});
it
(
'preventDefault(e)'
,
function
()
{
var
r
=
Util
.
preventDefault
(
e
);
expect
(
r
).
toBe
(
undefined
);
expect
(
e
.
preventDefault
).
toHaveBeenCalled
();
});
it
(
'stepFalse(null)'
,
function
()
{
var
r
=
Util
.
stepFalse
(
null
);
expect
(
r
).
toBe
(
false
);
expect
(
e
.
preventDefault
).
not
.
toHaveBeenCalled
();
});
it
(
'stepFalse(undefined)'
,
function
()
{
var
r
=
Util
.
stepFalse
(
undefined
);
expect
(
r
).
toBe
(
false
);
expect
(
e
.
preventDefault
).
not
.
toHaveBeenCalled
();
});
it
(
'preventDefault(e)'
,
function
()
{
var
r
=
Util
.
stepFalse
(
e
);
expect
(
r
).
toBe
(
false
);
expect
(
e
.
preventDefault
).
toHaveBeenCalled
();
});
it
(
'setField only modifies given'
,
function
()
{
var
r
=
Util
.
setField
(
pojo
,
'a'
,
100
);
...
...
Please
register
or
sign in
to post a comment