Removed ceo-uploader.php.

Moved uploader ajax to coe-image-manager.php.
Fixed ajax uploader to work in FF and Chrome.
Changed uploader to run through admin-ajax.php.
Removed post generator form uploader ajax function.
Working on image manager(delet/ detach comics from posts).
This commit is contained in:
zerzix
2010-09-12 10:09:42 -04:00
parent da802cb028
commit d727e7db3b
10 changed files with 264 additions and 385 deletions
+24 -2
View File
@@ -1,13 +1,35 @@
<?php
// Config screen coming soon
// Show Config Variables for right now
// var_dump(ceo_pluginfo());
?>
<div class="wrap">
<h2><?php _e('Comic Easel - Config','comiceasel'); ?></h2>
<table class="widefat">
<thead>
<tr>
<th colspan="3"><?php _e('Configuration','comiceasel'); ?></th>
<th colspan="3"><?php _e('Variables','comiceasel'); ?></th>
</tr>
</thead>
<tr><td>error</td><td><?php echo ceo_pluginfo('error'); ?></td></tr>
<tr><td>base_url</td><td><?php echo ceo_pluginfo('base_url'); ?></td></tr>
<tr><td>base_path</td><td><?php echo ceo_pluginfo('base_path'); ?></td></tr>
<tr><td>theme_url</td><td><?php echo ceo_pluginfo('theme_url'); ?></td></tr>
<tr><td>theme_path</td><td><?php echo ceo_pluginfo('theme_path'); ?></td></tr>
<tr><td>style_url</td><td><?php echo ceo_pluginfo('style_url'); ?></td></tr>
<tr><td>style_path</td><td><?php echo ceo_pluginfo('style_path'); ?></td></tr>
<tr><td>plugin_url</td><td><?php echo ceo_pluginfo('plugin_url'); ?></td></tr>
<tr><td>plugin_path</td><td><?php echo ceo_pluginfo('plugin_path'); ?></td></tr>
<tr><td>comic_url</td><td><?php echo ceo_pluginfo('comic_url'); ?></td></tr>
<tr><td>comic_path</td><td><?php echo ceo_pluginfo('comic_path'); ?></td></tr>
<tr><td>thumbnail_medium_url</td><td><?php echo ceo_pluginfo('thumbnail_medium_url'); ?></td></tr>
<tr><td>thumbnail_medium_path</td><td><?php echo ceo_pluginfo('thumbnail_medium_path'); ?></td></tr>
<tr><td>thumbnail_small_url</td><td><?php echo ceo_pluginfo('thumbnail_small_url'); ?></td></tr>
<tr><td>thumbnail_small_path</td><td><?php echo ceo_pluginfo('thumbnail_small_path'); ?></td></tr>
<tr><td>comic_folder</td><td><?php echo ceo_pluginfo('comic_folder'); ?></td></tr>
<tr><td>comic_folder_medium</td><td><?php echo ceo_pluginfo('comic_folder_medium'); ?></td></tr>
<tr><td>comic_folder_small</td><td><?php echo ceo_pluginfo('comic_folder_small'); ?></td></tr>
<tr><td>medium_comic_width</td><td><?php echo ceo_pluginfo('medium_comic_width'); ?></td></tr>
<tr><td>small_comic_width</td><td><?php echo ceo_pluginfo('small_comic_width'); ?></td></tr>
<tr><td>add_dashboard_frumph_feed_widget</td><td><?php echo ceo_pluginfo('add_dashboard_frumph_feed_widget'); ?> (1 true, 0 false)</td></tr>
</table>
</div>
+18 -10
View File
@@ -32,10 +32,9 @@ function ceo_add_menu_pages() {
case 'comiceasel-chapter-manager':
add_action('admin_print_scripts-' . $chapter_manager_hook, 'ceo_load_scripts_chapter_manager');
break;
case 'comiceasel-upload':
add_action('admin_print_scripts-' . $upload_hook, 'ceo_load_scripts_upload');
add_action('admin_print_styles-' . $upload_hook, 'ceo_load_styles_upload');
add_action( 'admin_head-settings_page_' . $upload_hook, 'ceo_add_help_upload' );
case 'comiceasel-image-manager':
add_action('admin_print_scripts-' . $image_manager_hook, 'ceo_load_scripts_image_manager');
add_action('admin_print_styles-' . $image_manager_hook, 'ceo_load_styles_image_manager');
break;
}
}
@@ -47,18 +46,15 @@ function ceo_load_scripts_chapter_manager() {
wp_enqueue_script('jquery-ui-sortable');
}
function ceo_load_scripts_upload() {
function ceo_load_scripts_image_manager() {
wp_enqueue_script('comiceasel-fileuploader-script', ceo_pluginfo('plugin_url') .'/js/fileuploader.js');
}
function ceo_load_styles_upload() {
function ceo_load_styles_image_manager() {
wp_enqueue_style('comiceasel-fileuploader-style', ceo_pluginfo('plugin_url') .'/css/fileuploader.css');
}
function ceo_add_help_upload() {
global $current_screen;
add_contextual_help( $current_screen, __( 'Help\'s on the way! Don\'t panic!' ) );
}
// This is done this way to *not* load pages unless they are called, self sufficient code, but since attached to the ceo-core it can use the library in core.
@@ -94,7 +90,19 @@ function ceo_add_dashboard_widgets() {
wp_add_dashboard_widget('ceo_dashboard_widget', 'Frumph.NET News', 'ceo_dashboard_feed_widget');
}
// ajax stuff
// if both logged in and not logged in users can send this AJAX request,
// add both of these actions, otherwise add only the appropriate one
// add_action( 'wp_ajax_nopriv_ceo_comic_upload', 'myajax_submit' );
add_action( 'wp_ajax_ceo_uploader', 'ceo_comic_upload' );
function ceo_comic_upload() {
require_once('functions/uploader.php');
$result = ceo_handleUpload();
// to pass data through iframe you will need to encode all html tags
echo htmlspecialchars(json_encode($result), ENT_NOQUOTES);
exit;
}
?>
+22 -1
View File
@@ -1,3 +1,24 @@
<div class="wrap">
<h2><?php _e('Comic Easel - Image Manager','comiceasel'); ?></h2>
</div>
</div>
<div id="file-uploader-demo1">
<noscript>
<p>Please enable JavaScript to use file uploader.</p>
<!-- or put a simple form for upload here -->
</noscript>
</div>
<script>
function createUploader(){
var uploader = new qq.FileUploader({
element: document.getElementById('file-uploader-demo1'),
action: '<?php echo admin_url( 'admin-ajax.php' ); ?>',
params: {
action: 'ceo_uploader'
}
});
}
// in your app create uploader as soon as the DOM is readyi
// don't wait for the window to load
window.onload = createUploader;
</script>
+3 -2
View File
@@ -33,9 +33,10 @@
function createUploader(){
var uploader = new qq.FileUploader({
element: document.getElementById('file-uploader-demo1'),
action: '<?php echo ceo_pluginfo('plugin_url') ?>/functions/uploader.php',
action: userSettings.ajaxurl,
params: {
userid: userSettings.uid
userid: userSettings.uid,
action: 'ceo_uploader'
},
onSubmit: function(id, fileName){
uploader.setParams({
+4 -14
View File
@@ -7,9 +7,8 @@ function ceo_add_new_comic_columns($comic_columns) {
$new_columns['title'] = _x('Comic Title Name', 'column name');
$new_columns['chapters'] = __('Chapters','easel');
$new_columns['chapter'] = __('Chapter','easel');
$new_columns['characters'] = __('Characters','easel');
$new_columns['locations'] = __('Locations','easel');
$new_columns['tags'] = __('Tags', 'easel');
$new_columns['date'] = _x('Date', 'column name');
@@ -23,9 +22,9 @@ add_action('manage_posts_custom_column', 'ceo_manage_comic_columns', 10, 2);
function ceo_manage_comic_columns($column_name, $id) {
global $wpdb;
switch ($column_name) {
case 'chapters':
case 'chapter':
$allterms = get_the_terms( $id, 'chapters');
if (!empty($allterms) && !isset($allterms->errors)) {
if (!empty($allterms)) {
foreach ($allterms as $term) {
$term_list_chapters[] = '<a href="'.home_url('/wp-admin/edit.php?post_type=comic&chapters='.ceo_clean_filename($term->name)).'">'.$term->name.'</a>';
}
@@ -34,21 +33,12 @@ function ceo_manage_comic_columns($column_name, $id) {
break;
case 'characters':
$allterms = get_the_terms( $id, 'characters');
if (!empty($allterms) && !isset($allterms->errors)) {
if (!empty($allterms)) {
foreach ($allterms as $term) {
$term_list_characters[] = '<a href="'.home_url('/wp-admin/edit.php?post_type=comic&characters='.ceo_clean_filename($term->name)).'">'.$term->name.'</a>';
}
echo join(', ', $term_list_characters );
}
break;
case 'locations':
$allterms = get_the_terms( $id, 'locations');
if (!empty($allterms) && !isset($allterms->errors)) {
foreach ($allterms as $term) {
$term_list_locations[] = '<a href="'.home_url('/wp-admin/edit.php?post_type=comic&places='.ceo_clean_filename($term->name)).'">'.$term->name.'</a>';
}
echo join(', ', $term_list_locations );
}
break;
case 'comicimages':
$comicthumb = '';
+16 -17
View File
@@ -34,13 +34,13 @@ if (!function_exists('ceo_display_comic_navigation')) {
global $post, $wp_query;
if (!ceo_pluginfo('disable_default_comic_nav')) {
$first_comic = ceo_get_first_comic_permalink();
$first_text = __('&lsaquo;&lsaquo; First','comiceasel');
$first_text = __('&lsaquo;&lsaquo; First','comicpress');
$last_comic = ceo_get_last_comic_permalink();
$last_text = __('Last &rsaquo;&rsaquo;','comiceasel');
$last_text = __('Last &rsaquo;&rsaquo;','comicpress');
$next_comic = ceo_get_next_comic_permalink();
$next_text = __('Next &rsaquo;','comiceasel');
$next_text = __('Next &rsaquo;','comicpress');
$prev_comic = ceo_get_previous_comic_permalink();
$prev_text = __('&lsaquo; Prev','comiceasel');
$prev_text = __('&lsaquo; Prev','comicpress');
?>
<div class="nav">
<div class="nav-first"><?php if ( get_permalink() != $first_comic ) { ?><a href="<?php echo $first_comic ?>"><?php echo $first_text; ?></a><?php } else { echo $first_text; } ?></div>
@@ -55,7 +55,7 @@ if (!function_exists('ceo_display_comic_navigation')) {
}
function ceo_display_comic_swf($post, $comic) {
$file_url = ceo_pluginfo('base_url') .'/' . ceo_clean_filename($comic);
$file_url = ceo_pluginfo('baseurl') .'/' . ceo_clean_filename($comic);
$height = get_post_meta( $post->ID, "fheight", true );
$width = get_post_meta( $post->ID, "fwidth", true );
if (empty($height)) $height = '300';
@@ -87,10 +87,10 @@ function ceo_init_comic_swf() {
wp_enqueue_script('swfobject', '', array(), false, true);
}
// This function will let authors who want to use comic easel as a way to output their books/text in a comic area as a page.
// This function will let authors who want to use comicpress as a way to output their books/text in a comic area as a page.
function ceo_display_comic_text($comic) {
if (file_exists(ceo_pluginfo('base_path') . '/' .$comic)) {
$output = nl2br(file_get_contents(ceo_pluginfo('base_path') . '/' .$comic));
if (file_exists(ceo_pluginfo('basedir') . '/' .$comic)) {
$output = nl2br(file_get_contents(ceo_pluginfo('basedir') . '/' .$comic));
}
return apply_filters('ceo_display_comic_text', $output);
}
@@ -120,7 +120,7 @@ function ceo_display_comic_thumbnail($type = 'small', $override_post = null, $us
$thumbnail = array();
if (!empty($thumb_found)) {
foreach ($thumb_found as $thumb) {
$thumbnail[] = ceo_pluginfo('base_url') . '/' . ceo_clean_filename($thumb);
$thumbnail[] = ceo_pluginfo('baseurl') . '/' . ceo_clean_filename($thumb);
}
}
}
@@ -153,7 +153,7 @@ function ceo_display_comic_thumbnail($type = 'small', $override_post = null, $us
// TODO: Add the hovertext - rascal code and click to next INSIDE this.
function ceo_display_comic_image($post, $comic) {
$file_url = ceo_pluginfo('base_url') .'/'. ceo_clean_filename($comic);
$file_url = ceo_pluginfo('baseurl') .'/'. ceo_clean_filename($comic);
if (ceo_pluginfo('rascal_says')) {
$alt_text = get_the_title($post);
} else {
@@ -167,7 +167,6 @@ function ceo_display_comic_image($post, $comic) {
function ceo_display_comic() {
global $post;
$comics = get_comic_path('comic', $post);
$output = '';
if (is_array($comics)) {
$count = 1;
$outputlist = '';
@@ -287,7 +286,7 @@ function get_comic_path($folder = 'comic', $override_post = null, $filter = 'def
case "comic": default: $subfolder_to_use = ceo_pluginfo('comic_folder'); break;
}
$folder_to_use = ceo_pluginfo('base_path') . '/' . $subfolder_to_use;
$folder_to_use = ceo_pluginfo('basedir') . '/' . $subfolder_to_use;
// if (!file_exists($folder_to_use . '/' . $comicfile) && $folder !== 'comic')
// $subfolder_to_use = ceo_pluginfo('comic_folder');
@@ -320,25 +319,25 @@ function get_comic_path($folder = 'comic', $override_post = null, $filter = 'def
$newresults = array();
foreach ($results as $result) {
// Strip the base directory off.
$newresults[] = str_replace(ceo_pluginfo('base_path'), '', $result);
$newresults[] = str_replace(ceo_pluginfo('basedir'), '', $result);
}
return $newresults;
} else {
// fallback to the comics directory
$folder_to_use = ceo_pluginfo('base_path') . '/' . ceo_pluginfo('comic_folder');
$folder_to_use = ceo_pluginfo('basedir') . '/' . ceo_pluginfo('comic_folder');
if (count($results = glob("${folder_to_use}/${filter_with_date}")) > 0) {
$newresults = array();
foreach ($results as $result) {
// Strip the base directory off.
$newresults[] = str_replace(ceo_pluginfo('base_path'), '', $result);
$newresults[] = str_replace(ceo_pluginfo('basedir'), '', $result);
}
return $newresults;
}
}
}
$comic_pathfinding_errors[] = sprintf(__("Unable to find the file in the <strong>%s</strong> folder that matched the pattern <strong>%s</strong>. Check your WordPress and ComicPress settings.", 'comiceasel'), $folder_to_use, $filter_with_date);
$comic_pathfinding_errors[] = sprintf(__("Unable to find the file in the <strong>%s</strong> folder that matched the pattern <strong>%s</strong>. Check your WordPress and ComicPress settings.", 'comicpress'), $folder_to_use, $filter_with_date);
return false;
}
@@ -354,7 +353,7 @@ function get_comic_url($folder = 'comic', $override_post = null, $filter = 'defa
if (($results = get_comic_path($folder, $override_post, $filter)) !== false) {
$newresults = array();
foreach ($results as $result) {
$newresults[] = ceo_pluginfo('base_url') .'/'. $result;
$newresults[] = ceo_pluginfo('baseurl') .'/'. $result;
}
return $newresults;
}
+3 -31
View File
@@ -22,7 +22,7 @@ function ceo_edit_post_category($post_category) {
return $post_category;
}
add_action('easel-content-area', 'ceo_display_comic_area');
// add_action('easel-content-area', 'ceo_display_comic_area');
function ceo_display_comic_area() {
global $wp_query;
@@ -51,11 +51,9 @@ function ceo_display_comic_wrapper() {
<div id="comic-wrap">
<div id="comic-head"></div>
<div id="comic">
<?php echo ceo_display_comic(); ?>
</div>
<div id="comic-foot">
<?php ceo_display_comic_navigation(); ?>
<?php the_title(); ?>
</div>
<div id="comic-foot"></div>
</div>
<?php }
}
@@ -76,30 +74,4 @@ function ceo_display_comic_post_home() {
}
}
function ceo_display_characters() {
global $post;
$before = '<div class="characters">Characters: ';
$sep = ', ';
$after = '</div>';
$output = get_the_term_list( $post->ID, 'characters', $before, $sep, $after );
return $output;
}
function ceo_display_locations() {
global $post;
$before = '<div class="location">Location: ';
$sep = ', ';
$after = '</div>';
$output = get_the_term_list( $post->ID, 'locations', $before, $sep, $after );
return $output;
}
function ceo_display_comic_info() {
$output = ceo_display_characters();
$output .= ceo_display_locations();
echo $output;
}
add_action('easel-post-info', 'ceo_display_comic_info');
?>
+1 -1
View File
@@ -145,7 +145,7 @@ function ceo_get_adjacent_comic($in_same_chapter = false, $previous = true, $exc
$order = $previous ? 'DESC' : 'ASC';
$join = apply_filters( "get_{$adjacent}_comic_join", $join, $in_same_chapter, $excluded_chapters );
$where = apply_filters( "get_{$adjacent}_comic_where", $wpdb->prepare("WHERE p.post_date $op %s AND p.post_type = %s AND p.post_status = 'publish' $posts_in_ex_cats_sql", $current_post_date, $post->post_type), $in_same_chapter, $excluded_chapters );
$where = apply_filters( "get_{$adjacent}_comic_where", $wpdb->prepare("WHERE p.post_date $op %s AND p.post_type = %s AND p.post_status = 'publish' $posts_in_ex_cats_sql", $current_post_date, $post->post_type), $in_same_cat, $excluded_categories );
$sort = apply_filters( "get_{$adjacent}_comic_sort", "ORDER BY p.post_date $order LIMIT 1" );
$query = "SELECT p.* FROM $wpdb->posts AS p $join $where $sort";
-26
View File
@@ -1,9 +1,6 @@
<?php
require_once( "../../../../wp-load.php" );
include_once('easyphpthumbnail.class.php');
class ceo_UploadFileXhr {
function save($path){
$input = fopen("php://input", "r");
@@ -83,29 +80,6 @@ function ceo_handleUpload(){
$thumb -> Createthumb(ceo_pluginfo('comic_path') .'/'. $filename . '.' . $ext,'file');
}
//generate post for comic
//need to add more data for the post from the uploader form here.
$post = array(
'post_content' => $_REQUEST['content'], //The full text of the post.
'post_title' => $_REQUEST['title'], //The title of your post.
'post_type' => 'comic',
'post_author' => $_REQUEST['userid'],
'post_status' => 'publish',
'post_date' => $_REQUEST['date'] .' '. $_REQUEST['time'],
'tags_input' => $_REQUEST['tags']
);
$newpost = wp_insert_post( $post );
$chapter = get_term_by('id', $_REQUEST['chapter'], 'chapters');
wp_set_object_terms( $newpost, $chapter->slug , 'chapters', false);
add_post_meta($newpost, 'comic', $filename . '.' . $ext);
return array(success=>true);
}
$result = ceo_handleUpload();
// to pass data through iframe you will need to encode all html tags
echo htmlspecialchars(json_encode($result), ENT_NOQUOTES);
+173 -281
View File
@@ -4,7 +4,7 @@
* Multiple file upload component with progress-bar, drag-and-drop.
* © 2010 Andrew Valums andrew(at)valums.com
*
* Licensed under GNU GPL 2 or later, see license.txt.
* Licensed under GNU GPL.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
@@ -100,7 +100,7 @@ qq.FileUploader = function(o){
var self = this;
this._button = new qq.UploadButton({
element: this._getElement('button'),
multiple: qq.UploadHandlerXhr.isSupported(),
//multiple: qq.UploadHandlerXhr.isSupported(),
onChange: function(input){
self._onInputChange(input);
}
@@ -172,56 +172,86 @@ qq.FileUploader.prototype = {
return false;
},
_setupDragDrop: function(){
function isValidDrag(e){
var dt = e.dataTransfer,
// do not check dt.types.contains in webkit, because it crashes safari 4
isWebkit = navigator.userAgent.indexOf("AppleWebKit") > -1;
// dt.effectAllowed is none in Safari 5
// dt.types.contains check is for firefox
return dt && dt.effectAllowed != 'none' &&
(dt.files || (!isWebkit && dt.types.contains && dt.types.contains('Files')));
}
var self = this,
dropArea = this._getElement('drop');
var dz = new qq.FileDropZone({
element: dropArea,
onEnter: function(e){
qq.addClass(dropArea, self._classes.dropActive);
e.stopPropagation();
},
onLeave: function(e){
e.stopPropagation();
},
onLeaveNotDescendants: function(e){
qq.removeClass(dropArea, self._classes.dropActive);
},
onDrop: function(e){
dropArea.style.display = 'none';
qq.removeClass(dropArea, self._classes.dropActive);
self._uploadFileList(e.dataTransfer.files);
}
});
dropArea.style.display = 'none';
var hideTimeout;
qq.attach(document, 'dragenter', function(e){
e.preventDefault();
});
qq.attach(document, 'dragenter', function(e){
if (!dz._isValidFileDrag(e)) return;
dropArea.style.display = 'block';
qq.attach(document, 'dragover', function(e){
if (isValidDrag(e)){
if (hideTimeout){
clearTimeout(hideTimeout);
}
if (dropArea == e.target || qq.contains(dropArea,e.target)){
var effect = e.dataTransfer.effectAllowed;
if (effect == 'move' || effect == 'linkMove'){
e.dataTransfer.dropEffect = 'move'; // for FF (only move allowed)
} else {
e.dataTransfer.dropEffect = 'copy'; // for Chrome
}
qq.addClass(dropArea, self._classes.dropActive);
e.stopPropagation();
} else {
dropArea.style.display = 'block';
e.dataTransfer.dropEffect = 'none';
}
e.preventDefault();
}
});
qq.attach(document, 'dragleave', function(e){
if (!dz._isValidFileDrag(e)) return;
var relatedTarget = document.elementFromPoint(e.clientX, e.clientY);
// only fire when leaving document out
if ( ! relatedTarget || relatedTarget.nodeName == "HTML"){
dropArea.style.display = 'none';
}
});
qq.attach(document, 'dragleave', function(e){
if (isValidDrag(e)){
if (dropArea == e.target || qq.contains(dropArea,e.target)){
qq.removeClass(dropArea, self._classes.dropActive);
e.stopPropagation();
} else {
if (hideTimeout){
clearTimeout(hideTimeout);
}
hideTimeout = setTimeout(function(){
dropArea.style.display = 'none';
}, 77);
}
}
});
qq.attach(dropArea, 'drop', function(e){
dropArea.style.display = 'none';
self._uploadFileList(e.dataTransfer.files);
e.preventDefault();
});
},
_createUploadHandler: function(){
var self = this,
handlerClass;
if(qq.UploadHandlerXhr.isSupported()){
handlerClass = 'UploadHandlerXhr';
} else {
//if(qq.UploadHandlerXhr.isSupported()){
// handlerClass = 'UploadHandlerXhr';
//} else {
handlerClass = 'UploadHandlerForm';
}
//}
var handler = new qq[handlerClass]({
action: this._options.action,
@@ -255,17 +285,17 @@ qq.FileUploader.prototype = {
},
_onInputChange: function(input){
if (this._handler instanceof qq.UploadHandlerXhr){
this._uploadFileList(input.files);
} else {
//if (this._handler instanceof qq.UploadHandlerXhr){
//
// this._uploadFileList(input.files);
//
//} else {
if (this._validateFile(input)){
this._uploadFile(input);
}
}
//}
this._button.reset();
},
@@ -288,7 +318,8 @@ qq.FileUploader.prototype = {
_uploadFile: function(fileContainer){
var id = this._handler.add(fileContainer);
var name = this._handler.getName(id);
this._options.onSubmit(id, name);
if (false == this._options.onSubmit(id, name))
return false;
this._addToList(id, name);
this._handler.upload(id, this._options.params);
},
@@ -391,91 +422,6 @@ qq.FileUploader.prototype = {
}
};
qq.FileDropZone = function(o){
this._options = {
element: null,
onEnter: function(e){},
onLeave: function(e){},
// is not fired when leaving element by hovering descendants
onLeaveNotDescendants: function(e){},
onDrop: function(e){}
};
qq.extend(this._options, o);
this._element = this._options.element;
this._disableDropOutside();
this._attachEvents();
};
qq.FileDropZone.prototype = {
_disableDropOutside: function(e){
// run only once for all instances
if (!qq.FileDropZone.dropOutsideDisabled ){
qq.attach(document, 'dragover', function(e){
e.dataTransfer.dropEffect = 'none';
e.preventDefault();
});
qq.FileDropZone.dropOutsideDisabled = true;
}
},
_attachEvents: function(){
var self = this;
qq.attach(self._element, 'dragover', function(e){
if (!self._isValidFileDrag(e)) return;
var effect = e.dataTransfer.effectAllowed;
if (effect == 'move' || effect == 'linkMove'){
e.dataTransfer.dropEffect = 'move'; // for FF (only move allowed)
} else {
e.dataTransfer.dropEffect = 'copy'; // for Chrome
}
e.stopPropagation();
e.preventDefault();
});
qq.attach(self._element, 'dragenter', function(e){
if (!self._isValidFileDrag(e)) return;
self._options.onEnter(e);
});
qq.attach(self._element, 'dragleave', function(e){
if (!self._isValidFileDrag(e)) return;
self._options.onLeave(e);
var relatedTarget = document.elementFromPoint(e.clientX, e.clientY);
// do not fire when moving a mouse over a descendant
if (qq.contains(this, relatedTarget)) return;
self._options.onLeaveNotDescendants(e);
});
qq.attach(self._element, 'drop', function(e){
if (!self._isValidFileDrag(e)) return;
e.preventDefault();
self._options.onDrop(e);
});
},
_isValidFileDrag: function(e){
var dt = e.dataTransfer,
// do not check dt.types.contains in webkit, because it crashes safari 4
isWebkit = navigator.userAgent.indexOf("AppleWebKit") > -1;
// dt.effectAllowed is none in Safari 5
// dt.types.contains check is for firefox
return dt && dt.effectAllowed != 'none' &&
(dt.files || (!isWebkit && dt.types.contains && dt.types.contains('Files')));
}
};
qq.UploadButton = function(o){
this._options = {
element: null,
@@ -535,11 +481,8 @@ qq.UploadButton.prototype = {
// the right side of the input
right: 0,
top: 0,
fontFamily: 'Arial',
// when button is big it becomes visible in IE8 on SOME PCs
// probably related to http://social.msdn.microsoft.com/forums/en-US/iewebdevelopment/thread/29d0b0e7-4326-4b3e-823c-51420d4cf253
// three persons reported this, the max values that worked for them were 243, 236, 236
fontSize: '222px',
zIndex: 1,
fontSize: '460px',
margin: 0,
padding: 0,
cursor: 'pointer',
@@ -732,7 +675,10 @@ qq.UploadHandlerForm.prototype = {
// Because in this case file won't be attached to request
var form = qq.toElement('<form method="post" enctype="multipart/form-data"></form>');
var queryString = '?' + qq.obj2url(params);
var queryString = '?';
for (var key in params){
queryString += '&' + key + '=' + encodeURIComponent(params[key]);
}
form.setAttribute('action', this._options.action + queryString);
form.setAttribute('target', iframe.name);
@@ -746,119 +692,115 @@ qq.UploadHandlerForm.prototype = {
/**
* Class for uploading files using xhr
*/
qq.UploadHandlerXhr = function(o){
this._options = {
// url of the server-side upload script,
//qq.UploadHandlerXhr = function(o){
// this._options = {
// // url of the server-side upload script,
// should be on the same domain
action: '/upload',
onProgress: function(id, fileName, loaded, total){},
onComplete: function(id, fileName, response){}
};
qq.extend(this._options, o);
// action: '/upload',
// onProgress: function(id, fileName, loaded, total){},
// onComplete: function(id, fileName, response){}
// };
// qq.extend(this._options, o);
this._files = [];
this._xhrs = [];
};
// this._files = [];
// this._xhrs = [];
//};
// static method
qq.UploadHandlerXhr.isSupported = function(){
var input = document.createElement('input');
input.type = 'file';
return (
'multiple' in input &&
typeof File != "undefined" &&
typeof (new XMLHttpRequest()).upload != "undefined" );
};
//qq.UploadHandlerXhr.isSupported = function(){
// return typeof File != "undefined" &&
// typeof (new XMLHttpRequest()).upload != "undefined";
//};
qq.UploadHandlerXhr.prototype = {
//qq.UploadHandlerXhr.prototype = {
/**
* Adds file to the queue
* Returns id to use with upload, cancel
**/
add: function(file){
return this._files.push(file) - 1;
},
// add: function(file){
// return this._files.push(file) - 1;
// },
/**
* Sends the file identified by id and additional query params to the server
* @param {Object} params name-value string pairs
*/
upload: function(id, params){
var file = this._files[id],
name = this.getName(id),
size = this.getSize(id);
if (!file){
throw new Error('file with passed id was not added, or already uploaded or cancelled');
}
var xhr = this._xhrs[id] = new XMLHttpRequest();
var self = this;
xhr.upload.onprogress = function(e){
if (e.lengthComputable){
self._options.onProgress(id, name, e.loaded, e.total);
}
};
// upload: function(id, params){
// var file = this._files[id],
// name = this.getName(id),
// size = this.getSize(id);
//
// if (!file){
// throw new Error('file with passed id was not added, or already uploaded or cancelled');
// }
//
// var xhr = this._xhrs[id] = new XMLHttpRequest();
// var self = this;
//
// xhr.upload.onprogress = function(e){
// if (e.lengthComputable){
// self._options.onProgress(id, name, e.loaded, e.total);
// }
// };
xhr.onreadystatechange = function(){
// xhr.onreadystatechange = function(){
// the request was aborted/cancelled
if (!self._files[id]){
return;
}
if (xhr.readyState == 4){
// if (!self._files[id]){
// return;
// }
// if (xhr.readyState == 4){
self._options.onProgress(id, name, size, size);
// self._options.onProgress(id, name, size, size);
if (xhr.status == 200){
var response;
try {
response = eval("(" + xhr.responseText + ")");
} catch(err){
response = {};
}
self._options.onComplete(id, name, response);
} else {
self._options.onComplete(id, name, {});
}
self._files[id] = null;
self._xhrs[id] = null;
}
};
// if (xhr.status == 200){
// var response;
//
// try {
// response = eval("(" + xhr.responseText + ")");
// } catch(err){
// response = {};
// }
//
// self._options.onComplete(id, name, response);
//
// } else {
// self._options.onComplete(id, name, {});
// }
//
// self._files[id] = null;
// self._xhrs[id] = null;
// }
// };
// build query string
var queryString = '?qqfile=' + encodeURIComponent(name) + '&' + qq.obj2url(params);
xhr.open("POST", this._options.action + queryString, true);
xhr.setRequestHeader("X-Requested-With", "XMLHttpRequest");
xhr.setRequestHeader("X-File-Name", encodeURIComponent(name));
xhr.send(file);
},
cancel: function(id){
this._files[id] = null;
if (this._xhrs[id]){
this._xhrs[id].abort();
this._xhrs[id] = null;
}
},
getName: function(id){
// var queryString = '?qqfile=' + encodeURIComponent(name);
// for (var key in params){
// queryString += '&' + key + '=' + encodeURIComponent(params[key]);
// }
//
// xhr.open("GET", this._options.action + queryString, true);
// xhr.setRequestHeader("X-File-Name", encodeURIComponent(name));
// xhr.send(file);
// },
// cancel: function(id){
// this._files[id] = null;
//
// if (this._xhrs[id]){
// this._xhrs[id].abort();
// this._xhrs[id] = null;
// }
// },
// getName: function(id){
// fix missing name in Safari 4
var file = this._files[id];
return file.fileName != null ? file.fileName : file.name;
},
getSize: function(id){
// var file = this._files[id];
// return file.fileName != null ? file.fileName : file.name;
// },
// getSize: function(id){
// fix missing size in Safari 4
var file = this._files[id];
return file.fileSize != null ? file.fileSize : file.size;
}
};
// var file = this._files[id];
// return file.fileSize != null ? file.fileSize : file.size;
// }
//};
//
// Helper functions
@@ -926,10 +868,7 @@ qq.remove = function(element){
element.parentNode.removeChild(element);
};
qq.contains = function(parent, descendant){
// compareposition returns false in this case
if (parent == descendant) return true;
qq.contains = function(parent, descendant){
if (parent.contains){
return parent.contains(descendant);
} else {
@@ -1017,50 +956,3 @@ qq.getByClass = function(element, className){
}
return result;
};
/**
* obj2url() takes a json-object as argument and generates
* a querystring. pretty much like jQuery.param()
*
* @param Object JSON-Object
* @param String current querystring-part
* @return String encoded querystring
*/
qq.obj2url = function(obj, temp){
var uristrings = [],
add = function(nextObj, i){
var nextTemp = temp
? (/\[\]$/.test(temp)) // prevent double-encoding
? temp
: temp+'['+i+']'
: i;
uristrings.push(typeof nextObj === 'object'
? qq.obj2url(nextObj, nextTemp)
: (Object.prototype.toString.call(nextObj) === '[object Function]')
? encodeURIComponent(nextTemp) + '=' + encodeURIComponent(nextObj())
: encodeURIComponent(nextTemp) + '=' + encodeURIComponent(nextObj));
};
if (Object.prototype.toString.call(obj) === '[object Array]'){
// we wont use a for-in-loop on an array (performance)
for (var i = 0, len = obj.length; i < len; ++i){
add(obj[i], i);
}
} else if ((obj !== undefined) &&
(obj !== null) &&
(typeof obj === "object")){
// for anything else but a scalar, we will use for-in-loop
for (var i in obj){
add(obj[i], i);
}
} else {
uristrings.push(encodeURIComponent(temp) + '=' + encodeURIComponent(obj));
}
return uristrings.join('&').replace(/%20/g, '+');
};