<!DOCTYPE html>
<!--[if IE 8]>
<html lang="en" class="ie8 no-js"> <![endif]-->
<!--[if IE 9]>
<html lang="en" class="ie9 no-js"> <![endif]-->
<!--[if !IE]><!-->
<html>
<!--<![endif]-->
<!-- BEGIN HEAD -->
<head>
    <base href="#springUrl('/assets/adminlte/')"/>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <title>工作台</title>
    <!-- Tell the browser to be responsive to screen width -->
    <meta content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no" name="viewport">
    <!-- Bootstrap 3.3.5 -->
    <link rel="stylesheet" href="bootstrap/css/bootstrap.min.css">
    <!-- Font Awesome -->
    <link rel="stylesheet" href="plugins/font-awesome/css/font-awesome.min.css">
    <!-- Ionicons -->
    <link rel="stylesheet" href="plugins/ionicons/css/ionicons.min.css">

    <!-- DataTables -->
    <link rel="stylesheet" href="plugins/datatables/dataTables.bootstrap.css">

    <!-- Theme style -->
    <link rel="stylesheet" href="dist/css/AdminLTE.min.css">
    <!-- AdminLTE Skins. Choose a skin from the css/skins
         folder instead of downloading all of them to reduce the load. -->
    <link rel="stylesheet" href="dist/css/skins/_all-skins.min.css">
    <!-- iCheck -->
    <link rel="stylesheet" href="plugins/iCheck/flat/blue.css">
    <!-- Date Picker -->
    <link rel="stylesheet" href="plugins/datepicker/datepicker3.css">
    <!-- Daterange picker -->
    <link rel="stylesheet" href="plugins/daterangepicker/daterangepicker-bs3.css">
    <!-- bootstrap wysihtml5 - text editor -->
    <link rel="stylesheet" href="plugins/bootstrap-wysihtml5/bootstrap3-wysihtml5.min.css">
    <!--validate css-->
    <link rel="stylesheet" href="plugins/jquery-validation/css/validate.css">
    <!--fileinput css-->
    <link rel="stylesheet" href="plugins/bootstrap-fileinput/bootstrap-fileinput.css">
    <!-- HTML5 Shim and Respond.js IE8 support of HTML5 elements and media queries -->
    <!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
    <!--[if lt IE 9]>
    <script src="https://oss.maxcdn.com/html5shiv/3.7.3/html5shiv.min.js"></script>
    <script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
    <script type="text/javascript" charset="utf-8"
            src="plugins/ueditor-min-1.4.3/p/main.js"></script>
    <script type="text/javascript" charset="utf-8"
            src="plugins/ueditor-min-1.4.3/q/main.js"></script>
    <![endif]-->

</head>
<style>


    #foo th {
        border: 1px #ccc solid;
        background: #FFFAF0;
    }

    #foo td {
        border: 1px #ccc solid;
        text-align: center;
    }

    .fileupload .thumbnail {
        overflow: hidden;
        display: inline-block;
        margin-bottom: 5px;
        vertical-align: middle;
        text-align: center;
    }

    .thumbnail {
        display: block;
        padding: 4px;
        line-height: 1.42857143;
        background-color: #fff;
        border: 0;
        -webkit-transition: all .2s ease-in-out;
        -o-transition: all .2s ease-in-out;
        transition: all .2s ease-in-out;
        margin-bottom: 5px;
        width: 200px;
        height: 150px;
        line-height: 150px;
        position: relative;
        text-align: center;

    }

    .thumbnail img {
        max-height: 100%;
    }

    .parentThumbnail {
        border: 1px solid #ddd;
        border-radius: 4px;
        margin-right: 10px;
        float: left;
    }

    .thumbnail .delRemove {
        width: 192px;
        height: 30px;
        opacity: 0.7;
        background: #000;
        position: absolute;
        text-align: center;
        line-height: 30px;
        color: #fff;
        font-size: 14px;
        cursor: pointer;
        display: none;
    }

    .parentThumbnail .delRemove:hover {
        background: #5c5c5c;
    }

    .previewImg {
        border: 0px;
        display: none;
        z-index: 999;
        max-height: 100%;
        max-width: 100%
    }

    .parentThumbnail textarea {
        width: 200px;
    }

    .imgSelect {
        text-align: center;
        border: 1px #ddd solid;
        position: relative;
    }
    .list-group{
        margin-top: 20px;
        width: 30%;
    }
</style>
<!-- END HEAD -->
<body class="hold-transition skin-blue sidebar-mini">
<div id="hiddenDiv" style="display:none">$!{data.content}</div>
<div class="wrapper">
    <div class="content-wrapper" style="margin-left:0;">

        <section class="content-header">
            <h1>
                内容管理
                <small>图集管理</small>
            </h1>
            <ol class="breadcrumb">
                <li><a href="#"><i class="fa fa-dashboard"></i>首页</a></li>
                <li><a class="active">图集管理</a></li>
            </ol>
        </section>


        <!-- Main content -->
        <section class="content">
            <div class="row">
                <div class="col-xs-12">
                    <!-- general form elements disabled -->
                    <div class="box box-primary">
                        <form role="form" id="myForm">
                            <input name="id" value="$!{data.id}" hidden="true"/>
                            <div class="box-body">
                                <div class="form-group form-md-line-input">
                                    <label>文章标题</label>
                                    <input type="text"
                                           class="form-control" name="title"
                                           id="title"
                                           maxlength="200" placeholder="文章标题"
                                           value="$!{data.title}"
                                           required="required"
                                    >

                                </div>
                                <div class="form-group form-md-line-input">
                                    <label>作者</label>
                                    <input type="text"
                                           class="form-control" name="author"
                                           id="author"
                                           maxlength="20" placeholder="文章作者"
                                           value="$!{data.author}">

                                </div>

                                <input type="text" style="display: none" name="_csrf" value="${_csrf.token}"/>
                                <input  type="text" style="display: none" name="_csrf_header" value="${_csrf.headerName}"/>


                                <div class="form-group form-md-line-input">
                                    <label>文章大图封面(建议360*200)</label>
                                    <div class="input-group">
                                        <input type="text"
                                               class="form-control" name="bigimg" style="display: none;"
                                               id="bigimg"
                                               maxlength="500" placeholder="文章大图封面"
                                               value="$!{data.bigimg}"
                                        >
                                        <!--<span class="input-group-btn">-->
                                        <!--<button type="button" id="bigImgSelect"-->
                                        <!--class="btn btn-info btn-flat">选择</button>-->
                                        <!--</span>-->
                                    </div>
                                    <div id="bigImgSelect"
                                         class="imgSelect" style="width: 360px;height: 200px;line-height: 200px">
                                        <i class="fa fa-plus" style="font-size:50px;color:#ccc"></i>
                                        <img class="previewImg"
                                             id="previewBigImg"/>
                                    </div>
                                </div>
                                <div class="form-group form-md-line-input">
                                    <label>文章小图封面(建议200*200)</label>
                                    <div class="input-group">
                                        <input type="text" style="display: none;"
                                               class="form-control" name="smallimg"
                                               id="smallimg"
                                               maxlength="500" placeholder="文章小图封面"
                                               value="$!{data.smallimg}"
                                        >

                                        <!--<span class="input-group-btn">-->
                                        <!--<button type="button" id="smallImgSelect"-->
                                        <!--class="btn btn-info btn-flat">选择</button>-->
                                        <!--</span>-->
                                    </div>
                                    <div id="smallImgSelect"
                                         class="imgSelect" style="width: 200px;height: 200px;line-height: 200px">
                                        <i class="fa fa-plus" style="font-size:50px;color:#ccc"></i>
                                        <img src=""
                                             class="previewImg"
                                             id="previewSmallImg"/>
                                    </div>
                                </div>

                                <label style="width: 100%">图集图片<font style="font-size: 12px;" color="red">（拖动可排序,点击可更换）</font></label>
                                <div class="form-group form-md-line-input" id="foo">
                                </div>
                                <div class="parentThumbnail addParentThumbnail">
                                    <div class="fileupload-preview thumbnail"
                                         style="color: #ccc;text-align: center;">
                                        <i class="fa fa-picture-o"
                                           style="font-size: 50px;margin: 0px auto;width: 100%;float:left;"></i>
                                        <span>建议最多添加10张图片</span>
                                    </div>
                                </div>


                                <!--<div class="form-group form-md-line-input" style="clear: both">-->
                                <!--<label>文章内容<font style="font-size: 13px;" color="#5f9ea0">* 建议最多10张图片,尺寸为640*480【图片比例4:3,高：宽】,大小在300KB以内</font></label>-->
                                <!--<table id="prizes" class="table table-bordered table-striped dataTable no-footer">-->
                                <!--<th style="text-align: center">图片</th>-->
                                <!--<th>描述</th>-->
                                <!--<th>操作</th>-->
                                <!--</table>-->
                                <!--<p id="addPrizes" style="width:100%;text-align:center"><a-->
                                <!--href="javascript:void(0)">添加图片</a></p>-->

                                <!--</div>-->
                                <div class="form-group form-md-line-input" style="clear: both">
                                    <label>文章描述</label>
                                    <input type="text"
                                           class="form-control" name="desc"
                                           id="desc"
                                           maxlength="300" placeholder="文章描述"
                                           value="$!{data.desc}"
                                           required="required"
                                    >
                                </div>

                                <input value="1" style="display: none;" name="type"/>
                                <div class="form-group form-md-line-input" id="relationCfArticleDiv">
                                    <label>关联文章</label>
                                    <input type="text" style="display:none"
                                           class="form-control" name="relation_article"
                                           id="relation_article"
                                           placeholder="关联文章"
                                           value="$!{data.relation_article}"
                                           required="required"
                                    >
                                    <input type="text" style="display:none"
                                           class="form-control" name="relation_article_name"
                                           id="relation_article_name"
                                           placeholder="关联文章"
                                           value="$!{relationArticlesStr}"
                                           required="required"
                                    >

                                    <span class="input-group-btn">
                                            <button type="button" id="cfArticleSelect"
                                                    class="btn btn-info btn-flat">&nbsp;选&nbsp;择&nbsp;</button>
                                    </span>
                                    #if($relationArticles)
                                    <div class='list-group'>
                                        #foreach( $relation in $relationArticles )
                                        <p class="list-group-item">$relation</p>
                                        #end
                                    </div>
                                    #end
                                </div>
                                <div class="form-group form-md-line-input">
                                    <label>所属栏目</label>
                                    <div class="input-group">
                                        <input type="text" name="column" id="column"
                                               value="$!{data.column}"
                                               class="form-control" style="display: none">
                                        <input type="text" id="columnName"
                                               name="columnName" value="$!{columnName}"
                                               class="form-control" disabled>
                                        <span class="input-group-btn">
                                            <button type="button" id="columnSelect"
                                                    class="btn btn-info btn-flat">选择</button>
                                         </span>
                                    </div>

                                </div>
                                <div class="form-group form-md-line-input">
                                    <label>阅读全文链接</label>
                                    #if($data.isUrl=='0')
                                    <input type="checkbox" name="isUrl" checked value="0">作为微信被动回复消息时,图文直接跳转到此链接
                                    #else
                                    <input type="checkbox" name="isUrl" value="0">作为微信被动回复消息时,图文直接跳转到此链接
                                    #end

                                    <input type="text"
                                           class="form-control url" name="contentSourceUrl"
                                           id="contentSourceUrl"
                                           maxlength="500" placeholder="阅读全文链接,包含http"
                                           value="$!{data.contentSourceUrl}">

                                </div>
                            </div>

                            <div class="box-footer">
                                #if($shiro.hasPermission("qy:cfarticle:edit"))
                                <input class="btn btn-primary" id="save" value="保存" type="submit">
                                #end
                                <a href="#springUrl('/a/cfarticle/list?type=1')" class="btn btn-default">取消</a>
                            </div>
                        </form>
                        <!-- /.box-body -->
                    </div><!-- /.box -->


                </div><!-- /.col -->
            </div><!-- /.row -->
        </section><!-- /.content -->
    </div><!-- /.content-wrapper -->


    <!-- Add the sidebar's background. This div must be placed
         immediately after the control sidebar -->
    <div class="control-sidebar-bg"></div>
</div><!-- ./wrapper -->

<script src="plugins/jQuery/jQuery-2.1.4.min.js"></script>
<!-- Bootstrap 3.3.5 -->
<script src="bootstrap/js/bootstrap.min.js"></script>
<!-- DataTables -->
<script src="plugins/datatables/jquery.dataTables.min.js"></script>
<script src="plugins/datatables/extensions/i18n/lanauage_ch.js"></script>
<script src="plugins/datatables/dataTables.bootstrap.min.js"></script>
<!-- SlimScroll -->
<script src="plugins/slimScroll/jquery.slimscroll.min.js"></script>
<!-- FastClick -->
<script src="plugins/fastclick/fastclick.min.js"></script>
<!--fileinput js-->
<script src="plugins/bootstrap-fileinput/bootstrap-fileinput.js"></script>
<!-- AdminLTE App -->
<script src="dist/js/app.min.js"></script>
<script src="plugins/bootstrap-maxlength/bootstrap-maxlength.min.js" type="text/javascript"></script>
<script src="plugins/security/sha256.js" type="text/javascript"></script>
<script src="plugins/jquery-validation/js/jquery.validate.min.js"></script>
<script src="js/jquery.form.min.js"></script>
<script src="common/js/cfapp.js"></script>
<!-- Uedit Start -->
<script type="text/javascript" charset="utf-8"
        src="plugins/ueditor-min-1.4.3/ueditor.config.js"></script>
