Skip to content
Toggle navigation
Toggle navigation
This project
Loading...
Sign in
brainfood
/
rivets-error-binder
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
8c9d9371
authored
2014-04-12 18:07:29 -0500
by
Adam Heath
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
Fix jshint issues.
1 parent
8f9ef904
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
28 additions
and
19 deletions
src/scripts/rivets-error-binder.js
src/scripts/rivets-error-binder.js
View file @
8c9d937
/* global Backbone */
define
([
'rivets'
,
'bootstrap'
],
function
(
rivets
)
{
'use strict'
;
var
rivetsBinderCall
=
function
(
binding
,
binderName
,
methodName
,
args
)
{
var
binder
=
rivets
.
binders
[
binderName
];
if
(
binder
instanceof
Function
)
{
if
(
methodName
==
'routine'
)
{
binder
.
apply
(
binding
,
args
);
};
}
else
if
(
binder
)
{
if
(
binder
[
methodName
])
{
binder
[
methodName
].
apply
(
binding
,
args
);
}
var
binder
=
rivets
.
binders
[
binderName
];
if
(
binder
instanceof
Function
)
{
if
(
methodName
===
'routine'
)
{
binder
.
apply
(
binding
,
args
);
}
}
else
if
(
binder
)
{
if
(
binder
[
methodName
])
{
binder
[
methodName
].
apply
(
binding
,
args
);
}
}
}
};
var
diveIntoObject
=
function
(
obj
,
keypath
,
callback
)
{
if
(
!
keypath
)
{
...
...
@@ -21,7 +23,7 @@ define(['rivets', 'bootstrap'], function(rivets) {
//console.log('diveIntoObject(keyparts):', obj, keyparts);
while
(
keyparts
.
length
>
1
)
{
var
part
=
keyparts
.
shift
();
if
(
part
.
length
==
0
)
{
if
(
part
.
length
==
=
0
)
{
continue
;
}
//console.log('diveIntoObject:', obj, part);
...
...
@@ -32,30 +34,37 @@ define(['rivets', 'bootstrap'], function(rivets) {
};
var
doObjectRead
=
function
(
obj
,
id
)
{
if
(
obj
===
null
)
return
obj
;
if
(
!
id
)
return
obj
;
if
(
obj
===
null
)
{
return
obj
;
}
if
(
!
id
)
{
return
obj
;
}
//console.log('doObjectRead:', obj, id, obj instanceof Backbone.Model, obj instanceof Backbone.Collection);
if
(
obj
instanceof
Backbone
.
Model
)
{
return
obj
.
get
(
id
);
}
else
if
(
obj
instanceof
Backbone
.
Collection
)
{
return
obj
.
at
(
id
);
}
else
if
(
obj
!=
null
)
{
}
else
if
(
obj
!=
=
null
)
{
return
obj
[
id
];
}
};
rivets
.
binders
[
'error-*'
]
=
{
bind
:
function
(
el
)
{
var
self
=
this
;
var
holder
=
this
.
validationHolder
=
{
//marker: el.parentNode.insertBefore(document.createComment(" rivets: " + this.type + " "), el),
focus
:
function
()
{
$
(
holder
.
container
).
removeClass
(
'focused'
);
},
blur
:
function
()
{
if
(
holder
.
lastObj
)
holder
.
lastObj
.
seen
(
holder
.
lastId
,
true
);
if
(
holder
.
lastObj
)
{
holder
.
lastObj
.
seen
(
holder
.
lastId
,
true
);
}
$
(
holder
.
container
).
addClass
(
'focused'
);
if
(
holder
.
lastObj
)
holder
.
lastObj
.
validate
();
if
(
holder
.
lastObj
)
{
holder
.
lastObj
.
validate
();
}
},
validated
:
function
(
isValid
,
model
,
errors
)
{
var
errorList
=
errors
[
holder
.
lastId
];
...
...
@@ -76,13 +85,13 @@ define(['rivets', 'bootstrap'], function(rivets) {
var
holder
=
this
.
validationHolder
;
$
(
this
.
validationHolder
.
marker
).
after
(
el
).
remove
();
$
(
el
).
off
(
'focus'
,
holder
.
focus
).
off
(
'blur'
,
holder
.
blur
);
diveIntoObject
(
this
.
model
,
this
.
keypath
,
function
(
obj
,
id
)
{
diveIntoObject
(
this
.
model
,
this
.
keypath
,
function
(
obj
)
{
obj
.
off
(
'validated'
,
holder
.
validated
);
});
delete
this
.
validationHolder
;
rivetsBinderCall
(
this
,
this
.
args
[
0
],
'unbind'
,
arguments
);
},
routine
:
function
(
el
,
value
)
{
routine
:
function
()
{
var
holder
=
this
.
validationHolder
;
if
(
holder
.
lastObj
)
{
holder
.
lastObj
.
off
(
'validated'
,
holder
.
validated
);
...
...
Please
register
or
sign in
to post a comment