app/assets/javascripts/ruby_gallery.js in ruby_gallery-0.1.5 vs app/assets/javascripts/ruby_gallery.js in ruby_gallery-0.1.6
- old
+ new
@@ -1,51 +1,73 @@
-
- clearInterval(window.refeshWork);
- window.refeshWork = null;
+$(document).ready(function(){
- jQuery('#fileupload').fileupload({
- dropZone: $('#fileupload'),
- progressInterval: 20,
- add: function(e,data){
-
- if ($('span#upload_button').attr('status') == 'process'){
- return false;
- } else {
- var types = /(\.|\/)(png|jpg|gif|jpeg)$/i;
- var file = data.files[0];
- if (types.test(file.type) || types.test(file.name) ){
- $('span.upload-button span').html("<%= t('details.processing') %>");
- $("span#no-file").remove();
- $('#file_box ul#photos_album').append("<li class='photo-cat new-photo' ><div id='progress' class='pic-icon' ></div></li>");
- data.submit();
- } else {
- alert("<%= t('details.please_upload_image_file')%>");
- }
- }
- },
- progressall: function(e, data){
- // var progress = parseInt(data.loaded / data.total * 100, 10);
- // $('#file_box ul#photos_album li.new-photo').find('#progress div.bar').css('width',progress + '%' );
- },
- done: function(e, data){
-
- var report = '';
- if(data.result != 'failed'){
- var res = data.result;
- $('span#upload_button span').html("<%= t('details.upload_picture') %>");
- $('#file_box ul#photos_album li.new-photo').fadeOut('slow', function() {
+ $(document.body).delegate("a.gallery-colorbox", "click", function(e){
+ $(this).colorbox({rel: "ruby_gallery"});
+ e.preventDefault();
+ });
+
+ $('ul.ruby-gallery-sortable').sortable({
+ stop: function(event, ui){
+ $('ul.ruby-gallery-sortable').children().each(function(index){
+ $(this).find('input[name="position-item"]').val(index);
+ });
+ var arr_pos = []
+ $(':hidden[name^="position-item"]').each(function(){
+ arr_pos.push($(this).val());
+ });
- $('#file_box ul#photos_album li.new-photo').remove();
- $('#file_box ul#photos_album').append(res);
-
- });
-
- // var t=setTimeout(function(){
- // }, 2000);
- } else {
- $('#file_box ul#photos_album li.new-photo').html("<%= t('details.upload_failed') %>");
- var t = setTimeout(function(){
- $('#file_box ul#photos_album li.new-photo').remove();
- }, 2000);
- }
- }
- });
+ var arr_key = $("li.photo-cat").map(function(){
+ return this.getAttribute("key");
+ }).get();
+ var json_str = "";
+ for(var i = 0; i < arr_pos.length && arr_key.length; i ++ ) {
+ json_str += "{'id':'" + arr_key[i] + "', 'position':'" + arr_pos[i] + "'},"
+ }
+ var json = eval("[" + json_str + "]")
+ $.ajax({
+ url: $("ul#photos_album").attr("data_url"),
+ data: {'json': json},
+ type: "PUT",
+ success: function(res){
+ }
+ })
+ }
+ });
+
+ $(document.body).delegate('span.remove-photo', 'click', function(e){
+ var _this = this
+ $.ajax({
+ url: "/" + $('div.file-box').attr('data_model') + "/" + $('div.file-box').attr('model_id') + "/delete_photo?photo_id="+ $(this).attr('photo_id') ,
+ type: "DELETE",
+ success: function(e){
+ if(e == "ok"){
+ var dom = $(_this).parent().find("li.photo_" + $(_this).attr('photo_id') + "").selector.toString();
+ $(dom).remove();
+ }else{
+
+ }
+ }
+ });
+ e.preventDefault();
+ });
+
+ $(document.body).delegate('li.photo-cat a','mouseover',function(event){
+ $(this).parent().find('span.remove-photo').addClass('blur');
+ $(this).parent().find('span.remove-photo').removeClass('hide');
+ });
+
+ $(document.body).delegate('li.photo-cat a','mouseout',function(event){
+ $(this).parent().find('span.remove-photo').removeClass('blur');
+ $(this).parent().find('span.remove-photo').addClass('hide');
+ });
+
+ $(document.body).delegate('span.remove-photo','mouseover',function(event){
+ $(this).removeClass('blur');
+ $(this).removeClass('hide');
+ });
+
+ $(document.body).delegate('span.remove-photo','mouseout',function(event){
+ $(this).addClass('blur');
+ $(this).removeClass('hide');
+
+ });
+});
\ No newline at end of file