Skip to content
This repository has been archived by the owner on Aug 5, 2020. It is now read-only.

V2.0 swift jazzcat merge #117

Merged
merged 11 commits into from
Mar 21, 2013
2 changes: 1 addition & 1 deletion Gruntfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ module.exports = function(grunt) {
all: {
options: {
urls: [
'http://localhost:3000/tests/capture.html',
'http://localhost:3000/tests/capture.html', 'http://localhost:3000/tests/jazzcat.html',
]
}
}
Expand Down
2 changes: 1 addition & 1 deletion examples/capturing-grumpycat/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@
return true;
},
// path to mobify.js
'/mobifyjs/build/mobify-2.0.0alpha2.min.js',
'/mobifyjs/build/mobify-2.0.0alpha2.js',

// path to main executable
'/mobifyjs/examples/capturing-grumpycat/main.js'
Expand Down
6 changes: 3 additions & 3 deletions examples/swift/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -62,13 +62,13 @@
return true;
},
// path to mobify.js
'http://cloud.dev:8000/projects/jan8-jansepar-1/swift/mobify.js'
//'http://cloud.dev:8000/projects/jan8-jansepar-1/swift/mobify.js'

/*

'/mobifyjs/build/mobify-2.0.0alpha2.js',

// path to main executable
'/mobifyjs/examples/swift/main.js' */
'/mobifyjs/examples/swift/main.js'
);

</script>
Expand Down
80 changes: 7 additions & 73 deletions examples/swift/main.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
var capturing = window.capturing || false;
var capturing = window.Mobify && window.Mobify.capturing || false;
if (capturing) {
// Remove the bootstrap and tag scripts
//var scripts = document.getElementsByTagName("script");
Expand All @@ -13,86 +13,20 @@ if (capturing) {
// Mobify.keepWarm = keepWarm;
// Mobify.speedClick = speedClick;

var swiftData = {
"jazzcat": {
"safe": true,
"defaults": [
{
"does": true,
"matchType": "contains", // contains, startswith, endswith, regex
"match": "adsense"
}
],
"excludes": [
{
"does": false,
"matchType": "contains", // contains, startswith, endswith, regex
"match": "jquery-ui"
}
]
},
"ir": {
"defaults": [
{
"does": true,
"matchType": "contains", // contains, startswith, endswith, regex
"match": "quantcast"
}
],
"excludes": [
{
"does": true,
"matchType": "contains", // contains, startswith, endswith, regex
"match": "adsense"
}
]
},
"dom": {
"excludes": [
{
"conditionType": "mediaquery", // mediaquery, javascript
"condition": "(max-width: 400px)",
"matchType": "css",
"match": ".removeme" // img, div, script, etc, *
}
]
}
}

// Initiate capture
var capture = Mobify.Capture.init();

// Grab reference to a newly created document
var capturedDoc = capture.capturedDoc;

// Exclude some DOM elements
if (swiftData.dom) {
[].forEach.call(swiftData.dom.excludes, function(exclude){
if (window.matchMedia && window.matchMedia(exclude.condition)) {
Mobify.Utils.removeBySelector(exclude.match);
}
})
}

// Concatinate Javascript using Jazzcat
if (swiftData.jazzcat) {
var scripts = capturedDoc.querySelectorAll('script');
var scriptExcludes = swiftData.jazzcat.defaults.concat(swiftData.jazzcat.excludes);
var filteredScripts = Mobify.Utils.removeElementFilter(scripts, scriptExcludes);
Mobify.Jazzcat.combineScripts(filteredScripts, {
doc: capturedDoc
});
}
var scripts = capturedDoc.querySelectorAll('script');
Mobify.Jazzcat.combineScripts(scripts);

// Resize images using Mobify Image Resizer
if (swiftData.ir) {
var images = capturedDoc.querySelectorAll('script');
var imageExcludes = swiftData.ir.defaults.concat(swiftData.ir.excludes);
var filteredScripts = Mobify.Utils.removeElementFilter(scripts, scriptExcludes);
Mobify.ResizeImages.resize( capturedDoc.querySelectorAll("img"), {
projectName: "mobifycom",
});
}
var images = capturedDoc.querySelectorAll('img');
Mobify.ResizeImages.resize( images, {
projectName: "mobifycom",
});

// Render source DOM to document
capture.renderCapturedDoc();
Expand Down
10 changes: 8 additions & 2 deletions src/capture.js
Original file line number Diff line number Diff line change
Expand Up @@ -354,6 +354,12 @@ Capture.prototype.escapedHTMLString = function() {
* Rewrite the document with a new html string
*/
Capture.prototype.render = function(htmlString) {
if (!htmlString) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jansepar hoist this var declaration?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TOO BAD ITS ALREADY MERGED SUCKAAA. lol jk sure I'll make the change in the branch that this has been merged into.

var escapedHTMLString = this.escapedHTMLString();
} else {
var escapedHTMLString = Capture.enable(htmlString);
}

var doc = this.doc;

// Set capturing state to false so that the user main code knows how to execute
Expand All @@ -362,7 +368,7 @@ Capture.prototype.render = function(htmlString) {
// Asynchronously render the new document
setTimeout(function(){
doc.open();
doc.write(htmlString);
doc.write(escapedHTMLString);
doc.close();
});
};
Expand Down Expand Up @@ -418,7 +424,7 @@ Capture.prototype.renderCapturedDoc = function(options) {
}


this.render(this.escapedHTMLString());
this.render();
};

return Capture;
Expand Down
Loading