Skip to content

Commit

Permalink
Add standalone tests and fix can.view.autorender
Browse files Browse the repository at this point in the history
  • Loading branch information
daffl committed Apr 1, 2015
1 parent 83359fa commit 290da55
Show file tree
Hide file tree
Showing 6 changed files with 51 additions and 10 deletions.
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ dist/
*.orig
util/can.*.js
*node_modules*
standalone*
docs*
*.DS_Store
.idea
Expand Down
2 changes: 1 addition & 1 deletion util/can.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ steal(function () {
can["import"] = function(moduleName) {
var deferred = new can.Deferred();

if(typeof window.System === "object") {
if(typeof window.System === "object" && can.isFunction(window.System["import"])) {
window.System["import"](moduleName).then(can.proxy(deferred.resolve, deferred),
can.proxy(deferred.reject, deferred));
} else if(window.define && window.define.amd){
Expand Down
9 changes: 4 additions & 5 deletions view/autorender/autorender.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,14 +90,13 @@ steal("can/util",function(can){
can.proxy(deferred.reject, deferred)
);
}



if(document.body){

if (document.readyState === 'complete') {
autoload();
} else {
can.bind.call(document,"DOMContentLoaded", autoload);
can.bind.call(window, 'load', autoload);
}

var promise = deferred.promise();
can.autorender = function(success, error){
return promise.then(success, error);
Expand Down
8 changes: 5 additions & 3 deletions view/autorender/autorender_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,14 @@ steal("can/test", "steal-qunit", function () {
asyncTest("the basics are able to work for steal", function(){
makeIframe( can.test.path("view/autorender/tests/steal-basics.html?"+Math.random()) );
});
}

if(window.requirejs) {
} else if(window.requirejs) {
asyncTest("the basics are able to work for requirejs", function(){
makeIframe(can.test.path("../../view/autorender/tests/requirejs-basics.html?"+Math.random()));
});
} else {
asyncTest("the basics are able to work standalone", function(){
makeIframe(can.test.path("view/autorender/tests/standalone-basics.html?"+Math.random()));
});
}

});
26 changes: 26 additions & 0 deletions view/autorender/tests/standalone-basics.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<script>
window.isReady = window.parent.isReady || function(el) {
console.log(el.length);
console.log(el.html());
};
window.hasError = window.parent.hasError || function(error) {
console.log("error in autoload", error)
};
window.removeMyself = window.parent.removeMyself;
</script>
<script src="../../../bower_components/jquery/dist/jquery.js"></script>
<script src="../../../dist/can.jquery.js"></script>
<script src="../../../dist/can.stache.js"></script>
<script src="../../../dist/can.autorender.js"></script>
<script src="standalone-basics.js"></script>

<script type="text/stache" id="basics" foo="bar" can-autorender>
<my-component></my-component>
</script>
<script>
$(function() {
can.autorender().then(function() {
isReady($("body my-component"), can.viewModel('my-component'));
});
});
</script>
15 changes: 15 additions & 0 deletions view/autorender/tests/standalone-basics.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
(function() {
window.MyComponent = can.Component.extend({
tag: "my-component",
// call can.stache b/c it should be imported auto-magically
template: can.stache("{{message}}"),
scope: {
message: "Hello World"
},
events: {
"inserted": function(){
this.element[0].className = "inserted";
}
}
});
})();

0 comments on commit 290da55

Please sign in to comment.