Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
renderjs
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Labels
Merge Requests
1
Merge Requests
1
Analytics
Analytics
Repository
Value Stream
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Commits
Open sidebar
nexedi
renderjs
Commits
5e541236
Commit
5e541236
authored
May 23, 2014
by
Romain Courteaud
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Allow to directly declareGadget inside the HTML.
parent
786c7abf
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
143 additions
and
1 deletion
+143
-1
renderjs.js
renderjs.js
+28
-1
test/renderjs_test.js
test/renderjs_test.js
+115
-0
No files found.
renderjs.js
View file @
5e541236
...
@@ -42,7 +42,34 @@
...
@@ -42,7 +42,34 @@
g
.
__sub_gadget_dict
=
{};
g
.
__sub_gadget_dict
=
{};
}
}
RenderJSGadget
.
__ready_list
=
[
clearGadgetInternalParameters
];
function
loadSubGadgetDOMDeclaration
(
g
)
{
var
element_list
=
g
.
__element
.
querySelectorAll
(
'
[data-gadget-scope]
'
),
element
,
promise_list
=
[],
scope
,
url
,
sandbox
,
i
;
for
(
i
=
0
;
i
<
element_list
.
length
;
i
+=
1
)
{
element
=
element_list
[
i
];
scope
=
element
.
getAttribute
(
"
data-gadget-scope
"
);
url
=
element
.
getAttribute
(
"
data-gadget-url
"
);
sandbox
=
element
.
getAttribute
(
"
data-gadget-sandbox
"
);
if
((
scope
!==
null
)
&&
(
url
!==
null
))
{
promise_list
.
push
(
g
.
declareGadget
(
url
,
{
element
:
element
,
scope
:
scope
||
undefined
,
sandbox
:
sandbox
||
undefined
}));
}
}
return
RSVP
.
all
(
promise_list
);
}
RenderJSGadget
.
__ready_list
=
[
clearGadgetInternalParameters
,
loadSubGadgetDOMDeclaration
];
RenderJSGadget
.
ready
=
function
(
callback
)
{
RenderJSGadget
.
ready
=
function
(
callback
)
{
this
.
__ready_list
.
push
(
callback
);
this
.
__ready_list
.
push
(
callback
);
return
this
;
return
this
;
...
...
test/renderjs_test.js
View file @
5e541236
...
@@ -2404,6 +2404,121 @@
...
@@ -2404,6 +2404,121 @@
.
always
(
start
);
.
always
(
start
);
});
});
test
(
'
can declareGadget with scope in HTML directly
'
,
function
()
{
var
gadget
=
new
RenderJSGadget
(),
html_url
=
'
https://example.org/files/qunittest/test12345.html
'
,
html_url2
=
'
https://example.org/files/qunittest/test12346.html
'
,
spy
;
this
.
server
.
respondWith
(
"
GET
"
,
html_url
,
[
200
,
{
"
Content-Type
"
:
"
text/html
"
},
"
<html><body><div data-foo='bar'
"
+
"
data-gadget-scope='bar' data-gadget-url='
"
+
html_url2
+
"
'></div></body></html>
"
]);
this
.
server
.
respondWith
(
"
GET
"
,
html_url2
,
[
200
,
{
"
Content-Type
"
:
"
text/html
"
},
"
raw html
"
]);
spy
=
sinon
.
spy
(
renderJS
,
"
parseGadgetHTMLDocument
"
);
stop
();
gadget
.
declareGadget
(
html_url
)
.
then
(
function
(
g
)
{
equal
(
spy
.
callCount
,
2
);
equal
(
spy
.
firstCall
.
args
[
1
],
html_url
);
equal
(
spy
.
secondCall
.
args
[
1
],
html_url2
);
// Second gadget is a child
return
g
.
getDeclaredGadget
(
"
bar
"
);
})
.
then
(
function
(
g2
)
{
equal
(
g2
.
__path
,
html_url2
);
// The gadget element is the one defined in HTML
equal
(
g2
.
__element
.
getAttribute
(
"
data-foo
"
),
"
bar
"
);
// The gadget is public by default
equal
(
g2
.
__element
.
innerHTML
,
"
raw html
"
);
})
.
fail
(
function
(
e
)
{
ok
(
false
,
e
);
})
.
always
(
function
()
{
start
();
spy
.
restore
();
});
});
test
(
'
can declareGadget a sandboxed gadget in HTML directly
'
,
function
()
{
var
gadget
=
new
RenderJSGadget
(),
html_url
=
'
https://example.org/files/qunittest/test123456.html
'
,
html_url2
=
renderJS
.
getAbsoluteURL
(
'
./embedded.html
'
,
window
.
location
.
href
),
topURL
=
"
http://example.org/topGadget
"
;
this
.
server
.
respondWith
(
"
GET
"
,
html_url
,
[
200
,
{
"
Content-Type
"
:
"
text/html
"
},
"
<html><body><div data-foo='bar'
"
+
"
data-gadget-sandbox='iframe'
"
+
"
data-gadget-scope='bar' data-gadget-url='
"
+
html_url2
+
"
'></div></body></html>
"
]);
gadget
.
__aq_parent
=
function
(
method_name
,
argument_list
)
{
throw
new
renderJS
.
AcquisitionError
(
"
Can not handle
"
+
method_name
);
};
gadget
.
__acquired_method_dict
=
{
getTopURL
:
function
()
{
return
topURL
;
}
};
document
.
getElementById
(
"
qunit-fixture
"
).
textContent
=
""
;
stop
();
gadget
.
declareGadget
(
html_url
,
{
element
:
document
.
getElementById
(
'
qunit-fixture
'
)
})
.
then
(
function
(
g
)
{
return
g
.
getDeclaredGadget
(
"
bar
"
);
})
.
then
(
function
(
g2
)
{
equal
(
g2
.
__path
,
html_url2
);
// The gadget element is the one defined in HTML
equal
(
g2
.
__element
.
getAttribute
(
"
data-foo
"
),
"
bar
"
);
// The gadget is inside an iframe
equal
(
g2
.
__element
.
innerHTML
,
'
<iframe src="
'
+
html_url2
+
'
"></iframe>
'
);
})
.
fail
(
function
(
e
)
{
ok
(
false
,
e
);
})
.
always
(
function
()
{
start
();
});
});
test
(
'
fail if declareGadget with scope in HTML fail
'
,
function
()
{
var
gadget
=
new
RenderJSGadget
(),
html_url
=
'
https://example.org/files/qunittest/test12345.html
'
,
html_url2
=
'
https://example.org/files/qunittest/test12346.html
'
;
this
.
server
.
respondWith
(
"
GET
"
,
html_url
,
[
200
,
{
"
Content-Type
"
:
"
text/html
"
},
"
<html><body><div data-foo='bar'
"
+
"
data-gadget-scope='bar' data-gadget-url='
"
+
html_url2
+
"
'></div></body></html>
"
]);
this
.
server
.
respondWith
(
"
GET
"
,
html_url2
,
[
403
,
{
"
Content-Type
"
:
"
text/html
"
},
"
raw html
"
]);
stop
();
gadget
.
declareGadget
(
html_url
)
.
then
(
function
()
{
ok
(
false
);
})
.
fail
(
function
(
e
)
{
equal
(
e
.
status
,
403
);
equal
(
e
.
url
,
html_url2
);
})
.
always
(
start
);
});
/////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////
// RenderJSGadget.declareGadget (iframe)
// RenderJSGadget.declareGadget (iframe)
/////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment