Created
December 16, 2012 16:43
-
-
Save vladtsf/4309252 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| jQuery(function($) { | |
| var $selectPhoto = $('#selectPhoto') | |
| $selectPhoto.photoUploader( $selectPhoto.data("action"), true ) | |
| // /illuminator/1/upload -> куда отправлять запрос | |
| // true -> multiple | |
| }) |
This file contains hidden or 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
| (function($, undefined) { | |
| var makeUploader = function(selector, url, multiple) { | |
| var def, | |
| _this = this; | |
| if (multiple == null) { | |
| multiple = false; | |
| } | |
| def = new $.Deferred(); | |
| new qq.FineUploader({ | |
| element: $(selector).get(0), | |
| multiple: multiple, | |
| validation: { | |
| allowedExtensions: ["jpeg", "jpg", "gif", "png"] | |
| // sizeLimit: 4096e3 | |
| }, | |
| request: { | |
| endpoint: url, | |
| forceMultipart: true, | |
| inputName: "picture" | |
| // customHeaders: { | |
| // } | |
| }, | |
| text: { | |
| uploadButton: "Upload" | |
| }, | |
| template: "<div class=\"qq-uploader\">\n <pre class=\"qq-upload-drop-area span12\"><span>{dragZoneText}</span></pre>\n <div class=\"qq-upload-button btn btn-success\">Выбрать</div>\n <ul class=\"qq-upload-list\" style=\"display: none;\"></ul>\n</div>", | |
| classes: { | |
| success: 'alert alert-success', | |
| fail: 'alert alert-error' | |
| }, | |
| debug: false, | |
| callbacks: { | |
| onComplete: function(id, fileName, res) { | |
| if (res.success) { | |
| return def.notify(id, res.url); | |
| } | |
| }, | |
| onError: function(id, fileName, errorReason) { | |
| return def.fail(id, errorReason); | |
| } | |
| } | |
| }); | |
| return def; | |
| }; | |
| // 'input[name="picture"]' | |
| $.fn.photoUploader = function( url, multiple ) { | |
| $.each(this, function( idx, el ) { | |
| makeUploader( el, url, multiple ) | |
| .progress(function(id, url) { | |
| $( "#uploaded-photos-placeholder" ) // id блока с картинками | |
| .append('<span><img class="img-rounded" style="margin: 10px;" src="' + url + '" alt="" /></span>') | |
| }); | |
| }); | |
| } | |
| })(jQuery); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment