<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" dir="ltr">
<head>
    <meta http-equiv="content-type" content="text/html; charset=utf-8"/>
    <title>Plupload - jQuery UI Widget</title>
    <link rel="stylesheet" href="{R}libs/jquery-ui/jquery-ui.min.css" type="text/css" />
    <link rel="stylesheet" href="{R}libs/html5upload/jquery.ui.plupload/css/jquery.ui.plupload.css" type="text/css" />
    <script type="text/javascript">
        var cookie_pre = "{COOKIE_PRE}";var cookie_domain = '{COOKIE_DOMAIN}';var cookie_path = '{COOKIE_PATH}';var web_url = '{WEBURL}';var callback_func = '{$callback}';
        var is_admin = {$is_admin};
    </script>
    <script src="{R}libs/jquery/jquery.min.js"></script>
    <script type="text/javascript" src="{R}libs/jquery-ui/jquery-ui.min.js"></script>
    <!-- production -->
    <script type="text/javascript" src="{R}libs/html5upload/plupload.full.min.js"></script>
    <script type="text/javascript" src="{R}libs/html5upload/jquery.ui.plupload/jquery.ui.plupload.js"></script>
    <script type="text/javascript" src="{R}libs/html5upload/i18n/zh_cn.js"></script>
    <script type="text/javascript" src="{R}libs/html5upload/extension.js"></script>
</head>
<body>
<div id="uploader">
    <p>Your browser doesn't have Flash, Silverlight or HTML5 support.</p>
</div>

<script type="text/javascript">
    // Initialize the widget when the DOM is ready
    var uplodfiles = '';
    $(function() {
        $("#uploader").plupload({
            // General settings
            runtimes : 'html5,flash,silverlight,html4',
            url : '{WEBURL}index.php?m=attachment&f=index&v=h5upload&is_thumb={$is_thumb}&cut={$cut}&width={$width}&height={$height}&ext={$ext}&token={$token}',
            // User can upload no more then 20 files in one go (sets multiple_queues to false)
            max_file_count: {$limit},
            chunk_size: '1mb',
            filters : {
                // Maximum file size
                max_file_size : '{$maxsize}',
                // Specify what files to browse for
                mime_types: [
                         {title : "Image files", extensions : "{$extImages}"},
                         {title : "Compression files", extensions : "{$extCompression}"},
                         {title : "files", extensions : "{$extFile}"},
                         {title : "Video", extensions : "{$extVideo}"},
                            ]
                },
            init: {
                 FileUploaded: function(up, file, info) {
                     myres = JSON.parse(info.response);
                     if(myres['error']) {
                     alert(myres['error']['message']);
                          return ;
                     }
                     if(myres['result']) {
                         <?php if($callback == 'callback_ck_images'):?>
                         uplodfiles += myres['result'] + '|';
                         <?php else: ?>
                         if ({$limit} > 1) {
                             uplodfiles += myres['result'] + ',' + myres['filename'] + ',' + myres['id'] + '|';
                         } else {
                             uplodfiles += myres['result'] + '|';
                         }
                         <?php endif; ?>
                     }},
                 UploadComplete: function() {
                    if(uplodfiles!='') {
                        uplodfiles = uplodfiles.substring(0, uplodfiles.lastIndexOf('|'));
                     }
                    {$callback}(uplodfiles,'{$htmlid}','{$is_thumb}','{$htmlname}');
                    //console.info(uplodfiles);
                    //console.info(file);
                    }},
                    // Rename files by clicking on their titles
                    rename: true,
                    // Sort files
                    sortable: true,

                    // Enable ability to drag'n'drop files onto the widget (currently only HTML5 supports that)
                    dragdrop: true,

                    // Views to activate
                    views: {
                        list: true,
                                thumbs: true, // Show thumbs
                                active: 'thumbs'
                    },

                        // Flash settings
                    flash_swf_url : '{R}libs/html5upload/Moxie.swf',

                    // Silverlight settings
                    silverlight_xap_url : '{R}libs/html5upload/Moxie.xap'
                    });
                });

                var dialog = '';
                $(function () {
                    try {
                        dialog = top.dialog.get(window);
                    } catch (e) {
                        $('body').append(
                                '<p><strong>Error:</strong> 跨域无法无法操作 iframe 对象</p>'
                                +'<p>chrome 浏览器本地会认为跨域，请使用 http 方式访问当前页面</p>'
                        );
                        return;
                    }

                    dialog.title('上传附件');
                    //dialog.width(550);
                    //dialog.height($(document).height());
                    dialog.reset();
                })

</script>
</body>
</html>
