mirror of https://github.com/zulip/zulip.git
zjsquery: Add data support.
Before this we just noop'ed it, since at one time we were trying to deprecate this is in favor of attr calls.
This commit is contained in:
parent
9ba1829243
commit
493afcb9f0
|
@ -50,6 +50,11 @@ run_test('basics', () => {
|
|||
|
||||
widget.attr('data-employee-id', 42);
|
||||
assert.equal(widget.attr('data-employee-id'), 42);
|
||||
assert.equal(widget.data('employee-id'), 42);
|
||||
|
||||
widget.data('department-id', 77);
|
||||
assert.equal(widget.attr('data-department-id'), 77);
|
||||
assert.equal(widget.data('department-id'), 77);
|
||||
|
||||
widget.html('<b>hello</b>');
|
||||
assert.equal(widget.html(), '<b>hello</b>');
|
||||
|
|
|
@ -177,7 +177,17 @@ exports.make_new_elem = function (selector, opts) {
|
|||
}
|
||||
return elem.parent().closest(selector);
|
||||
},
|
||||
data: noop,
|
||||
data: function (name, val) {
|
||||
if (val === undefined) {
|
||||
const data_val = attrs.get('data-' + name);
|
||||
if (data_val === undefined) {
|
||||
return;
|
||||
}
|
||||
return JSON.parse(data_val);
|
||||
}
|
||||
attrs.set('data-' + name, val);
|
||||
return self;
|
||||
},
|
||||
delay: function () {
|
||||
return self;
|
||||
},
|
||||
|
|
Loading…
Reference in New Issue