Authored by dongjunjie

逛拖拽

var dragging = function(el, array, callback) {
var $ = require('jquery');
var drag = function(el, array, callback) {
this.el = el;
this.dataArray = array;
this.callback = callback;
}
dragging.prototype = {
constructor: dragging,
drag.prototype = {
constructor: drag,
minZindex: 1,
dragItemList: null,
dragItemPos: [],
Initialize: function(){
console.log(list);
this.dragItemList = $("#" + this.el).find(".dragItem");
this.dragItemList = $(this.el).find("li");
if(this.dragItemList.length < 1){
return;
}
var elHeight = 0;
$(this.el).css("position","relative");
for(var i=0;i<this.dragItemList.length;i++){
var top = this.dragItemList[i].offsetTop;
var left = this.dragItemList[i].offsetLeft;
... ... @@ -24,7 +27,12 @@ dragging.prototype = {
this.dragItemPos[i] = {left:left, top:top};
this.dragItemList[i].index = i;
if(i == this.dragItemList.length - 1){
elHeight = top + $(this.dragItemList[i]).height() + 20;
}
}
$(this.el).css("height", elHeight + "px");
for(var i=0; i<this.dragItemList.length; i++){
$(this.dragItemList[i]).css("position", "absolute").css("margin", 0);
... ... @@ -82,6 +90,11 @@ dragging.prototype = {
_self.move(oNear,_self.dragItemPos[obj.index]);
_self.move(obj,_self.dragItemPos[oNear.index]);
/*
$(oNear).css("top",_self.dragItemPos[obj.index].top+"px").css("left",_self.dragItemPos[obj.index].left+"px");
$(obj).css("top",_self.dragItemPos[oNear.index].top+"px").css("left",_self.dragItemPos[oNear.index].left+"px");
*/
//交换index
oNear.index += obj.index;
obj.index = oNear.index - obj.index;
... ... @@ -191,3 +204,5 @@ dragging.prototype = {
}
}
module.exports = drag;
\ No newline at end of file
... ...
... ... @@ -134,6 +134,13 @@ var Bll = {
},
__render: function(selecter, templater, data) {
$(selecter).html(common.util.__template2($("#" + templater).html(), data));
var contentDrag = new common.drag("#add-content", Bll.contentDatas, function(data){
console.log(data);
Bll.contentDatas = data;
Bll.__render("#add-content","template_content",{modules:Bll.contentDatas});
});
contentDrag.Initialize();
},
Tags: []
}
... ... @@ -165,6 +172,8 @@ Bll.__render("#add-content","template_content",{modules:Bll.contentDatas});
new common.dropDown({
el: "#authorId",
ajax: "guangGetAuthorList"
... ... @@ -351,7 +360,7 @@ $(document).on("click", ".del", function() {
$(document).on("change", ".observe", function() {
var $this = $(this);
var name = $this.data("field");
var name = $this.data("field");//a.b.2.d
Bll.module.contentData.data=common.util.__buildobj(name, '.', Bll.module.contentData.data, function(obj, name) {
obj[name] = $this.val();
});
... ... @@ -622,3 +631,5 @@ $(document).on("click","#brandAutoBtn",function(){
}
});
... ...
... ... @@ -266,13 +266,14 @@
[[each btns as btn index]]
<li><a href="javascript:void(0)" name="text" class="add_btn" data-index="[[index]]">[[btn.template_intro]]</a></li>
[[/each]]
<div class="clearfix"></div>
</script>
<script type="text/template" id="template_content">
<!-- 文本内容 -->
[[each modules as module index]]
<li class="form-group custom-group" data-index="[[index]]">
<li class="form-group custom-group" data-index="[[index]]" style="width: 100%">
[[if module.contentData.template_name=='text']]
<div class="col-sm-12"><h3>[[module.contentData.data.text]]</h3></div>
[[else if module.contentData.template_name=='singleImage']]
... ...