Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
…ction into sokokaleb-master
  • Loading branch information
jaysalvat committed Nov 4, 2017
2 parents f198bfe + 6bf3336 commit bfe4979
Show file tree
Hide file tree
Showing 7 changed files with 56 additions and 77 deletions.
9 changes: 4 additions & 5 deletions README.md
Expand Up @@ -32,8 +32,8 @@ Download the plugin with the method of your choice.

Include [jQuery](http://code.jquery.com/jquery-1.11.1.min.js) and the plugin.

<script src="http://code.jquery.com/jquery-1.11.1.min.js"></script>
<script src="path/to/dist/jquery.facedetection.min.js"></script>
<script src="http://code.jquery.com/jquery-1.11.1.min.js"></script>
<script src="path/to/dist/jquery.facedetection.min.js"></script>

Set a picture with some faces in your HTML page.

Expand All @@ -47,7 +47,7 @@ Apply the plugin to this image and get the face coordinates.
console.log(faces);
}
});
</script>
</script>

Results
-------
Expand Down Expand Up @@ -78,10 +78,9 @@ Settings
complete: function (faces) {
// ...
}

- **error** — Callback function trigged on errors

error: function (code, message) {
// ...
}
27 changes: 20 additions & 7 deletions dist/jquery.facedetection.js
Expand Up @@ -16246,7 +16246,8 @@
name: funct.toString(),
shared: scope.shared,
id: i,
worker: params.worker_num
worker: params.worker_num,
from: "jquery.facedetection"
};
try {
worker.postMessage(msg);
Expand Down Expand Up @@ -16493,15 +16494,27 @@
post: post
};
})
};
}, originalOnMessage = window.onmessage || function() {};
onmessage = function(event) {
var data = "string" == typeof event.data ? JSON.parse(event.data) : event.data, scope = {
shared: data.shared
}, result = parallable.core[data.name].apply(scope, [ data.input, data.id, data.worker ]);
var data;
try {
postMessage(result);
if (data = "string" == typeof event.data ? JSON.parse(event.data) : event.data,
"jquery.facedetection" === data.type) {
var scope = {
shared: data.shared
}, result = parallable.core[data.name].apply(scope, [ data.input, data.id, data.worker ]);
try {
postMessage(result);
} catch (e) {
postMessage(JSON.stringify(result));
}
} else {
var args = Array.prototype.slice.call(arguments);
originalOnMessage.apply(window, args);
}
} catch (e) {
postMessage(JSON.stringify(result));
var args = Array.prototype.slice.call(arguments);
originalOnMessage.apply(window, args);
}
}, $.fn.faceDetection = function(settingsOrCallback) {
"use strict";
Expand Down
2 changes: 1 addition & 1 deletion dist/jquery.facedetection.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/jquery.facedetection.min.js.map

Large diffs are not rendered by default.

51 changes: 0 additions & 51 deletions package.bk.json

This file was deleted.

2 changes: 1 addition & 1 deletion package.json
@@ -1,6 +1,6 @@
{
"name": "jquery.facedetection",
"version": "2.0.2",
"version": "2.0.3",
"description": "A jQuery plugin to detect faces on images, videos and canvases.",
"homepage": "http://facedetection.jaysalvat.com",
"main": "./dist/jquery.facedetection.min.js",
Expand Down
40 changes: 29 additions & 11 deletions src/ccv.js
Expand Up @@ -32,7 +32,7 @@ if (parallable === undefined) {
"use strict";

parallable.core[funct.toString()] = funct().core;

return function () {
var i;
var async, worker_num, params;
Expand Down Expand Up @@ -79,7 +79,8 @@ if (parallable === undefined) {
"name" : funct.toString(),
"shared" : scope.shared,
"id" : i,
"worker" : params.worker_num };
"worker" : params.worker_num,
"from" : "jquery.facedetection" };
try {
worker.postMessage(msg);
} catch (e) {
Expand Down Expand Up @@ -481,13 +482,30 @@ var ccv = {
})
}

// Monkey patch to avoid overriding window's onmessage handler.
var originalOnMessage = window.onmessage || function () {};
onmessage = function (event) {
var data = (typeof event.data == "string") ? JSON.parse(event.data) : event.data;
var scope = { "shared" : data.shared };
var result = parallable.core[data.name].apply(scope, [data.input, data.id, data.worker]);
try {
postMessage(result);
} catch (e) {
postMessage(JSON.stringify(result));
}
}
var data;
try {
data = (typeof event.data == "string") ? JSON.parse(event.data) : event.data;
if (data.type === "jquery.facedetection") {
// This is the event that is intended for jquery.facedetection
var scope = { "shared" : data.shared };
var result = parallable.core[data.name].apply(scope, [data.input, data.id, data.worker]);
try {
postMessage(result);
} catch (e) {
postMessage(JSON.stringify(result));
}
} else {
// Nope. This is not the event that should be handled by jquery.facedetection
var args = Array.prototype.slice.call(arguments);
originalOnMessage.apply(window, args);
}
} catch (e) {
// `event.data` is string, but too bad it is not in JSON format.
// so just pass it to window's original onmessage handler
var args = Array.prototype.slice.call(arguments);
originalOnMessage.apply(window, args);
}
}

0 comments on commit bfe4979

Please sign in to comment.