adding method for checking presence or absence of attribute

This commit is contained in:
Danny Yoo 2011-11-22 02:21:53 -05:00
parent dd01373ae5
commit d6fb2ff295
3 changed files with 17 additions and 1 deletions

View File

@ -65,6 +65,7 @@
view-hide view-hide
view-attr view-attr
view-has-attr?
update-view-attr update-view-attr
remove-view-attr remove-view-attr

View File

@ -216,6 +216,10 @@
return $(this.cursor.node[0]).attr(name); return $(this.cursor.node[0]).attr(name);
}; };
MockView.prototype.hasAttr = function(name) {
return $(this.cursor.node[0]).attr(name) !== undefined;
};
MockView.prototype.updateAttr = function(name, value) { MockView.prototype.updateAttr = function(name, value) {
return this.act( return this.act(
@ -1923,6 +1927,14 @@
return view.getAttr(name); return view.getAttr(name);
}); });
EXPORTS['view-has-attr?'] = makePrimitiveProcedure(
'view-has-attr?',
2,
function(MACHINE) {
var view = checkMockViewOnElement(MACHINE, 'view-has-attr?', 0);
var name = checkSymbolOrString(MACHINE, 'view-has-attr?', 1).toString();
return view.hasAttr(name);
});
EXPORTS['update-view-attr'] = makePrimitiveProcedure( EXPORTS['update-view-attr'] = makePrimitiveProcedure(
'update-view-attr', 'update-view-attr',

View File

@ -18,7 +18,7 @@
view-backward view-backward
view-text update-view-text view-text update-view-text
view-attr update-view-attr remove-view-attr view-attr view-has-attr? update-view-attr remove-view-attr
view-css update-view-css view-css update-view-css
view-id view-id
@ -148,6 +148,9 @@
(define (view-attr v attr-name) (define (view-attr v attr-name)
(error 'view-attr "Please run in JavaScript context.")) (error 'view-attr "Please run in JavaScript context."))
(define (view-has-attr? v attr-name)
(error 'view-has-attr? "Please run in JavaScript context."))
(define (update-view-attr v attr-name value) (define (update-view-attr v attr-name value)
(error 'update-view-attr "Please run in JavaScript context.")) (error 'update-view-attr "Please run in JavaScript context."))