forked from danpros/htmly
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
use bootstrap for file upload, remove iframe for ajax
- Loading branch information
1 parent
b21e786
commit 49511a8
Showing
9 changed files
with
181 additions
and
279 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,67 +1,69 @@ | ||
(function () { | ||
|
||
var converter = new Markdown.Converter(); | ||
Markdown.Extra.init(converter); | ||
var editor = new Markdown.Editor(converter); | ||
|
||
var $dialog = $('#insertImageDialog').dialog({ | ||
autoOpen: false, | ||
closeOnEscape: false, | ||
open: function(event, ui) { $(".ui-dialog-titlebar-close").hide(); } | ||
//======Image Uploader===== | ||
var callbackFunc; | ||
var dialogClose = function() { | ||
$('#insertImageDialog').modal('hide'); | ||
$('#insertImageDialogURL').val(''); | ||
$('#insertImageDialogFile').val(''); | ||
}; | ||
$('#insertImageDialogInsert').click( function() { | ||
callbackFunc( $('#insertImageDialogURL').val().length > 0 ? $('#insertImageDialogURL').val() : null ); | ||
dialogClose(); | ||
}); | ||
|
||
var $url = $('input[type=text]', $dialog); | ||
var $file = $('input[type=file]', $dialog); | ||
|
||
editor.hooks.set('insertImageDialog', function(callback) { | ||
|
||
var dialogClose = function() { | ||
$url.val(''); | ||
$file.val(''); | ||
$dialog.dialog('close'); | ||
}; | ||
|
||
$dialog.dialog({ | ||
buttons : { | ||
"Insert" : { | ||
text: "Insert", | ||
id: "insert", | ||
click: function(){ | ||
callback($url.val().length > 0 ? $url.val(): null); | ||
dialogClose(); | ||
} | ||
}, | ||
"Cancel" : { | ||
text: "Cancel", | ||
id: "cancel", | ||
click: function(){ | ||
dialogClose(); | ||
callback(null); | ||
} | ||
} | ||
} | ||
}); | ||
|
||
var uploadComplete = function(response) { | ||
if (response.error == '0') { | ||
$url.val(base_path + response.path); | ||
$("#insert").trigger('click'); | ||
} else { | ||
alert(response.error); | ||
$file.val(''); | ||
$('#insertImageDialogClose').click( function() { | ||
callbackFunc(null); | ||
dialogClose(); | ||
}); | ||
$('#insertImageDialogCancel').click( function() { | ||
callbackFunc(null); | ||
dialogClose(); | ||
}); | ||
$('#insertImageDialogFile').on('input', function(){ | ||
var file = $("#insertImageDialogFile").prop("files"); | ||
var formData = new FormData(); | ||
formData.append('file', file[0], file[0].name); | ||
// Set up the request. | ||
$.ajax({ | ||
type: "POST", | ||
url: base_path + 'upload.php', | ||
data: formData, | ||
processData: false, | ||
contentType: false, | ||
success: function (response) { | ||
if (response.error == '0') | ||
{ | ||
callbackFunc(base_path + response.path); | ||
dialogClose(); | ||
} | ||
else | ||
{ | ||
if (response.error !== '') alert(response.error); | ||
else alert("An unknown error has occurred"); | ||
console.error("Bad Response"); | ||
console.error(response); | ||
$('#insertImageDialogFile').val(''); | ||
} | ||
}, | ||
failure: function (response) { | ||
if (response.error !== '') alert(response.error); | ||
else alert("An unknown error has occurred"); | ||
console.error("Unable to Upload"); | ||
console.error(response); | ||
$('#insertImageDialogFile').val(''); | ||
} | ||
}; | ||
|
||
$file.ajaxfileupload({ | ||
'action': base_path + 'upload.php', | ||
'onComplete': uploadComplete, | ||
}); | ||
|
||
$dialog.dialog('open'); | ||
});//ajax | ||
});//oninput | ||
editor.hooks.set('insertImageDialog', function(callback) { | ||
$('#insertImageDialog').modal('show'); | ||
callbackFunc = callback; | ||
|
||
return true; // tell the editor that we'll take care of getting the image url | ||
}); | ||
|
||
//=====end image uploader===== | ||
editor.run(); | ||
|
||
})(); |
This file was deleted.
Oops, something went wrong.
This file contains 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
Oops, something went wrong.