<script type="text/javascript" charset="utf-8"
        src="plugins/ueditor-min-1.4.3/ueditor.all.js"></script>
<script type="text/javascript" charset="utf-8"
        src="plugins/ueditor-min-1.4.3/p/main.js"></script>
<script type="text/javascript" charset="utf-8"
        src="plugins/ueditor-min-1.4.3/q/main.js"></script>
<!-- Uedit End -->

<script src="js/jquery.serializejson.js"></script>
<script src="plugins/jquery-validation/js/localization/messages_zh.js"></script>
<!-- END PAGE LEVEL PLUGINS -->
<script src="plugins/Sortable/Sortable.min.js"></script>
<script>
    var ue = null;


    function loadThumbnailHover() {
        $(".thumbnail").hover(function () {
            $(this).find(".delRemove").slideDown();
        }, function () {
            $(this).find(".delRemove").slideUp();
        })
    }


    $().ready(function () {

        $(".addParentThumbnail").click(function () {//图集图片添加

            Cfapp.sm({
                title: "图集图片选择",
                checkType: 'multi',
                success: function (data) {
                    var HTML = "";
                    if(data && data.length>0){
                        if(($(".sortableThumbnail").length+data.length)==10){
                            $(".addParentThumbnail").hide();
                        }
                        if(($(".sortableThumbnail").length+data.length)>10){
                            return;
                        }
                        for(var i = 0;i<data.length;i++){
                            HTML += "<div class='parentThumbnail sortableThumbnail'>";
                            HTML += " <div class='fileupload-preview thumbnail'>";
                            HTML += "<p class='delRemove'>删除</p>";
                            HTML += "<img src='" + data[i] + "'></div>";
                            HTML += "<textarea class='form-control' placeholder='图片描述...'></textarea>";
                            HTML += "</div>";
                        }
                    }
                    $("#foo").append(HTML);
                    loadThumbnailHover();//重新悬停事件
                },
                cancel: function (data) {

                }
            })
        })

        $("#foo").on("click",".sortableThumbnail img",function(){//点击图集更换图片事件
            obj = this;
            Cfapp.sm({
                title: "图集图片选择",
                checkType: 'single',
                success: function (data) {
                    $(obj).attr("src",data);
                    loadThumbnailHover();//重新悬停事件
                },
                cancel: function (data) {

                }
            })
        })



        loadThumbnailHover();//加载悬停事件
        if ("$!{data.id}" != null && "$!{data.id}" != "") {
            var prizes = eval('$!{data.content}');
            for (var i = 0; i < prizes.length; i++) {
                var HTML = "";
                HTML += "<div class='parentThumbnail sortableThumbnail'>";
                HTML += " <div class='fileupload-preview thumbnail'>";
                HTML += "<p class='delRemove'>删除</p>";
                HTML += "<img src='" + prizes[i].imgUrl + "'></div>";
                HTML += "<textarea class='form-control' placeholder='图片描述...'>" + prizes[i].desc + "</textarea>";
                HTML += "</div>";
                $("#foo").append(HTML);
            }
            loadThumbnailHover();
        }

        $("#foo").on("click", ".parentThumbnail>.thumbnail>.delRemove", function () {
            $(this).parent().parent().remove();
            if($(".sortableThumbnail").length>=10){
                $(".addParentThumbnail").hide();
            }
            if($(".sortableThumbnail").length<10){
                $(".addParentThumbnail").show();
            }
        })


        Cfapp.init();
        recdTypeAdd.init();
        var smallimg = "$!{data.smallimg}";

        var protocol = window.location.protocol;
        var host = window.location.host;
        if (smallimg && smallimg != null) {
            if (smallimg.substring(0, 7) == "http://") {
                $("#previewSmallImg").attr("src", smallimg).show();
            } else {
                $("#previewSmallImg").attr("src", protocol + '//' + host + smallimg).show();
            }
            $("#previewSmallImg").siblings("i").remove();
        }

        var bigimg = "$!{data.bigimg}";

        if (bigimg && bigimg != null) {
            if (bigimg.substring(0, 7) == "http://") {
                $("#previewBigImg").attr("src", bigimg).show();

            } else {
                $("#previewBigImg").attr("src", protocol + '//' + host + bigimg).show();
            }
            $("#previewBigImg").siblings("i").remove();
        }

        var columnUrl = "#springUrl('/a/column/listData')";

        var cfArticleUrl = "#springUrl('/a/cfarticle/listData')";

        /**
         * 小图选择
         */
        $("#smallImgSelect").click(function () {
            obj = $(this);
            Cfapp.sm({
                title: "文章小图选择",
                success: function (data) {
                    obj.find("i").remove();
                    $("#smallimg").val(data[0]);
                    $("#previewSmallImg").attr("src", data[0]).show();
                },
                cancel: function (data) {

                }
            })
        })

        /**
         * 大图选择
         */
        $("#bigImgSelect").click(function () {
            obj = $(this);
            Cfapp.sm({
                title: "文章大图选择",
                success: function (data) {
                    obj.find("i").remove();
                    $("#bigimg").val(data[0]);
                    $("#previewBigImg").attr("src", data[0]).show();
                    console.log(data.toString());
                },
                cancel: function (data) {

                }
            })
        })


        //选择栏目
        $("#columnSelect").click(function () {
            Cfapp.f7({
                dataUrl: columnUrl,
                checkType: 'single', // 多选为multi
                title: "选择栏目",
                btnoktext: "确定",
                btncanceltext: "取消",
                columns: ['选择', '栏目名称', '栏目图'],
                isSearch: '0',
                searchColumns: ["name"],//搜索的字段名称
                searchColumnsRemarks: ['栏目名称'],//搜索的字段备注
                aoColumns: [{
                    "mData": "id"
                }, {
                    "mData": "name"
                }, {
                    "mData": "img"
                }],
                aoColumnDefs: [{
                    "aTargets": [0],
                    "mData": "id",
                    "mRender": function (a, b, c, d) {
                        return '<input type="radio" id="' + a + '" name="sel" data-value="' + a + '" data-name="' + c.name + '">';
                    }
                }, {
                    "aTargets": [2],
                    "mData": "img",
                    "mRender": function (a, b, c, d) {//a表示createtime对应的值，c表示当前记录行对象
                        return "<img src='" + a + "' style='width: 80px;height:80px;' />";
                    }
                }],
                success: function () {

                },
                cancel: function () {

                },
                storeFields: 'column', // 储存的字段
                displayFields: 'columnName'
            })
        })


        $("#cfArticleSelect").click(function () {
            Cfapp.f7({
                dataUrl: cfArticleUrl,
                checkType: 'multi', // 多选为multi
                title: "选择文章",
                btnoktext: "确定",
                btncanceltext: "取消",
                columns: ['选择', '文章标题', '所属栏目', '文章封面'],
                isSearch: '0',
                searchColumns: ["title", "columnName"],//搜索的字段名称
                searchColumnsRemarks: ['文章标题', '所属栏目'],//搜索的字段备注
                aoColumns: [{
                    "mData": "id"
                }, {
                    "mData": "title"
                }, {
                    "mData": "columnName"
                }, {
                    "mData": "bigimg"
                }],
                aoColumnDefs: [{
                    "aTargets": [0],
                    "mData": "id",
                    "mRender": function (a, b, c, d) {
                        return '<input type="checkbox" id="' + a + '" name="sel" data-value="' + a + '" data-name="' + c.title + '">';
                    }
                }, {
                    "aTargets": [3],
                    "mData": "img",
                    "mRender": function (a, b, c, d) {//a表示createtime对应的值，c表示当前记录行对象
                        return "<img src='" + a + "' style='width: 80px;height:80px;' />";
                    }
                }],
                success: function () {
                    var HTML = "";
                    var relationArticleNames;
                    if ($("#relation_article_name").val()) {
                        relationArticleNames = $("#relation_article_name").val().split(",");
                        HTML+=" <div class='list-group' style='margin-top: 20px;'>";
                        for (var i = 0; i < relationArticleNames.length; i++) {
                            if(relationArticleNames[i] && relationArticleNames[i]!=""){
                                HTML += "<p class='list-group-item'>" + relationArticleNames[i] + "</p>";
                            }
                        }
                    }else{
                        $(".list-group").remove();
                    }
                    $("#relationCfArticleDiv").find(".list-group").remove();
                    $("#relationCfArticleDiv").find(".appendTemp").remove();
                    $("#relationCfArticleDiv").append(HTML);
                },
                cancel: function () {

                },
                storeFields: 'relation_article', // 储存的字段
                displayFields: 'relation_article_name'
            })
        })

    });


    var recdTypeAdd = function () {
        var initForm = function () {
            var initFormCtrl = function () {
                bindEvent();
            };
            var bindEvent = function () {

                $("#myForm").validate({
                    rules: {},
                    messages: {},
                    submitHandler: function (form) {

                        if($("input[name='isUrl']").is(':checked') && ($("#contentSourceUrl").val()==null || $("#contentSourceUrl").val()=="")){
                            var error = "<label class='error'>请填写网址</label>";
                            $("input[name='contentSourceUrl']").after(error);
                            return false;
                        }

                        var dataJson = $("#myForm").serializeJSON();
                        var array = [];
                        var tb = document.getElementById("foo");  //根据id找到这个表格
                        $("#foo").find(".parentThumbnail").each(function (index, item) {
                            var json = {};
                            var imgUrl = $(this).find(".thumbnail").find("img").attr("src");
                            var desc = $(this).find('textarea').val();//    奖项内容
                            json.imgUrl = imgUrl;
                            json.desc = desc;
                            array.push(json);
                        });
                        var arrayStr = JSON.stringify(array);
                        dataJson.content = arrayStr;
                        $("#save").attr("disabled", true);
                        $.post("#springUrl('/a/cfarticle/formData')", dataJson, function (returnobj) {
                            $("#save").attr("disabled", false);
                            if (returnobj.errorNo == 2) {  //保存成功
                                Cfapp.confirm({
                                    message: "添加成功",
                                    btnoktext: "继续添加",
                                    btncanceltext: "关闭",
                                    success: function () {
                                        location.href = "#springUrl('/a/cfarticle/picform')";
                                    },
                                    cancel: function () {
                                        location.href = "#springUrl('/a/cfarticle/list?type=1')";
                                    }
                                });
                            } else if (returnobj.errorNo == 0) {  //修改成功
                                Cfapp.alert({
                                    message: "更新成功",
                                    btntext: "确定",
                                    success: function () {
                                        location.href = "#springUrl('/a/cfarticle/list?type=1')";
                                    }
                                });
                            } else {
                                Cfapp.alert({
                                    message: "创建失败",
                                    btntext: "确定",
                                    success: function () {
                                        location.href = "#springUrl('/a/cfarticle/list?type=1')";
                                    }
                                });
                            }
                        });
                    }
                })
            }
            initFormCtrl();
        }
        return {

            //main function to initiate the module
            init: function () {
                initForm();
            }

        };
    }();
