Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit b4d67cc
Showing
8 changed files
with
442 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
DS_Store |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
Copyright 2012 John Krauss. All rights reserved. | ||
|
||
Redistribution and use in source and binary forms, with or without | ||
modification, are permitted provided that the following conditions | ||
are met: | ||
|
||
1. Redistributions of source code must retain the above copyright | ||
notice, this list of conditions and the following disclaimer. | ||
|
||
2. Redistributions in binary form must reproduce the above | ||
copyright notice, this list of conditions and the following | ||
disclaimer in the documentation and/or other materials provided | ||
with the distribution. | ||
|
||
THIS SOFTWARE IS PROVIDED BY JOHN KRAUSS ''AS IS'' AND ANY EXPRESS | ||
OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | ||
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
ARE DISCLAIMED. IN NO EVENT SHALL JOHN KRAUSS OR CONTRIBUTORS BE | ||
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR | ||
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT | ||
OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR | ||
BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF | ||
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE | ||
USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH | ||
DAMAGE. | ||
|
||
The views and conclusions contained in the software and | ||
documentation are those of the authors and should not be | ||
interpreted as representing official policies, either expressed or | ||
implied, of John Krauss. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
all: | ||
uglifyjs jquery-download.js > jquery-download.min.js | ||
|
||
clean: | ||
rm jquery-download.min.js |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,141 @@ | ||
# jquery-download | ||
|
||
This jQuery plugin uses the `data:` URI to download the DOM of | ||
arbitrary elements into files. One file will be downloaded for each | ||
selected element. Since the DOM is captured, any javascript-generated | ||
content will be included in the download. | ||
|
||
[See it in action.](http://talos.github.com/jquery-download/demo.html) | ||
|
||
### Usage | ||
|
||
`failCallback`: (Optional) The browser may not support the data: URI. | ||
If this is the case, this function will be called once with the text | ||
ofeach element not downloaded. | ||
|
||
```javascript | ||
$(selector).download(failCallback); | ||
``` | ||
|
||
There is also a utility function you can use to check whether the | ||
browser supports the data URI. This will return `true` if there is | ||
support, and `false` otherwise. | ||
|
||
```javascript | ||
$().download('support'); | ||
``` | ||
|
||
### Examples | ||
|
||
This will download into a browser-named file the contents of the | ||
current page view: | ||
|
||
$('html').download(); | ||
|
||
This would download every svg on the page into a separate file: | ||
|
||
$('svg').download(); | ||
|
||
This takes advantage of `failCallback` in case the browser doesn't | ||
support the `data:` uri. | ||
|
||
var failCallback = function(text) { | ||
alert("Could not download " + text); | ||
}; | ||
$('#elem').download(failCallback); | ||
|
||
### Links | ||
|
||
Fork it from | ||
|
||
http://www.github.com/talos/jquery-download | ||
|
||
CDN it at | ||
|
||
http://talos.github.com/jquery-download/jquery-download.js | ||
|
||
http://talos.github.com/jquery-download/jquery-download.min.js | ||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
This jQuery plugin arbitrarly CSS transforms elements to a specific | ||
pixel size. All the contents of the element will scale with it! | ||
|
||
[See it in action.](http://talos.github.com/jquery-rescale/demo.html) | ||
|
||
### Usage | ||
|
||
`w` The width to scale to. Required. | ||
|
||
`h` The height to scale to. Required. | ||
|
||
`distort` Whether to allow differing x and y scale | ||
factors. Is true by default, meaning the element could be | ||
distorted. If false, the smallest of the two scales will be | ||
used for both axes, so that neither w or h is ever exceeded. | ||
|
||
`scaleDirection` If negative, only scaling down will be | ||
allowed. If greater than 0, only scaling up will be allowed. | ||
Otherwise, either direction is allowed. Defaults to 0. | ||
|
||
```javascript | ||
$(selector).rescale(w, h, distort, scaleDirection); | ||
``` | ||
|
||
### Examples | ||
|
||
```javascript | ||
$('.rescale').rescale(100, 100); | ||
``` | ||
|
||
Would scale all elements with the class 'scale' to 100 by 100 | ||
pixels. If you don't want the elements to be distorted, pass | ||
'false' as the distort argument: | ||
|
||
```javascript | ||
$('.rescale').rescale(100, 100, false); | ||
``` | ||
|
||
Each element will keep its original aspect ratio, but no dimension | ||
will exceed 100 pixels. | ||
|
||
If you want to only scale elements up, or only scale them down, you | ||
can pass a fourth argument. If it is negative, elements will only | ||
be scaled down: | ||
|
||
```javascript | ||
$('.rescale').rescale(100, 100, false, -1); | ||
``` | ||
|
||
Any elements with both dimensions already smaller than 100 pixels | ||
will be unmodified. | ||
|
||
To only scale elements up, pass a positive value: | ||
|
||
```javascript | ||
$('.rescale').rescale(100, 100, false, 1); | ||
``` | ||
|
||
Now, elements exceeding 100px * 100px will be unmodified, but any | ||
smaller than that will be scaled up. | ||
|
||
Play around with demo.html to see it in action. | ||
|
||
### Links | ||
|
||
Fork it from: | ||
|
||
http://www.github.com/talos/jquery-rescale | ||
|
||
CDN it from: | ||
|
||
http://talos.github.com/jquery-rescale/jquery-rescale.js | ||
|
||
http://talos.github.com/jquery-rescale/jquery-rescale.min.js |
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
/** | ||
Copyright 2012 John Krauss. All rights reserved. | ||
Redistribution and use in source and binary forms, with or without | ||
modification, are permitted provided that the following conditions | ||
are met: | ||
1. Redistributions of source code must retain the above copyright | ||
notice, this list of conditions and the following disclaimer. | ||
2. Redistributions in binary form must reproduce the above | ||
copyright notice, this list of conditions and the following | ||
disclaimer in the documentation and/or other materials provided | ||
with the distribution. | ||
THIS SOFTWARE IS PROVIDED BY JOHN KRAUSS ''AS IS'' AND ANY EXPRESS | ||
OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | ||
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
ARE DISCLAIMED. IN NO EVENT SHALL JOHN KRAUSS OR CONTRIBUTORS BE | ||
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR | ||
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT | ||
OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR | ||
BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF | ||
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE | ||
USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH | ||
DAMAGE. | ||
The views and conclusions contained in the software and | ||
documentation are those of the authors and should not be | ||
interpreted as representing official policies, either expressed or | ||
implied, of John Krauss. | ||
**/ | ||
(function($) { | ||
/** | ||
Download some text to the client computer. Only works in | ||
browsers that support the 'data:' scheme. | ||
@param text The text to download. | ||
**/ | ||
var download = function(text) { | ||
window.location.href = | ||
'data:application/x-download;charset=utf-8,' + | ||
encodeURIComponent(text); | ||
}, | ||
|
||
// Test to see if data URI is supported | ||
// Thanks to http://weston.ruter.net/2009/05/07/detecting-support-for-data-uris | ||
data = new Image(), | ||
supported = false; | ||
data.onload = data.onerror = function() { | ||
supported = (this.width === 1 && this.height === 1) ? true : false; | ||
}; | ||
data.src = "data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///ywAAAAAAQABAAACAUwAOw=="; | ||
|
||
/** | ||
Download the HTML of selected elements as text to the client | ||
computer, one file per element. Only works in browsers that | ||
support the 'data:' scheme. | ||
**/ | ||
$.fn.download = function(arg) { | ||
if(arg === 'support') { | ||
return supported; | ||
} else { | ||
var texts = [], | ||
interval; | ||
|
||
$.each(this, function(i, el) { | ||
var $el = $(el), | ||
$container = $('<div />'), | ||
text; | ||
|
||
$el.clone().appendTo($container); | ||
text = $container.html(); | ||
|
||
if(supported === true) { | ||
texts.push(text); | ||
} else { | ||
// If user supplied failCallback, call it. | ||
if($.isFunction(arg)) { | ||
arg(text); | ||
} | ||
} | ||
}); | ||
|
||
// Interval to shuffle through window.location.href | ||
interval = setInterval(function() { | ||
if(texts.length > 0) { | ||
download(texts.pop()); | ||
} else { | ||
clearInterval(interval); | ||
} | ||
}, 100); | ||
|
||
return this; | ||
} | ||
}; | ||
})(jQuery); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
/** | ||
Copyright 2012 John Krauss. All rights reserved. | ||
Redistribution and use in source and binary forms, with or without | ||
modification, are permitted provided that the following conditions | ||
are met: | ||
1. Redistributions of source code must retain the above copyright | ||
notice, this list of conditions and the following disclaimer. | ||
2. Redistributions in binary form must reproduce the above | ||
copyright notice, this list of conditions and the following | ||
disclaimer in the documentation and/or other materials provided | ||
with the distribution. | ||
THIS SOFTWARE IS PROVIDED BY JOHN KRAUSS ''AS IS'' AND ANY EXPRESS | ||
OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | ||
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
ARE DISCLAIMED. IN NO EVENT SHALL JOHN KRAUSS OR CONTRIBUTORS BE | ||
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR | ||
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT | ||
OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR | ||
BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF | ||
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE | ||
USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH | ||
DAMAGE. | ||
The views and conclusions contained in the software and | ||
documentation are those of the authors and should not be | ||
interpreted as representing official policies, either expressed or | ||
implied, of John Krauss. | ||
**/(function(a){var b=function(a){window.location.href="data:application/x-download;charset=utf-8,"+encodeURIComponent(a)},c=new Image,d=!1;c.onload=c.onerror=function(){d=this.width===1&&this.height===1?!0:!1},c.src="data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///ywAAAAAAQABAAACAUwAOw==",a.fn.download=function(c){if(c==="support")return d;var e=[],f;return a.each(this,function(b,f){var g=a(f),h=a("<div />"),i;g.clone().appendTo(h),i=h.html(),d===!0?e.push(i):a.isFunction(c)&&c(i)}),f=setInterval(function(){e.length>0?b(e.pop()):clearInterval(f)},100),this}})(jQuery); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
{ | ||
"name": "jquery-download", | ||
"version": "0.1.0", | ||
"title": "jQuery-download", | ||
"author": { | ||
"name": "John Krauss", | ||
"url": "https://github.com/talos" | ||
}, | ||
"licenses": [ | ||
{ | ||
"type": "BSD", | ||
"url": "LICENSE.txt" | ||
} | ||
], | ||
"dependencies": { | ||
"jquery": "1" | ||
}, | ||
"description": "This plugin uses the data: uri to allow users to download arbitrary pieces of DOM, including SVGs.", | ||
"keywords": [ | ||
"download", | ||
"data" | ||
], | ||
"homepage": "https://github.com/talos/jquery-download", | ||
"maintainers": [ | ||
{ | ||
"name": "John Krauss", | ||
"url": "https://github.com/talos" | ||
} | ||
], | ||
"files": [ | ||
"jquery-download.js", | ||
"jquery-download.min.js" | ||
] | ||
} |