From 05712f2c080ef974903678d8cc24a1e5ee1a889b Mon Sep 17 00:00:00 2001 From: Henrique Dias Date: Mon, 8 Feb 2016 08:24:12 +0000 Subject: [PATCH] fix delete name, and start moving handlers to '#content' --- assets/js/app.min.js | 2 +- assets/src/js/app.js | 4 ++- assets/src/js/browse.js | 55 +++++++++++++++++++++++------------------ 3 files changed, 35 insertions(+), 26 deletions(-) diff --git a/assets/js/app.min.js b/assets/js/app.min.js index 12960bc5..277cb490 100644 --- a/assets/js/app.min.js +++ b/assets/js/app.min.js @@ -1 +1 @@ -$(document).ready(function(){$("#logout").click(function(a){return a.preventDefault(),$.ajax({type:"GET",url:"/admin",async:!1,username:"username",password:"password",headers:{Authorization:"Basic xxx"}}).fail(function(){window.location="/"}),!1}),$(document).pjax("a[data-pjax]","#content")}),$(document).on("ready pjax:success",function(){function a(){this.style.height="5px",this.style.height=this.scrollHeight+"px"}return document.title=document.getElementById("site-title").innerHTML,$("textarea").each(a),$("textarea").keyup(a),$(window).resize(function(){$("textarea").each(a)}),$("main").hasClass("browse")&&$(document).trigger("page:browse"),$(".editor")[0]&&$(document).trigger("page:editor"),!1}),$(document).on("page:browse",function(){var a=$("#foreground"),b=new Object;b.form=$("form#delete"),b.row="",b.button="",b.url="",$("body").off("click",".delete").on("click",".delete",function(c){return c.preventDefault(),b.button=$(this),b.row=$(this).parent().parent(),a.fadeIn(200),b.url=b.row.find(".filename").text(),b.form.fadeIn(200),b.form.find("span").text(d.url),!1}),b.form.off("submit").submit(function(c){return c.preventDefault(),$.ajax({type:"DELETE",url:b.button.data("file")}).done(function(c){a.fadeOut(200),b.form.fadeOut(200),b.row.fadeOut(200),notification({text:b.button.data("message"),type:"success",timeout:5e3})}).fail(function(a){notification({text:"Something went wrong.",type:"error"}),console.log(a)}),!1}),$("body").off("change",'input[type="file"]').on("change",'input[type="file"]',function(a){a.preventDefault(),files=a.target.files;var b=new FormData;return $.each(files,function(a,c){b.append(a,c)}),$.ajax({url:window.location.pathname,type:"POST",data:b,cache:!1,dataType:"json",headers:{"X-Upload":"true"},processData:!1,contentType:!1}).done(function(a){notification({text:"File(s) uploaded successfully.",type:"success",timeout:5e3}),$.pjax({url:window.location.pathname,container:"#content"})}).fail(function(a){notification({text:"Something went wrong.",type:"error"}),console.log(a)}),!1}),$("body").off("click",".upload").on("click",".upload",function(a){return a.preventDefault(),$('.actions input[type="file"]').click(),!1});var c=new Object;c.form=$("form#new"),c.button="",c.url="",$("body").off("click",".new").on("click",".new",function(b){return b.preventDefault(),c.button=$(this),a.fadeIn(200),c.form.fadeIn(200),!1}),c.form.find('input[type="text"]').off("keypress").keypress(function(a){return 13==a.keyCode?(a.preventDefault(),$(c.form).submit(),!1):void 0}),c.form.submit(function(a){a.preventDefault();var b=c.form.find('input[type="text"]').val(),d=b.split(":"),e="",f="";if(""==b)return notification({text:"You have to write something. If you want to close the box, click the button again.",type:"warning",timeout:5e3}),!1;if(1==d.length)e=b;else{if(2!=d.length)return notification({text:"Hmm... I don't understand you. Try writing something like 'name[:archetype]'.",type:"error"}),!1;e=d[0],f=d[1]}var g='{"filename": "'+e+'", "archetype": "'+f+'"}';return $.ajax({type:"POST",url:window.location.pathname,data:g,dataType:"json",encode:!0}).done(function(a){notification({text:"File created successfully.",type:"success",timeout:5e3}),$.pjax({url:window.location.pathname.replace("browse","edit")+e,container:"#content"})}).fail(function(a){notification({text:"Something went wrong.",type:"error"}),console.log(a)}),!1});var d=new Object;d.form=$("form#rename"),d.button="",d.url="",$("body").off("click",".rename").on("click",".rename",function(b){return b.preventDefault(),d.button=$(this),a.fadeIn(200),d.url=$(this).parent().parent().find(".filename").text(),d.form.fadeIn(200),d.form.find("span").text(d.url),d.form.find('input[type="text"]').val(d.url),!1}),d.form.find('input[type="text"]').off("keypress").keypress(function(a){return 13==a.keyCode?(a.preventDefault(),$(d.form).submit(),!1):void 0}),d.form.off("submit").submit(function(a){a.preventDefault();var b=d.form.find('input[type="text"]').val();if(""===b)return!1;"/"!=b.substring(0,1)&&(b=window.location.pathname.replace("/admin/browse/","")+"/"+b);var c='{"filename": "'+b+'"}';return $.ajax({type:"PUT",url:d.url,data:c,dataType:"json",encode:!0}).done(function(a){$.pjax({url:window.location.pathname,container:"#content"}),notification({text:d.button.data("message"),type:"success",timeout:5e3})}).fail(function(a){notification({text:"Something went wrong.",type:"error"}),console.log(a)}),!1}),$("body").off("click",".close").on("click",".close",function(b){return b.preventDefault(),$(this).parent().parent().fadeOut(200),a.click(),!1}),a.off("click").click(function(){a.fadeOut(200),c.form.fadeOut(200),d.form.fadeOut(200),b.form.fadeOut(200)})}),$(document).on("page:editor",function(){var a=$(".editor"),b=$("#editor-preview"),c=$("#editor-source");if(a.hasClass("complete")&&$("#site-title").keyup(function(){$(".frontmatter #title").val($(this).val())}),!a.hasClass("frontmatter-only")){var d=$("#editor-source").data("mode"),e=$('textarea[name="content"]').hide(),f=ace.edit("editor-source");f.getSession().setMode("ace/mode/"+d),f.getSession().setValue(e.val()),f.getSession().on("change",function(){e.val(f.getSession().getValue())}),f.setOptions({wrap:!0,maxLines:1/0,theme:"ace/theme/github",showPrintMargin:!1,fontSize:"1em"}),$("#see-source").off("click").click(function(a){a.preventDefault(),b.hide(),c.fadeIn(),$("#see-preview").data("previewing","false")}),$("#see-preview").off("click").click(function(a){if(a.preventDefault(),"true"==$(this).data("previewing"))b.hide(),c.fadeIn(),$(this).data("previewing","false");else{var d=new showdown.Converter,e=f.getValue(),g=d.makeHtml(e);c.hide(),b.html(g).fadeIn(),$(this).data("previewing","true")}return!1})}$("body").off("keypress","input").on("keypress","input",function(a){return 13==a.keyCode?(a.preventDefault(),$('input[value="Save"]').focus().click(),!1):void 0}),$("form").submit(function(d){d.preventDefault(),a.hasClass("frontmatter-only")||(b.html("").fadeOut(),$("#see-preview").data("previewing","false"),c.fadeIn());var e=JSON.stringify($(this).serializeJSON()),f=$(this).find("input[type=submit]:focus");return $.ajax({type:"POST",url:window.location,data:e,headers:{"X-Regenerate":f.data("regenerate"),"X-Schedule":f.data("schedule"),"X-Content-Type":f.data("type")},dataType:"json",encode:!0,contentType:"application/json; charset=utf-8"}).done(function(a){notification({text:f.data("message"),type:"success",timeout:5e3})}).fail(function(a){notification({text:"Something went wrong.",type:"error"}),console.log(a)}),!1}),$("body").on("click",".add",function(a){if(a.preventDefault(),defaultID="lorem-ipsum-sin-dolor-amet",$("#"+defaultID).length)return!1;if(block=$(this).parent().parent(),blockType=block.data("type"),blockID=block.attr("id"),block.is("div")&&block.hasClass("frontmatter")&&(block=$(".blocks"),block.append('
'),blockType="object"),"array"==blockType&&(newID=blockID+"[]",input=blockID,input=input.replace(/\[/,"\\["),input=input.replace(/\]/,"\\]"),block.append('
div").length+'" data-type="array-item">
')),"object"!=blockType||block.hasClass("frontmatter")||(block.append('
'),blockType="object"),"object"==blockType){if(newItem=$("#"+defaultID),newItem.html(''),field=$("#name-"+defaultID),!document.cookie.replace(/(?:(?:^|.*;\s*)placeholdertip\s*\=\s*([^;]*).*$)|^.*$/,"$1")){var b=new Date;b.setDate(b.getDate()+365),document.cookie="placeholdertip=true; expires="+b.toUTCString+"; path=/",notification({text:'Write the field name and then press enter. If you want to create an array or an object, end the name with ":array" or ":object".',type:"information"})}$(field).keypress(function(a){return console.log("got it"),13==a.which?(a.preventDefault(),value=field.val(),""==value?(newItem.remove(),!1):(elements=value.split(":"),elements.length>2?(notification({text:"Invalid syntax. It must be 'name[:type]'.",type:"error"}),!1):2==elements.length&&"array"!=elements[1]&&"object"!=elements[1]?(notification({text:"Only arrays and objects are allowed.",type:"error"}),!1):(field.remove(),"undefined"==typeof blockID?blockID=elements[0]:blockID=blockID+"["+elements[0]+"]",1==elements.length?(newItem.attr("id","block-"+blockID),newItem.append('
'),newItem.prepend(' ')):(type="","array"==elements[1]?type="array":type="object",template='

${elements[0]}

',template=template.replace("${blockID}",blockID),template=template.replace("${elements[0]}",elements[0]),template=template.replace("${type}",type),newItem.after(template),newItem.remove(),console.log('"'+blockID+'" block of type "'+type+'" added.')),!1))):void 0})}return!1}),$("body").on("click",".delete",function(a){return a.preventDefault(),button=$(this),name=button.parent().parent().attr("for")||button.parent().parent().attr("id")||button.parent().parent().parent().attr("id"),name=name.replace(/\[/,"\\["),name=name.replace(/\]/,"\\]"),console.log(name),$('label[for="'+name+'"]').fadeOut().remove(),$("#"+name).fadeOut().remove(),!1})}),$.noty.themes.admin={name:"admin",helpers:{},modal:{css:{position:"fixed",width:"100%",height:"100%",backgroundColor:"#000",zIndex:1e4,opacity:.6,display:"none",left:0,top:0}}},$.noty.defaults={layout:"topRight",theme:"admin",dismissQueue:!0,animation:{open:"animated bounceInRight",close:"animated fadeOut",easing:"swing",speed:500},timeout:!1,force:!1,modal:!1,maxVisible:5,killer:!1,closeWith:["click"],callback:{onShow:function(){},afterShow:function(){},onClose:function(){},afterClose:function(){},onCloseClick:function(){}},buttons:!1},notification=function(a){var b;switch(a.type){case"success":b='';break;case"error":b='';break;case"warning":b='';break;case"information":b='';break;default:b=''}var c={template:'
'+b+'
'};if(a=$.extend({},c,a),noty(a),!document.cookie.replace(/(?:(?:^|.*;\s*)stickynoties\s*\=\s*([^;]*).*$)|^.*$/,"$1")&&!a.timeout){var d=new Date;d.setDate(d.getDate()+365),document.cookie="stickynoties=true; expires="+d.toUTCString+"; path=/",notification({text:"Some notifications are sticky. If it doesn't go away, click to dismiss it.",type:"information"})}}; \ No newline at end of file +$(document).ready(function(){$("#logout").click(function(a){return a.preventDefault(),$.ajax({type:"GET",url:"/admin",async:!1,username:"username",password:"password",headers:{Authorization:"Basic xxx"}}).fail(function(){window.location="/"}),!1}),$(document).pjax("a[data-pjax]","#content")}),$(document).on("ready pjax:end",function(){function a(){this.style.height="5px",this.style.height=this.scrollHeight+"px"}return $("#content").off(),document.title=document.getElementById("site-title").innerHTML,$("textarea").each(a),$("textarea").keyup(a),$(window).resize(function(){$("textarea").each(a)}),$("main").hasClass("browse")&&$(document).trigger("page:browse"),$(".editor")[0]&&$(document).trigger("page:editor"),!1}),$(document).on("page:browse",function(){var a="#foreground",b=new Object;b.selector="form#delete",b.form=$(b.selector),b.row="",b.button="",b.url="",$("#content").on("click",".delete",function(c){return c.preventDefault(),b.button=$(this),b.row=$(this).parent().parent(),$(a).fadeIn(200),b.url=b.row.find(".filename").text(),b.form.find("span").text(b.url),b.form.fadeIn(200),!1}),$("#content").on("submit",b.selector,function(c){return c.preventDefault(),$.ajax({type:"DELETE",url:b.button.data("file")}).done(function(c){$(a).fadeOut(200),b.form.fadeOut(200),b.row.fadeOut(200),notification({text:b.button.data("message"),type:"success",timeout:5e3})}).fail(function(a){notification({text:"Something went wrong.",type:"error"}),console.log(a)}),!1}),$("#content").on("change",'input[type="file"]',function(a){a.preventDefault(),files=a.target.files;var b=new FormData;return $.each(files,function(a,c){b.append(a,c)}),$.ajax({url:window.location.pathname,type:"POST",data:b,cache:!1,dataType:"json",headers:{"X-Upload":"true"},processData:!1,contentType:!1}).done(function(a){notification({text:"File(s) uploaded successfully.",type:"success",timeout:5e3}),$.pjax({url:window.location.pathname,container:"#content"})}).fail(function(a){notification({text:"Something went wrong.",type:"error"}),console.log(a)}),!1}),$("#content").on("click",".upload",function(a){return a.preventDefault(),$('.actions input[type="file"]').click(),!1});var c=new Object;c.selector="form#new",c.form=$(c.selector),c.input=c.selector+' input[type="text"]',c.button="",c.url="",$("#content").on("click",".new",function(b){return b.preventDefault(),c.button=$(this),$(a).fadeIn(200),c.form.fadeIn(200),!1}),$("#content").on("keypress",c.input,function(a){return 13==a.keyCode?(a.preventDefault(),$(c.form).submit(),!1):void 0}),$("#content").on("submit",c.selector,function(a){a.preventDefault();var b=c.form.find('input[type="text"]').val(),d=b.split(":"),e="",f="";if(""==b)return notification({text:"You have to write something. If you want to close the box, click the button again.",type:"warning",timeout:5e3}),!1;if(1==d.length)e=b;else{if(2!=d.length)return notification({text:"Hmm... I don't understand you. Try writing something like 'name[:archetype]'.",type:"error"}),!1;e=d[0],f=d[1]}var g='{"filename": "'+e+'", "archetype": "'+f+'"}';return $.ajax({type:"POST",url:window.location.pathname,data:g,dataType:"json",encode:!0}).done(function(a){notification({text:"File created successfully.",type:"success",timeout:5e3}),$.pjax({url:window.location.pathname.replace("browse","edit")+e,container:"#content"})}).fail(function(a){notification({text:"Something went wrong.",type:"error"}),console.log(a)}),!1});var d=new Object;d.selector="form#rename",d.form=$(d.selector),d.input=d.selector+' input[type="text"]',d.button="",d.url="",$("#content").on("click",".rename",function(b){return b.preventDefault(),d.button=$(this),$(a).fadeIn(200),d.url=$(this).parent().parent().find(".filename").text(),d.form.fadeIn(200),d.form.find("span").text(d.url),d.form.find('input[type="text"]').val(d.url),!1}),$("#content").on("keypress",d.input,function(a){return 13==a.keyCode?(a.preventDefault(),$(d.form).submit(),!1):void 0}),$("#content").on("submit",d.selector,function(a){a.preventDefault();var b=d.form.find('input[type="text"]').val();if(""===b)return!1;"/"!=b.substring(0,1)&&(b=window.location.pathname.replace("/admin/browse/","")+"/"+b);var c='{"filename": "'+b+'"}';return $.ajax({type:"PUT",url:d.url,data:c,dataType:"json",encode:!0}).done(function(a){$.pjax({url:window.location.pathname,container:"#content"}),notification({text:d.button.data("message"),type:"success",timeout:5e3})}).fail(function(a){notification({text:"Something went wrong.",type:"error"}),console.log(a)}),!1}),$("#content").on("click",".close",function(b){return b.preventDefault(),$(this).parent().parent().fadeOut(200),$(a).click(),!1}),$("#content").on("click",a,function(e){return e.preventDefault(),$(a).fadeOut(200),c.form.fadeOut(200),d.form.fadeOut(200),b.form.fadeOut(200),!1})}),$(document).on("page:editor",function(){var a=$(".editor"),b=$("#editor-preview"),c=$("#editor-source");if(a.hasClass("complete")&&$("#site-title").keyup(function(){$(".frontmatter #title").val($(this).val())}),!a.hasClass("frontmatter-only")){var d=$("#editor-source").data("mode"),e=$('textarea[name="content"]').hide(),f=ace.edit("editor-source");f.getSession().setMode("ace/mode/"+d),f.getSession().setValue(e.val()),f.getSession().on("change",function(){e.val(f.getSession().getValue())}),f.setOptions({wrap:!0,maxLines:1/0,theme:"ace/theme/github",showPrintMargin:!1,fontSize:"1em"}),$("#see-source").off("click").click(function(a){a.preventDefault(),b.hide(),c.fadeIn(),$("#see-preview").data("previewing","false")}),$("#see-preview").off("click").click(function(a){if(a.preventDefault(),"true"==$(this).data("previewing"))b.hide(),c.fadeIn(),$(this).data("previewing","false");else{var d=new showdown.Converter,e=f.getValue(),g=d.makeHtml(e);c.hide(),b.html(g).fadeIn(),$(this).data("previewing","true")}return!1})}$("body").off("keypress","input").on("keypress","input",function(a){return 13==a.keyCode?(a.preventDefault(),$('input[value="Save"]').focus().click(),!1):void 0}),$("form").submit(function(d){d.preventDefault(),a.hasClass("frontmatter-only")||(b.html("").fadeOut(),$("#see-preview").data("previewing","false"),c.fadeIn());var e=JSON.stringify($(this).serializeJSON()),f=$(this).find("input[type=submit]:focus");return $.ajax({type:"POST",url:window.location,data:e,headers:{"X-Regenerate":f.data("regenerate"),"X-Schedule":f.data("schedule"),"X-Content-Type":f.data("type")},dataType:"json",encode:!0,contentType:"application/json; charset=utf-8"}).done(function(a){notification({text:f.data("message"),type:"success",timeout:5e3})}).fail(function(a){notification({text:"Something went wrong.",type:"error"}),console.log(a)}),!1}),$("body").on("click",".add",function(a){if(a.preventDefault(),defaultID="lorem-ipsum-sin-dolor-amet",$("#"+defaultID).length)return!1;if(block=$(this).parent().parent(),blockType=block.data("type"),blockID=block.attr("id"),block.is("div")&&block.hasClass("frontmatter")&&(block=$(".blocks"),block.append('
'),blockType="object"),"array"==blockType&&(newID=blockID+"[]",input=blockID,input=input.replace(/\[/,"\\["),input=input.replace(/\]/,"\\]"),block.append('
div").length+'" data-type="array-item">
')),"object"!=blockType||block.hasClass("frontmatter")||(block.append('
'),blockType="object"),"object"==blockType){if(newItem=$("#"+defaultID),newItem.html(''),field=$("#name-"+defaultID),!document.cookie.replace(/(?:(?:^|.*;\s*)placeholdertip\s*\=\s*([^;]*).*$)|^.*$/,"$1")){var b=new Date;b.setDate(b.getDate()+365),document.cookie="placeholdertip=true; expires="+b.toUTCString+"; path=/",notification({text:'Write the field name and then press enter. If you want to create an array or an object, end the name with ":array" or ":object".',type:"information"})}$(field).keypress(function(a){return console.log("got it"),13==a.which?(a.preventDefault(),value=field.val(),""==value?(newItem.remove(),!1):(elements=value.split(":"),elements.length>2?(notification({text:"Invalid syntax. It must be 'name[:type]'.",type:"error"}),!1):2==elements.length&&"array"!=elements[1]&&"object"!=elements[1]?(notification({text:"Only arrays and objects are allowed.",type:"error"}),!1):(field.remove(),"undefined"==typeof blockID?blockID=elements[0]:blockID=blockID+"["+elements[0]+"]",1==elements.length?(newItem.attr("id","block-"+blockID),newItem.append('
'),newItem.prepend(' ')):(type="","array"==elements[1]?type="array":type="object",template='

${elements[0]}

',template=template.replace("${blockID}",blockID),template=template.replace("${elements[0]}",elements[0]),template=template.replace("${type}",type),newItem.after(template),newItem.remove(),console.log('"'+blockID+'" block of type "'+type+'" added.')),!1))):void 0})}return!1}),$("body").on("click",".delete",function(a){return a.preventDefault(),button=$(this),name=button.parent().parent().attr("for")||button.parent().parent().attr("id")||button.parent().parent().parent().attr("id"),name=name.replace(/\[/,"\\["),name=name.replace(/\]/,"\\]"),console.log(name),$('label[for="'+name+'"]').fadeOut().remove(),$("#"+name).fadeOut().remove(),!1})}),$.noty.themes.admin={name:"admin",helpers:{},modal:{css:{position:"fixed",width:"100%",height:"100%",backgroundColor:"#000",zIndex:1e4,opacity:.6,display:"none",left:0,top:0}}},$.noty.defaults={layout:"topRight",theme:"admin",dismissQueue:!0,animation:{open:"animated bounceInRight",close:"animated fadeOut",easing:"swing",speed:500},timeout:!1,force:!1,modal:!1,maxVisible:5,killer:!1,closeWith:["click"],callback:{onShow:function(){},afterShow:function(){},onClose:function(){},afterClose:function(){},onCloseClick:function(){}},buttons:!1},notification=function(a){var b;switch(a.type){case"success":b='';break;case"error":b='';break;case"warning":b='';break;case"information":b='';break;default:b=''}var c={template:'
'+b+'
'};if(a=$.extend({},c,a),noty(a),!document.cookie.replace(/(?:(?:^|.*;\s*)stickynoties\s*\=\s*([^;]*).*$)|^.*$/,"$1")&&!a.timeout){var d=new Date;d.setDate(d.getDate()+365),document.cookie="stickynoties=true; expires="+d.toUTCString+"; path=/",notification({text:"Some notifications are sticky. If it doesn't go away, click to dismiss it.",type:"information"})}}; \ No newline at end of file diff --git a/assets/src/js/app.js b/assets/src/js/app.js index 0b86c509..bdf01667 100644 --- a/assets/src/js/app.js +++ b/assets/src/js/app.js @@ -21,7 +21,9 @@ $(document).ready(function() { $(document).pjax('a[data-pjax]', '#content'); }); -$(document).on('ready pjax:success', function() { +$(document).on('ready pjax:end', function() { + $('#content').off(); + // Update the title document.title = document.getElementById('site-title').innerHTML; diff --git a/assets/src/js/browse.js b/assets/src/js/browse.js index 6ac95b55..e3da21ca 100644 --- a/assets/src/js/browse.js +++ b/assets/src/js/browse.js @@ -1,33 +1,34 @@ $(document).on('page:browse', function() { - var foreground = $('#foreground'); + var foreground = '#foreground'; /* DELETE FILE */ var remove = new Object(); - remove.form = $('form#delete'); + remove.selector = 'form#delete'; + remove.form = $(remove.selector); remove.row = ''; remove.button = ''; remove.url = ''; - $('body').off('click', '.delete').on('click', '.delete', function(event) { + $('#content').on('click', '.delete', function(event) { event.preventDefault(); remove.button = $(this); remove.row = $(this).parent().parent(); - foreground.fadeIn(200); + $(foreground).fadeIn(200); remove.url = remove.row.find('.filename').text(); + remove.form.find('span').text(remove.url); remove.form.fadeIn(200); - remove.form.find('span').text(rename.url); return false; }); - remove.form.off('submit').submit(function(event) { + $('#content').on('submit', remove.selector, function(event) { event.preventDefault(); $.ajax({ type: 'DELETE', url: remove.button.data("file") }).done(function(data) { - foreground.fadeOut(200); + $(foreground).fadeOut(200); remove.form.fadeOut(200); remove.row.fadeOut(200); notification({ @@ -48,7 +49,7 @@ $(document).on('page:browse', function() { /* FILE UPLOAD */ - $('body').off('change', 'input[type="file"]').on('change', 'input[type="file"]', function(event) { + $('#content').on('change', 'input[type="file"]', function(event) { event.preventDefault(); files = event.target.files; @@ -90,7 +91,7 @@ $(document).on('page:browse', function() { return false; }); - $('body').off('click', '.upload').on('click', '.upload', function(event) { + $('#content').on('click', '.upload', function(event) { event.preventDefault(); $('.actions input[type="file"]').click(); return false; @@ -99,19 +100,21 @@ $(document).on('page:browse', function() { /* NEW FILE */ var create = new Object(); - create.form = $('form#new'); + create.selector = 'form#new'; + create.form = $(create.selector); + create.input = create.selector + ' input[type="text"]'; create.button = ''; create.url = ''; - $('body').off('click', '.new').on('click', '.new', function(event) { + $('#content').on('click', '.new', function(event) { event.preventDefault(); create.button = $(this); - foreground.fadeIn(200); + $(foreground).fadeIn(200); create.form.fadeIn(200); return false; }); - create.form.find('input[type="text"]').off('keypress').keypress(function(event) { + $('#content').on('keypress', create.input, function(event) { if (event.keyCode == 13) { event.preventDefault(); $(create.form).submit(); @@ -119,7 +122,7 @@ $(document).on('page:browse', function() { } }); - create.form.submit(function(event) { + $('#content').on('submit', create.selector, function(event) { event.preventDefault(); var value = create.form.find('input[type="text"]').val(), @@ -182,15 +185,17 @@ $(document).on('page:browse', function() { /* RENAME FILE */ var rename = new Object(); - rename.form = $('form#rename'); + rename.selector = 'form#rename'; + rename.form = $(rename.selector); + rename.input = rename.selector + ' input[type="text"]'; rename.button = ''; rename.url = ''; - $('body').off('click', '.rename').on('click', '.rename', function(event) { + $('#content').on('click', '.rename', function(event) { event.preventDefault(); rename.button = $(this); - foreground.fadeIn(200); + $(foreground).fadeIn(200); rename.url = $(this).parent().parent().find('.filename').text(); rename.form.fadeIn(200); rename.form.find('span').text(rename.url); @@ -199,7 +204,7 @@ $(document).on('page:browse', function() { return false; }); - rename.form.find('input[type="text"]').off('keypress').keypress(function(event) { + $('#content').on('keypress', rename.input, function(event) { if (event.keyCode == 13) { event.preventDefault(); $(rename.form).submit(); @@ -207,7 +212,7 @@ $(document).on('page:browse', function() { } }); - rename.form.off('submit').submit(function(event) { + $('#content').on('submit', rename.selector, function(event) { event.preventDefault(); var filename = rename.form.find('input[type="text"]').val(); @@ -248,19 +253,21 @@ $(document).on('page:browse', function() { return false; }); - /* FOREGROUND AND STUFF */ + /* $(foreground) AND STUFF */ - $('body').off('click', '.close').on('click', '.close', function(event) { + $('#content').on('click', '.close', function(event) { event.preventDefault(); $(this).parent().parent().fadeOut(200); - foreground.click(); + $(foreground).click(); return false; }); - foreground.off('click').click(function() { - foreground.fadeOut(200); + $('#content').on('click', foreground, function(event) { + event.preventDefault(); + $(foreground).fadeOut(200); create.form.fadeOut(200); rename.form.fadeOut(200); remove.form.fadeOut(200); + return false; }); });