</script>
<script>
    /*增加图片拖动排序*/
    var byId = function (id) { return document.getElementById(id); },

            loadScripts = function (desc, callback) {
                var deps = [], key, idx = 0;

                for (key in desc) {
                    deps.push(key);
                }

                (function _next() {
                    var pid,
                            name = deps[idx],
                            script = document.createElement('script');

                    script.type = 'text/javascript';
                    script.src = desc[deps[idx]];

                    pid = setInterval(function () {
                        if (window[name]) {
                            clearTimeout(pid);

                            deps[idx++] = window[name];

                            if (deps[idx]) {
                                _next();
                            } else {
                                callback.apply(null, deps);
                            }
                        }
                    }, 30);

                    document.getElementsByTagName('head')[0].appendChild(script);
                })()
            },

            console = window.console;


    if (!console.log) {
        console.log = function () {
            alert([].join.apply(arguments, ' '));
        };
    }


    Sortable.create(byId('foo'), {
        group: "words",
        animation: 150,
        store: {
            get: function (sortable) {
                var order = localStorage.getItem(sortable.options.group);
                return order ? order.split('|') : [];
            },
            set: function (sortable) {
                var order = sortable.toArray();
                localStorage.setItem(sortable.options.group, order.join('|'));
            }
        },
        onAdd: function (evt){ console.log('onAdd.foo:', [evt.item, evt.from]); },
        onUpdate: function (evt){ console.log('onUpdate.foo:', [evt.item, evt.from]); },
        onRemove: function (evt){ console.log('onRemove.foo:', [evt.item, evt.from]); },
        onStart:function(evt){ console.log('onStart.foo:', [evt.item, evt.from]);},
        onSort:function(evt){ console.log('onStart.foo:', [evt.item, evt.from]);},
        onEnd: function(evt){ console.log('onEnd.foo:', [evt.item, evt.from]);}
    });
</script>
</body>
<!-- END BODY -->
</html>