initial commit
[namibia] / public / scripts / blueimp-jQuery-File-Upload / js / main.js
1 /*
2  * jQuery File Upload Plugin JS Example 6.7
3  * https://github.com/blueimp/jQuery-File-Upload
4  *
5  * Copyright 2010, Sebastian Tschan
6  * https://blueimp.net
7  *
8  * Licensed under the MIT license:
9  * http://www.opensource.org/licenses/MIT
10  */
11
12 /*jslint nomen: true, unparam: true, regexp: true */
13 /*global $, window, document */
14
15 $(function () {
16     'use strict';
17
18     // Initialize the jQuery File Upload widget:
19     $('#fileupload').fileupload();
20
21     // Enable iframe cross-domain access via redirect option:
22     $('#fileupload').fileupload(
23         'option',
24         'redirect',
25         window.location.href.replace(
26             /\/[^\/]*$/,
27             '/cors/result.html?%s'
28         )
29     );
30
31     if (window.location.hostname === 'blueimp.github.com') {
32         // Demo settings:
33         $('#fileupload').fileupload('option', {
34             url: '//jquery-file-upload.appspot.com/',
35             maxFileSize: 5000000,
36             acceptFileTypes: /(\.|\/)(gif|jpe?g|png)$/i,
37             process: [
38                 {
39                     action: 'load',
40                     fileTypes: /^image\/(gif|jpeg|png)$/,
41                     maxFileSize: 20000000 // 20MB
42                 },
43                 {
44                     action: 'resize',
45                     maxWidth: 1440,
46                     maxHeight: 900
47                 },
48                 {
49                     action: 'save'
50                 }
51             ]
52         });
53         // Upload server status check for browsers with CORS support:
54         if ($.support.cors) {
55             $.ajax({
56                 url: '//jquery-file-upload.appspot.com/',
57                 type: 'HEAD'
58             }).fail(function () {
59                 $('<span class="alert alert-error"/>')
60                     .text('Upload server currently unavailable - ' +
61                             new Date())
62                     .appendTo('#fileupload');
63             });
64         }
65     } else {
66         // Load existing files:
67         $('#fileupload').each(function () {
68             var that = this;
69             $.getJSON(this.action, function (result) {
70                 if (result && result.length) {
71                     $(that).fileupload('option', 'done')
72                         .call(that, null, {result: result});
73                 }
74             });
75         });
76     }
77
78 });