Advertisement
Guest User

Just making jQuery Plugins--no big deal.

a guest
Mar 4th, 2015
211
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. ;(function($){
  2.    $(document).ready(function(){
  3.     var dropItLikesItsHot =  $("div.dropzone").dropZone();
  4.     Dropzone.autoDiscover = false;
  5.   });
  6.  
  7.   var markupButton = "<button class=\"dropzone-del\"><i class=\"fa fa-remove\"></i> Remove File</button>";
  8.   $.fn.extend({
  9.     dropZone: function() {
  10.       return new Dropzone($(this)[0],
  11.         {
  12.           init: function (){
  13.             var $that = $(this); // this jQuery Plugin Obj
  14.             var _that = this; // this Dropzone Obj
  15.            
  16.             //dropZone addFile Event
  17.             _that.on("addedfile", function(file) {
  18.               var removeButton = Dropzone.createElement(markupButton);
  19.               removeButton.addEventListener("click", function(e){
  20.                 e.preventDefault();
  21.                 _that.removeFile(file);
  22.                 //del from server sessions/filesystem
  23.                 $that.delFromServer(file.name);
  24.               });
  25.               //on this file obj append a button
  26.               file.previewElement.appendChild(removeButton);
  27.  
  28.             })
  29.           },
  30.  
  31.           url: "/embroidery-quote/ajax",
  32.           paramName: "file"
  33.       });
  34.     },
  35.  
  36.     delFromServer: function(key) {
  37.       $.get("/embroidery-quote/ajax", {'do': 'remove_artwork', 'key': key});
  38.     }
  39.   });
  40. })(jQuery);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement