Skip to content
This repository has been archived by the owner on Dec 26, 2019. It is now read-only.

Commit

Permalink
jQuery contract adjusted #4
Browse files Browse the repository at this point in the history
- jQuery.ClipPath only argument is the path string
- backward compatibility with Object ensured
- devDependencies updated
- documentation updated
  • Loading branch information
AlfonsoFilho committed Aug 19, 2017
1 parent 532e6db commit a195ef1
Show file tree
Hide file tree
Showing 7 changed files with 588 additions and 442 deletions.
1 change: 1 addition & 0 deletions .yarnrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
save-prefix false
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,13 @@ With jQuery:
```javascript
$('.target').ClipPath('5% 5%, 100% 0%, 100% 75%');
```
> NOTE: for backward compatibility reasons, jquery implementation also accepts an object as an argument. In this case, a path property is expected. This alternative should be avoided since it is deprecated.
```javascript
// Using object instead string
// @deprecated
$('.image').ClipPath({path: '5% 5%, 100% 0%, 100% 75%, 75% 75%, 75% 100%, 50% 75%, 0% 75%'});
```

Or can use html element's attribute to set clip points:
```html
Expand Down
2 changes: 1 addition & 1 deletion dist/clippath.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions example/jquery.html
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,12 @@

$(function(){
console.log('Applying clip-path with jQuery');
$('.image').ClipPath({path: '5% 5%, 100% 0%, 100% 75%, 75% 75%, 75% 100%, 50% 75%, 0% 75%'});
$('.image').ClipPath('5% 5%, 100% 0%, 100% 75%, 75% 75%, 75% 100%, 50% 75%, 0% 75%');
$('.image-2').ClipPath();
});

setTimeout(function() {
$('.image').ClipPath({path:'5% 5%, 100% 0%, 100% 75%, 75% 75%, 75% 100%'});
$('.image').ClipPath('5% 5%, 100% 0%, 100% 75%, 75% 75%, 75% 100%');
console.log('Changed after some time...');
}, 4000);
</script>
Expand Down
11 changes: 8 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
{
"name": "clip-path",
"version": "1.0.0",
"keywords": [
"jquery",
"polyfill",
"clip-path"
],
"description": "ClipPath",
"main": "./dist/clippath.min.js",
"scripts": {
Expand All @@ -20,12 +25,12 @@
},
"homepage": "https://github.com/AlfonsoFilho/ClipPath#readme",
"devDependencies": {
"eslint": "3.19.0",
"eslint": "4.4.1",
"gulp": "3.9.1",
"gulp-rename": "1.2.2",
"gulp-size": "2.1.0",
"gulp-uglify": "2.1.2",
"jest": "19.0.2",
"gulp-uglify": "3.0.0",
"jest": "20.0.4",
"rimraf": "2.6.1",
"through2": "2.0.3"
},
Expand Down
11 changes: 8 additions & 3 deletions src/clippath.js
Original file line number Diff line number Diff line change
Expand Up @@ -113,11 +113,16 @@ ClipPath.applyClipPath = applyClipPath;

if(typeof jQuery !== 'undefined') {
(function($, _ClipPath){
$.fn.ClipPath = function(options) {
$.fn.ClipPath = function(pathStr) {

// pathStr can be an object due backward compatibility
// but pathStr must be a string
if(pathStr === Object(pathStr) && pathStr.path) {
pathStr = pathStr.path;
}

return this.each(function() {
var path = $(this).attr('data-clip') || (options && options.path);
_ClipPath.applyClipPath(this, path);
_ClipPath.applyClipPath(this, $(this).attr('data-clip') || pathStr);
});

};
Expand Down
Loading

0 comments on commit a195ef1

Please sign in to comment.