PATH:
home
/
letacommog
/
letaweb
/
scripts
/
editor
Function.prototype.clone = function() { var that = this; var temp = function(arguments) { return that.apply(this, arguments); }; for(var key in this) { if (this.hasOwnProperty(key)) { temp[key] = this[key]; } } return temp; }; var pagemanager_iframe_app = angular.module('pagemanager.iframe',['pageEdit.widgets','pagemanager.file_manager','pagemanger.controls','pagemanager.link','ui.sortable','ui.popup','ui.config.edit']) .service('pageEdit_modules', function() { this.modules = {}; this.deleted_modules=[]; }) .service('pageEdit_function', ['$injector','pageEdit_event','pageEdit_modules','lazyLoadWidget',function($injector,pageEdit_event,pageEdit_modules,lazyLoadWidget) { this.getUniqueId = function(a) { var timestamp = $.now(); var id = a+ timestamp;//Math.floor(Math.random()*101); while( jQuery('#' + id).length > 0) { id = a + timestamp+Math.floor(Math.random()*101); } return id; }; this.getModules = function() { return pageEdit_modules.modules; }; this.generateModuleId = function(element) { var h = ''; h = pageEdit_event.iframe.iframe.page_file_name; var p = h +'-module'; return this.getUniqueId(p); }; this.createModuleInstance = function(moduleDefinition, type) { if(!moduleDefinition) return false; var bases = moduleDefinition.bases; if(moduleDefinition.originalPrototype == undefined) { var originalPrototype = $.extend(true,{}, moduleDefinition.prototype); moduleDefinition.originalPrototype = originalPrototype; } var moduleDef = moduleDefinition; var parents = []; var m = {}; if(bases != undefined) { for(var i in bases) { if(!bases.hasOwnProperty(i)) continue; var b = $injector.instantiate(bases[i]); m = $.extend(true, m,b); parents.push(b); } moduleDef.prototype = $.extend(true,{}, m, moduleDefinition.originalPrototype); moduleDef.prototype.bases = parents; moduleDef.prototype.type = type; moduleDef.prototype.display_name = type; if(window.sts_module_list != undefined && window.sts_module_list[type] != undefined) { moduleDef.prototype.display_name = window.sts_module_list[type][0]; moduleDef.prototype.icon_path = window.sts_module_list[type][1]; } } //delete moduleDefinition.bases; return $injector.invoke(function($injector) { return $injector.instantiate(moduleDef) }); }; }]) .value('pageEdit_constanst', { columns : [ 5.80111,14.3646, 22.9282, 31.4917, 40.0552, 48.6188, 57.1823, 65.7459, 74.3094, 82.8729, 91.4365,100 ], margin_columns : [ 0, 2.12766, 2.12766, 2.12766, 2.12766, 2.12766, 2.12766, 2.12766, 2.12766, 2.12766, 2.12766,2.12766 ], margin_left : 2.12766, row_helper_class : 'ww_row_helper', pagezone_gridline_class:'pagezone_gridline', highlight_element_class:'highlighter', pagezone_class : 'page_zone', zone_class : 'zone', row_class : 'row', row_locked_class : 'row-locked', column_class : 'col', container_class : 'container', module_class : 'module', module_locked_class : 'module-locked', module_split_class : 'module-text', module_split_droppable_selector : "p,h1,h2,h3,h4,h5,h6,ul,ol", column_float_class : "column-float-none", column_float_left_class : "column-float-left", column_float_right_class : "column-float-right", module_row_class : "module_row", insertion_point_class : "page_insertion_button" }) .factory('pageEdit_iframe', ['$q','pageEdit_layout','$dialog',function($q, pageEdit_layout,$dialog) { return function(iframe) { window.jQuery = iframe.$; this.iframe = iframe; this.getDocument = function() { return this.iframe.document; }; this.getWindow = function() { return this.iframe.window; }; this.setVariable = function(name,value) { this.iframe[name] = value; return this.iframe[name]; }; this.getVariable = function(name) { return this.iframe[name]; } } }]) .service('pageEdit_event',[function() { this.BLOCK_DROPPED = 'block_dropped'; this.BLOCK_MOVED='block_moved'; this.DRAGGING = 'dragging'; this.BLOCK_REMOVED = 'block_removed'; this.BLOCK_ADDED = 'block_added'; this.COLUMN_ADDED = 'column_added'; this.COLUMN_REMOVED = 'column_removed'; this.ROW_ADDED = 'row_added'; this.ROW_REMOVED = 'row_removed'; this.ZONE_ADDED = 'zone_added'; this.ZONE_REMOVED = 'zone_removed'; this.iframe; this.fire = function(event_name, params) { jQuery(this.iframe.getDocument()).trigger(event_name, params); }; this.on = function(event_name,data, fn) { jQuery(this.iframe.getDocument()).bind(event_name, data, fn); }; this.off = function(event_name, fn) { jQuery(this.iframe.getDocument()).unbind(event_name, fn); }; }]) .service('pageEdit', ['communication','ajax','pageEdit_highlighter','pageEdit_highlighter_manager','$location','pageEdit_event','$rootScope','$q','pageEdit_layout','$dialog','pageEdit_iframe','lazyLoadWidget','pageEdit_modules','$injector','pageEdit_function',function(communication,ajax,pageEdit_highlighter,pageEdit_highlighter_manager,$location,pageEdit_event,$rootScope,$q, pageEdit_layout,$dialog,pageEdit_iframe,lazyLoadWidget,pageEdit_modules,$injector,pageEdit_function) { this.mode = "content"; this.changeMode = function(mode, oldMode) { if(oldMode != undefined) this.exitMode(oldMode); switch(mode) { case 'design': $('#customize_preview').addClass('design'); this.mode=mode; this.initDesign(); break; case 'content': this.mode=mode; this.initModule(); break; } }; this.exitMode = function(mode) { switch(mode) { case 'design': this.exitDesignMode(); break; case 'content': this.exitContentMode(); break; } }; this.exitDesignMode = function() { $('#customize_preview').removeClass('design'); pageEdit_layout.unhightlightAll(); jQuery('body *').unbind('mouseover'); jQuery('body *').unbind('mouseleave'); jQuery('body *').unbind('click'); }; this.exitContentMode = function() { var that = this; jQuery("." + pageEdit_layout.module_class).each(function() { var moduleInstance = that.getModule(this); if(moduleInstance != undefined) moduleInstance.unbindEvent(); }); pageEdit_layout.unbindEvent(); }; this.initModule = function() { var that = this; pageEdit_modules.modules = {}; jQuery('body').children("." + pageEdit_layout.pagezone_class).each(function() { pageEdit_layout.createPageZone(this); }); pageEdit_layout.bindEvent(); }; this.initDesign = function() { var that = this; jQuery('body *').bind('mouseover', function(event) { if(jQuery(this).hasClass('module')) { return; } if(angular.isUndefined(this.id) || this.id.length == 0) return; event.stopPropagation(); pageEdit_layout.unhightlightAll(); pageEdit_layout.hightlight(this); }); jQuery('body *').bind('mouseleave', function(event) { if(angular.isUndefined(this.id) || this.id.length == 0) return; event.stopPropagation(); pageEdit_layout.unhightlight(this); }); jQuery('body *').bind('click', function(event) { if(jQuery(this).hasClass('module')) { return; } if(angular.isUndefined(this.id) || this.id.length == 0) return; event.stopPropagation(); pageEdit_layout.unhightlightAll(); pageEdit_highlighter_manager.unhighlightAll(); var h = new pageEdit_highlighter(this); var path ="/content/design/module/" + this.id; $rootScope.$apply(function() { $location.path(path); }); }); }; this._init = function(iframe) { if(iframe != undefined) { pageEdit_event.iframe = this.iframe = new pageEdit_iframe(iframe); this.page_id = iframe.page_id; this.page_name = iframe.page_name; this.page_file_name = iframe.page_file_name; console.log(this.page_file_name); this.script_url = iframe.script_url; } delete pageEdit_modules.modules; this.bindEvent(); //this.changeMode('content'); }; this.bindEvent = function() { // jQuery('a').unbind(); jQuery('a').click(function(event) { event.preventDefault(); }); }; this.getDocument = function() { return this.iframe.getDocument(); }; this.getWindow = function() { return this.iframe.getWindow(); }; this.getStyleSheets = function() { return this.getDocument().styleSheets; }; this.restoreCSS = function() { window.top.StyleSheet.restore2Origin(); }; this.changePage = function(page_id, page_name, file_name, success) { var that = this; var p = page_id; var ajaxInstance = new ajax(); ajaxInstance.get("view?body&page_id=" + p,{}).then(function(data) { try { jQuery('body').html(data); } catch(e) { console.log(e); } try { that.page_id = that.iframe.setVariable('page_id',page_id); that.page_name = that.iframe.setVariable('page_name',page_name); that.page_file_name = that.iframe.setVariable('page_file_name',file_name); if(success && typeof success == 'function') success(); that._init(that.iframe.iframe); that.changeMode('content'); } catch(e) { console.log(e); } }); this.restoreCSS(); }; this.getParameterByName = function(name) { var match = RegExp('[?&]' + name + '=([^&]*)').exec(window.location.search); return match && decodeURIComponent(match[1].replace(/\+/g, ' ')); }; this.deleteModule = function(el) { var module_id = jQuery(el).attr('id'); delete pageEdit_modules.modules[module_id]; pageEdit_modules.deleted_modules.push(module_id); }; this.getModule = function(el) { var module_id = jQuery(el).attr('id'); return pageEdit_modules.modules[module_id]; }; this.getModuleById = function(module_id) { return pageEdit_modules.modules[module_id]; }; this.archiveEditedModule = function(m) { var id = jQuery(m.getElement()).attr('id'); this.edited_modules = this.edited_modules || {}; this.edited_modules[id] = m; }; this.compareModule = function(m1, m2) { if(!m1 || !m2) return false; var id1 = m1.getElement().attr('id'); var id2 = m2.getElement().attr('id'); return id1 == id2; }; this.get_page_name = function() { var p = this.page_name; return p; }; this.get_page_id = function() { var p = this.page_id; return p; }; this.get_page_file_name = function() { var p = this.page_file_name; return p; }; this.get_script_url = function() { var p = this.script_url; return p; }; this.generateModuleId = function() { var h = ''; h = this.get_page_file_name(); var p = h +'-module'; return this.getUniqueId(p); }; this.getUniqueId = function(a) { var timestamp = $.now() var id = a+ timestamp;//Math.floor(Math.random()*101); while( jQuery('#' + id).length > 0) { id = a + timestamp+Math.floor(Math.random()*101); } return id; }; this.init= function() { this.modules = {}; this.edited_modules = {}; }; this.getModuleStructure= function(module) { var s = {}; var moduleInstance = this.getModule(module); if(!moduleInstance) { return s; } return moduleInstance.getStructure(); }; this.getColumnStructure= function(column) { var s = {}; var column = jQuery(column); var s = {}; s.id = column.attr('id'); s.class = column.attr('class'); var that = this; if(column.children('.block').children('.'+pageEdit_layout.module_class).length > 0) { s.modules = {}; jQuery(column).children('.block').children('.'+pageEdit_layout.module_class).each(function(i) { s.modules[i] = that.getModuleStructure(this); }); } return s; }; this.getRowStructure= function(row) { var s = {}; var moduleInstance = this.getModule(row); if(!moduleInstance) { return s; } return moduleInstance.getStructure(); }; this.getZoneStructure= function(zone) { var s = {}; var moduleInstance = this.getModule(zone); if(!moduleInstance) { return s; } return moduleInstance.getStructure(); }; this.getInnerZoneStructure= function(zone) { var s = {}; s.id = zone.id; s.class = jQuery(zone).attr('class'); s.type = jQuery(zone).attr('type'); s.style = jQuery(zone).attr('style'); s.rows = []; var that = this; jQuery(zone).children('.'+pageEdit_layout.row_class).each(function(i) { var row = that.getRowStructure(this); if(row != undefined) s.rows.push( row); }); return s; }; this.getPagePartStructure= function(part) { var s = {}; s.id = part.id; s.class = jQuery(part).attr('class'); s.type = jQuery(part).attr('type'); s.style = jQuery(part).attr('style'); s.zones = []; var that = this; jQuery(part).children('.'+pageEdit_layout.zone_class).each(function(i) { var zone = that.getZoneStructure(this); if(zone != undefined) s.zones.push( zone); }); return s; }; this.getPageStructure= function() { var s = {}; s.structure = {}; s.structure.parts = []; var that = this; jQuery('body').children('.page_zone').each(function(i) { var part = that.getPagePartStructure(this); if(part != undefined) s.structure.parts.push(part); }); return s; }; }]) .factory('pageEdit_highlighter',[ 'pageEdit_modules','lazyLoadWidget','pageEdit_function','pageEdit_constanst','pageEdit_highlighter_manager','$dialog',function(pageEdit_modules,lazyLoadWidget,pageEdit_function,pageEdit_constanst,pageEdit_highlighter_manager, $dialog) { return function(element) { this.alignElement = element; this._create = function() { var sides = ['top', 'left', 'right', 'bottom']; for (var i=0;i < sides.length;i++) { var side = sides[i]; var sideCap = side.substring(0,1).toUpperCase() + side.substring(1); var highlight = this['highlight' + sideCap] = $('<div class></div>'); highlight.addClass(pageEdit_constanst.highlight_element_class); jQuery('body').prepend(highlight); } pageEdit_highlighter_manager.register(this); this.id = jQuery(this.alignElement).attr('id'); this.align(); this.bindEvent(); }; this.getalignElement = function() { return this.alignElement; }; this.show = function() { this._align(); }; this.hide = function() { }; this._align = function() { var t = jQuery(this.alignElement); var offset = t.offset(); var top = Math.round(offset.top); var left = Math.round(offset.left); var height = t.outerHeight(); var width = t.outerWidth(); if (height == 0 && width == 0) { return; } var nleft = left + (width) /2; var ntop = 0; if(top > 20) ntop = 0; else ntop = top + t.outerHeight(); //divname.css({top: ntop, left: 0}); this.highlightTop.css({top: top, left: left, width:width}); this.highlightLeft.css({left: left, top: top, height: height}); this.highlightBottom.css({top: (top+height), left: left, width: width}); this.highlightRight.css({left: left+width, top: top, height: height}); }; this.align = function() { this._align(); }; this.create = function() { this._create(); this._align(); this.bindEvent(); }; this.remove = function() { pageEdit_highlighter_manager.deregister(this); this.highlightTop.remove(); this.highlightLeft.remove(); this.highlightBottom.remove(); this.highlightRight.remove(); jQuery(this.alignElement).unbind('resize'); }; this.bindEvent = function(point) { var that = this; jQuery(this.alignElement).bind('resize', function() { pageEdit_highlighter_manager.align(); }); } this.create(); }; }]) .service('pageEdit_highlighter_manager',[function() { this.highlighters = []; this.deregister = function(highlighter) { for(var i = 0;i < this.highlighters.length;i++) { if(this.highlighters[i] == highlighter) { this.highlighters.splice(i,1); } } }; this.unhighlight= function(element) { for(var i = 0;i < this.highlighters.length;i++) { if(this.highlighters[i].getalignElement().is( element)) { this.highlighters[i].remove(); } } }; this.unhighlightAll= function() { for(var i = this.highlighters.length-1;i >=0;i--) { if(this.highlighters[i] != 'undefined') this.highlighters[i].remove(); } }; this.register = function(h) { this.highlighters = this.highlighters || []; this.highlighters.push(h); }; this.align = function() { for(var i = 0;i < this.highlighters.length;i++) { this.highlighters[i].align(); } } }]) .service('pageEdit_layout', ['pageEdit_function','pageEdit_reserve_trarsever','lazyLoadWidget','pageEdit_modules','pageEdit_event', 'popup_module_list', function(pageEdit_function,pageEdit_reserve_trarsever,lazyLoadWidget,pageEdit_modules,pageEdit_event,popup_module_list) { this.columns = [ 5.80111,14.3646, 22.9282, 31.4917, 40.0552, 48.6188, 57.1823, 65.7459, 74.3094, 82.8729, 91.4365,100 ]; this.margin_columns = [ 0, 2.12766, 2.12766, 2.12766, 2.12766, 2.12766, 2.12766, 2.12766, 2.12766, 2.12766, 2.12766,2.12766 ]; this.margin_left = 2.12766; this.row_helper_class = 'ww_row_helper'; this.pagezone_class = 'page_zone'; this.zone_class = 'zone'; this.container_class = 'container'; this.container_fluid_class = 'container-fluid'; this.row_class = 'row'; this.row_locked_class = 'row-locked'; this.column_class = 'col'; this.column_desktop_class = 'col-md-'; this.column_large_desktop_class = 'col-lg-'; this.column_phone_class = 'col-xs-'; this.column_tablet_class = 'col-sm-'; this.column_tablet_push_offset_class = 'col-sm-push-'; this.column_tablet_pull_offset_class = 'col-sm-pull-'; this.column_phone_push_offset_class = 'col-xs-push-'; this.column_phone_pull_offset_class = 'col-xs-pull-'; this.column_desktop_push_offset_class = 'col-md-push-'; this.column_desktop_pull_offset_class = 'col-md-pull-'; this.hidden_large_desktop_class = 'hidden-lg'; this.hidden_phone_class = 'hidden-xs'; this.hidden_tablet_class = 'hidden-sm'; this.module_class = 'module'; this.module_locked_class = 'module-locked'; this.module_split_class = 'module-text'; this.module_split_droppable_selector = "p,h1,h2,h3,h4,h5,h6"; this.column_float_class = "column-float-none"; this.column_float_left_class = "column-float-left"; this.column_float_right_class = "column-float-right"; this.module_row_class = "module_row"; this.insertion_point_class = "page_insertion_button"; this.hightlight_class = 'hightlight'; this.bindEvent = function() { var that = this; pageEdit_event.on(pageEdit_event.BLOCK_REMOVED, function(event, params) { var column = jQuery(params.parent); if(!column.children().children().length) { var parent = column.parent(); column.remove(); pageEdit_event.fire(pageEdit_event.COLUMN_REMOVED,{block:column, parent:parent}); } }); pageEdit_event.on(pageEdit_event.COLUMN_ADDED, function(event, params) { var column = params.block; var row = jQuery(column).parent(); that.on_addColumn(row, column); if(!that.isFloatingModule(column)) { //that.createColumnResizer(row); } else { //that.createFloatColumnResizer(row); } }); pageEdit_event.on(pageEdit_event.COLUMN_REMOVED, function(event, params) { var row = jQuery(params.parent); if(!row.children().not('.ww_module_info').length) { var parent = row.parent(); row.remove(); pageEdit_event.fire(pageEdit_event.ROW_REMOVED,{block:row, parent:parent}); } else { that.on_removeColumn(row); //that.createColumnResizer(row); } }); pageEdit_event.on(pageEdit_event.ROW_ADDED, function(event, params) { var zone = params.block; that.createRow(zone); }); pageEdit_event.on(pageEdit_event.ROW_REMOVED, function(event, params) { //is in module var container = jQuery(params.parent); var inzone = container.is('.' + that.container_class) && container.parent().is('.' + that.zone_class); var inmodule = container.parents('.' + that.module_class + ':first').length; if(inzone && !container.children().length) { var zone = container.parent(); var parent = zone.parent(); zone.remove(); pageEdit_event.fire(pageEdit_event.ZONE_REMOVED,{block:zone, parent:parent}); } else if(inmodule) { if(jQuery(container).children().length == 0) { var dumprow = that.create_row_helper(); jQuery(container).append(dumprow); pageEdit_event.fire(pageEdit_event.ROW_ADDED,{'block':dumprow}); } } }); pageEdit_event.on(pageEdit_event.ZONE_ADDED, function(event, params) { var zone = params.block; that.createZone(zone); }); pageEdit_event.on(pageEdit_event.ZONE_REMOVED, function(event, params) { var e = jQuery(params.parent); if(e.children().length == 0) { var zone = that.create_zone_helper(e); jQuery(e).append(zone); pageEdit_event.fire(pageEdit_event.ZONE_ADDED,{'block':zone}); } }); pageEdit_event.on(pageEdit_event.BLOCK_MOVED, function(event, params) { var oldParent = jQuery(params.oldParent); if(!oldParent.children().length) { var column = oldParent.parent(); var row = column.parent(); column.remove(); pageEdit_event.fire(pageEdit_event.COLUMN_REMOVED,{block:column, parent:row}); } }); }; this.unbindEvent = function() { pageEdit_event.off(pageEdit_event.COLUMN_ADDED, function(event, params) { }); pageEdit_event.off(pageEdit_event.ROW_ADDED, function(event, params) { }); pageEdit_event.off(pageEdit_event.ZONE_ADDED, function(event, params) { }); pageEdit_event.off(pageEdit_event.BLOCK_MOVED, function(event, params) { }); } this.getColumnSize = function(col) { var column = jQuery(col); for(var i =1;i <= 12;i++) { if(column.hasClass(this.column_desktop_class + i)) return i; } }; this.getColumnLgSize = function(col) { var column = jQuery(col); for(var i =1;i <= 12;i++) { if(column.hasClass(this.column_large_desktop_class + i)) return i; } }; this.setColumnLgSize = function(col,size) { var column = jQuery(col); for(var i =1;i <= 12;i++) { column.removeClass(this.column_large_desktop_class + i); } column.removeClass(this.hidden_large_desktop_class); if(size >=1) column.addClass(this.column_large_desktop_class + size); else if(size==-1) column.addClass(this.hidden_large_desktop_class); }; this.getColumnXsSize = function(col) { var column = jQuery(col); for(var i =1;i <= 12;i++) { if(column.hasClass(this.column_phone_class + i)) return i; } }; this.getColumnXsOffsetSize = function(col) { var column = jQuery(col); for(var i =1;i <= 12;i++) { if(column.hasClass(this.column_phone_push_offset_class + i)) return -1*i; } for(var i =1;i <= 12;i++) { if(column.hasClass(this.column_phone_pull_offset_class + i)) return i; } }; this.setColumnXsSize = function(col,size) { var column = jQuery(col); for(var i =1;i <= 12;i++) { column.removeClass(this.column_phone_class + i); } column.removeClass(this.hidden_phone_class); if(size >=1) column.addClass(this.column_phone_class + size); else if(size==-1) column.addClass(this.hidden_phone_class); }; this.isColumnPull = function(col) { var column = jQuery(col); for(var i =1;i <= 12;i++) { if(column.hasClass(this.column_phone_pull_offset_class + i)) return true; if(column.hasClass(this.column_tablet_pull_offset_class + i)) return true; } return false; }; this.isColumnPush = function(col) { var column = jQuery(col); for(var i =1;i <= 12;i++) { if(column.hasClass(this.column_phone_push_offset_class + i)) return true; if(column.hasClass(this.column_tablet_push_offset_class + i)) return true; } return false; }; this.setColumnXsOffsetSize = function(col,size) { var column = jQuery(col); for(var i =1;i <= 12;i++) { column.removeClass(this.column_phone_push_offset_class + i); column.removeClass(this.column_phone_pull_offset_class + i); } if(!this.isColumnPull(col)) column.removeClass(this.column_desktop_pull_offset_class + 0); if(!this.isColumnPush(col)) column.removeClass(this.column_desktop_push_offset_class + 0); if(size >0) { column.addClass(this.column_phone_pull_offset_class + Math.abs(size)); column.addClass(this.column_desktop_pull_offset_class + 0); } else if(size<0) { column.addClass(this.column_phone_push_offset_class + Math.abs(size)); column.addClass(this.column_desktop_push_offset_class + 0); } }; this.getColumnSmSize = function(col) { var column = jQuery(col); for(var i =1;i <= 12;i++) { if(column.hasClass(this.column_tablet_class + i)) return i; } }; this.getColumnSmOffsetSize = function(col) { var column = jQuery(col); for(var i =1;i <= 12;i++) { if(column.hasClass(this.column_tablet_push_offset_class + i)) return -1*i; } for(var i =1;i <= 12;i++) { if(column.hasClass(this.column_tablet_pull_offset_class + i)) return i; } }; this.setColumnSmSize = function(col,size) { var column = jQuery(col); for(var i =1;i <= 12;i++) { column.removeClass(this.column_tablet_class + i); } column.removeClass(this.hidden_tablet_class); if(size >=1) column.addClass(this.column_tablet_class + size); else if(size==-1) column.addClass(this.hidden_tablet_class); }; this.setColumnSmOffsetSize = function(col,size) { var column = jQuery(col); for(var i =1;i <= 12;i++) { column.removeClass(this.column_tablet_push_offset_class + i); column.removeClass(this.column_tablet_pull_offset_class + i); } if(!this.isColumnPull(col)) column.removeClass(this.column_desktop_pull_offset_class + 0); if(!this.isColumnPush(col)) column.removeClass(this.column_desktop_push_offset_class + 0); if(size >0) { column.addClass(this.column_tablet_pull_offset_class + Math.abs(size)); column.addClass(this.column_desktop_pull_offset_class + 0); } else if(size<0) { column.addClass(this.column_tablet_push_offset_class + Math.abs(size)); column.addClass(this.column_desktop_push_offset_class + 0); } }; this.isColumnHideOnTablet = function(col) { var column = jQuery(col); if(column.hasClass(this.hidden_tablet_class)) return true; return false; }; this.isColumnHideOnPhone = function(col) { var column = jQuery(col); if(column.hasClass(this.hidden_phone_class)) return true; return false; }; this.isColumnHideOnLargeDesktop = function(col) { var column = jQuery(col); if(column.hasClass(this.hidden_large_desktop_class)) return true; return false; }; this.scanEmptyRow = function(zone) { var that = this; jQuery('.' + this.row_class, zone).each(function(i) { if(that.isRowHelper(this)) { jQuery(this).remove(); return; } that.remove_empty_column(this); }); }; this.isRow = function(element) { return jQuery(element).hasClass(this.row_class) || jQuery(element).hasClass(this.row_helper_class); }; this.isRowHelper = function(element) { return jQuery(element).hasClass(this.row_helper_class); }; this.isZone = function(element) { return jQuery(element).hasClass(this.zone_class); }; this.isContent = function(element) { return jQuery(element).is(this.module_split_droppable_selector); }; this.isColumn = function(element) { return jQuery(element).hasClass(this.column_class); }; this.isInMultiColumnRow = function(e) { return e.siblings().length > 0; }; this.isFirstModuleInColumn = function(e) { return e.prev().length == 0; }; this.isLastModuleInColumn = function(e) { return e.next().length == 0; }; this.isFirstZone = function(e) { return e.prev().length == 0; }; this.isFirstColumnInRow = function(e) { return e.prev().length == 0; }; this.isLastRowInLayout = function(e) { return e.next().length == 0; }; this.isStructureModule = function(element) { var id = jQuery(element).attr('id'); if(pageEdit_modules.modules[id] != undefined) { return pageEdit_modules.modules[id].is_structure; } return false; }; this.isFloatingModule = function(e) { var r = jQuery(e) ; var t = !r.hasClass(this.column_float_left_class) && !r.hasClass(this.column_float_right_class); return !t; }; this.unFloatModule = function(e) { var r = jQuery(e) ; r.removeClass(this.column_float_left_class); r.removeClass(this.column_float_right_class); for(var i = 1;i<= 12;i++) { r.removeClass(pageEdit_layout.column_class + i); } }; this.getZone = function(module) { return jQuery(module).parents().filter('.' + this.zone_class + ':first'); }; this.getColumn = function(module) { return jQuery(module).parents().filter('.' + this.column_class + ':first'); }; this.getModule = function(el) { var module_id = jQuery(el).attr('id'); return pageEdit_modules.modules[module_id]; }; this.createCloneModule = function(el,source_el) { var instance = this.getModule(source_el); if(instance == undefined) { return false } var module_id = jQuery(el).attr('id'); var newInstance = jQuery.extend(true,{}, instance); newInstance.page_id = module_id; delete newInstance.system_id; //delete newInstance.skin; newInstance.element = el; newInstance.is_clone_element = true; newInstance.loadElement(el); pageEdit_modules.modules[module_id] = newInstance; instance.reloadElement(); return newInstance; } this.createModule = function(el, type) { var instance = this.getModule(el); if(instance != undefined) { instance.loadElement(el); return instance; } if(!type) { var type = jQuery(el).attr('data-type'); if(type == undefined) type = jQuery(el).attr('trel'); } jQuery(el).removeAttr('data-type'); jQuery(el).removeAttr('trel'); if(!type && jQuery(el).is('.' + this.zone_class) ) type = 'zone'; if(!type && jQuery(el).is('.' + this.column_class) ) type = 'column'; if(!type && jQuery(el).is('.' + this.pagezone_class) ) type = 'pagezone'; if(!type && jQuery(el).is('.' + this.row_class) ) type = 'row'; var that = this; lazyLoadWidget(type).then(function(moduleDefinition) { var module = pageEdit_function.createModuleInstance(moduleDefinition, type); if(!module) return; module.loadElement(el); var module_id = jQuery(el).attr('id'); pageEdit_modules.modules[module_id] = module; }); }; this.createColumn = function(el) { }; this.createPageZone = function(el) { this.createModule(el); } this.createRow = function(el) { this.createModule(el); } this.createZone = function(el) { this.createModule(el); } this.remove_module = function(module, trigger) { trigger = trigger||true; var column = module.parent().parent(); module.remove(); if(trigger) pageEdit_event.fire(pageEdit_event.BLOCK_REMOVED,{'block':module,'parent': column}); }; this.remove_empty_row = function(zone) { var that = this; var container = jQuery(zone).children('.container'); container.children('.' + this.row_class).each(function() { var columns = jQuery(this).find('.' + that.column_class); if(columns.length == 0 ) { var parent = jQuery(this).parent(); jQuery(this).remove(); pageEdit_event.fire(pageEdit_event.ROW_REMOVED,{'block':this,'parent': parent}); } }); }; this.remove_empty_float_column = function(row) { var f = false; var that = this; jQuery(row).children('.' + this.column_class).each(function() { var modules = jQuery(this).find('.module').not('moving'); if(modules.length == 0 ) { that.remove_float_column(row, this); } }); this.check_float_module(row); }; this.remove_empty_column = function(row) { var f = false; var that = this; jQuery(row).children('.' + this.column_class).each(function() { var modules = jQuery(this).find('.module').not('moving'); if(modules.length == 0 ) { var parent = jQuery(this).parent(); //that.remove_column(row, this); jQuery(this).remove(); pageEdit_event.fire(pageEdit_event.COLUMN_REMOVED,{'block':this,'parent': parent}); } }); }; this.unhightlight = function(element) { jQuery(element).removeClass(this.hightlight_class); }; this.unhightlightAll = function() { jQuery('.'+this.hightlight_class).removeClass(this.hightlight_class); }; this.hightlight = function(element, options) { jQuery(element).addClass(this.hightlight_class); } this.remove_row_helper = function() { jQuery('.' + this.row_helper_class).remove(); }; this.create_row_helper = function() { var dumprow = jQuery('<div/>'); dumprow.addClass(this.row_helper_class); dumprow.addClass(this.row_class); dumprow.attr('id', pageEdit_function.getUniqueId('ww_row_helper')); var button = jQuery('<button class="btn btn-primary fa fa-plus"></button>'); dumprow.append(button); var that = this; button.click(function(event) { that.rowHelper_clickEvent(jQuery(this).parent()); }); return dumprow; }; this.create_module_helper = function(column) { var column = jQuery(column); var button = jQuery('<button class="btn btn-primary fa fa-plus"></button>'); column.append(button); var that = this; button.click(function(event) { that.rowHelper_clickEvent(jQuery(this).parent()); }); return column; }; this.create_zone_helper = function(el) { var zone = jQuery('<div class="zone"/>'); var id = jQuery(el).attr('type'); zone.attr('id', pageEdit_function.getUniqueId('zone')); var container = jQuery('<div class="container"/>'); zone.append(container); var row = this.create_row_helper(); container.append(row); return zone; }; this.zoneHelper_clickEvent = function(dumprow,direction) { var that = this; popup_module_list.open({ controller:function($scope,$modalInstance) { $scope.insertModule = function(type) { $modalInstance.close(type); } } }).result.then(function(type) { that._insertModule_Static(dumprow,type,direction) }); }; this.rowHelper_clickEvent = function(dumprow,direction) { var that = this; popup_module_list.open({ controller:function($scope,$modalInstance) { $scope.insertModule = function(type) { $modalInstance.close(type); } } }).result.then(function(type) { that._insertModule_Static(dumprow,type,direction) }); }; this._insertModule_Static = function(dumprow,type,direction) { direction = direction||'top'; if(!type) return null;; type = type.substring(0,1).toLowerCase() + type.substring(1); var m = null; var dropInfo = { node:dumprow, direction:direction, shouldFloat:false, }; return this._insertModule(dumprow, type, dropInfo); }; this._insertModule = function(insert_point, type, dropInfo) { if(!type) return null;; type = type.substring(0,1).toLowerCase() + type.substring(1); var m = null; var insert_point = jQuery(dropInfo.node); var pos = dropInfo.direction; var that = this; var module_id = pageEdit_function.getUniqueId('module-'); dropInfo.element_identifier = module_id; lazyLoadWidget(type).then(function(moduleDefinition) { var module = pageEdit_function.createModuleInstance(moduleDefinition, type); if(!module) return; pageEdit_modules.modules[module_id] = module; module.insert(dropInfo).then(function() { if(that.isRowHelper(insert_point)) insert_point.remove(); module.openEditor(); }); }); }; this._insertZoneTemplate = function(insert_point, name, dropInfo) { if(!name) return null; var zone = this.getModule(insert_point); if(zone!= undefined) zone.insertZoneTemplate(name, dropInfo); }; this.check_mouse_in = function(mouseX, mouseY, el) { var coord = this.pageObj.ddManager.getCoordinate(el); return mouseX >= coord.left && mouseX <= coord.right && mouseY >= coord.top && mouseY <= coord.bottom; }; this.resize_module_column = function(col) { var that = this; jQuery(col).children('.block').children('.module').each(function() { that.resize_module(this); }); }; this.resize_float_module_column = function(col) { }; this.resize_module = function(module) { var type = jQuery(module).attr('trel'); if(window['resize_' + type]) window['resize_' + type]( module ); }; this.collapseCol = function(col) { var index = this.getColumnSize(col) || 12 index--; if(index <1) return false; this.changeColumnSize(col, index); return true; }; this.changeColumnSize = function(column,size) { for(var i = 1;i <=12;i++) jQuery(column).removeClass(this.column_desktop_class + i); jQuery(column).addClass(this.column_desktop_class + size); }; this.collapseFloatCol = function(col) { var index = this.getColumnSize(col) || 12 if(index <=1) return false; index--; this.changeColumnSize(col, index); return true; }; this.expandFloatCol = function(col) { var index = this.getColumnSize(col) || 12 if(index > this.columns.length - 1) return; index++; this.changeColumnSize(col, index); }; this.expandCol =function(col) { var index = this.getColumnSize(col) || 12 if(index > this.columns.length - 1) return false; index++; this.changeColumnSize(col, index); return true; }; this.updateColumnResizer = function(e) { //this.createColumnResizer(e); }; this.getPrevZone = function(zone) { var zone = jQuery(zone); var next_zones = zone.prevAll('.'+this.zone_class); if(next_zones.length) return next_zones[0]; } this.getNextZone = function(zone) { var zone = jQuery(zone); var next_zones = zone.nextAll('.'+this.zone_class); if(next_zones.length) return next_zones[0]; } this.getPrevRow = function(row) { var row = jQuery(row); var next_rows = row.prevAll('.'+this.row_class); if(next_rows.length) return next_rows[0]; } this.getNextRow = function(row) { var row = jQuery(row); var next_rows = row.nextAll('.'+this.row_class); if(next_rows.length) return next_rows[0]; } this.getPrevColumn = function(col) { var col = jQuery(col); var next_cols = col.prevAll('.'+this.column_class); if(next_cols.length) return next_cols[0]; } this.getNextColumn = function(col) { var col = jQuery(col); var next_cols = col.nextAll('.'+this.column_class); if(next_cols.length) return next_cols[0]; } this.getNextCollapsibleColumn = function(col) { var col = jQuery(col); var next_cols = col.nextAll('.'+this.column_class); for(var i = 0;i < next_cols.length;i++) { if(this.isCollapsibleColumn(next_cols[i])) return next_cols[i]; } } this.isCollapsibleColumn = function(col) { var index = this.getColumnSize(col) || 12 if(index <= 1) return false; return true; } this.createColumnResizer = function(e) { return; var t = jQuery(e); var l = 0; var that = this; t.children('.' + this.column_class).not(':last').each(function() { jQuery(this).children('.col_divider').remove(); var divider = jQuery('<div class="col_divider"/>'); divider.append('<div/>'); jQuery(this).append(divider); divider.css('position','absolute'); jQuery(divider).draggable( { axis: "x", stop: function(event, ui) { window.dragging = false; // var i = t.children('.col_divider').index(ui.helper); var col_left = ui.helper.parent();; var col_right = col_left.next();; var d = ui.position.left - ui.helper.originalPos; var move_direction = d < 0 ? 'left' : 'right'; if(move_direction == 'left') { that.expandCol(col_right); that.collapseCol(col_left); } else if(move_direction == 'right') { that.expandCol(col_left); that.collapseCol(col_right); } // that.pageObj.scanrowforedit(); that.updateColumnResizer(t); }, drag: function(event, ui) { }, start: function(event, ui) { window.dragging = true; that.unhightlightAll(); ui.helper.originalPos = ui.position.left; } }); }); }; this.getMinColumn = function(row) { var r = jQuery(row); var m = 12; var col; r.children('.' + this.column_class).each(function() { var c = jQuery(this).attr('class').split(' ')[1] || that.column_class; var index = c.substring(that.column_class.length); index = parseInt(index); if(isNaN(index) ) index = 12; if(index < m) { m = index col = this; } }); return col; }; this.getMaxColumn = function(row) { var r = jQuery(row); var m = 0; var col; r.children('.' + this.column_class).each(function() { var c = jQuery(this).attr('class').split(' ')[1] || that.column_class; var index = c.substring(that.column_class.length); index = parseInt(index); if(isNaN(index) ) index = 12; if(index > m) { m = index col = this; } }); return col; }; this.get_column_index = function(column) { column = jQuery(column); var c = jQuery(column).attr('class').split(' ')[1] || this.column_class; var index = c.substring(this.column_class.length); index = parseInt(index); if(isNaN(index) ) index = 12; return index; }; this.check_float_module = function(e) { var r = jQuery(e); var c = r.children("." + this.column_class).not("." + this.column_float_left_class + ",." + this.column_float_right_class); var l = c.length; if(l == 0) { var m = r.find("." + this.module_class); r.before(m); r.remove(); } }; this.remove_float_column = function(row, column) { var r = jQuery(row); var that = this; column.remove(); if(r.children('.' + this.column_class).length == 1) { var c = r.children('.' + this.column_class); if(c.find('.' + this.module_class).length >= 1) { var m = c.find('.' + this.module_class); r.before(m); } r.remove(); } }; this.getModules = function() { return pageEdit_modules.modules; }; this.on_removeColumn = function(row) { var arr = []; var m_arr = []; var r = jQuery(row); var that = this; r.children('.' + this.column_class).each(function() { var index = that.getColumnSize(this) || 12; m_arr.push( jQuery(this).index() ); arr.push(index); }); if(arr.length > 0) { for(var j = 0; j < 12 && !this.check_column_outsize(arr, m_arr); j++ ) { this.increase_all_index(arr); } var mii = this.get_min_index(arr); var ii = this.get_max_index(arr); for(var j = 0; this.check_column_outsize(arr, m_arr);j++ ) { if(ii >= arr.length) ii = 0; if(!this.decrease_index(arr,ii)) break; ii++; } var i = 0; r.children('.' + this.column_class).each(function() { that.changeColumnSize(this, arr[i]); i++; }); } }; this.is_row_can_add_column = function(row) { row = jQuery(row); return row.children('.' + this.column_class).length < 12; }; this.on_addColumn = function(row, column) { var arr = []; var m_arr = []; var r = jQuery(row); var that = this; r.children('.' + this.column_class).each(function(i) { var index = that.getColumnSize(this) || 12; m_arr.push( i ); arr.push(index); }); var iii = this.get_min_index(arr); var cindex = arr.length-1; arr[ cindex ] = arr[ iii ]; var ii = this.get_max_index(arr); for(var j = 0; this.check_column_outsize(arr, m_arr); j++ ) { if(ii >= arr.length) ii = 0; if(!this.decrease_index(arr,ii)) break; ii++; } var i = 0; r.children('.' + this.column_class).each(function() { that.changeColumnSize(this,arr[i]); i++; }); //this.createColumnResizer(r); }; this.check_column_outsize = function(arr, margin_arr) { var tt = 0; for(var i = 0;i < arr.length;i++) { if( !this.columns[ arr[i] - 1 ] ) return true; var margin if(!margin_arr) margin = 0; else margin = this.margin_columns[ margin_arr[i] ]; tt += arr[i]; } return tt > 12; }; this.add_float_column = function(row, column) { var arr = []; var m_arr = []; var r = jQuery(row); var that = this; var l = r.children('.' + this.column_class).length; var cls = Math.floor(12 / l); r.children('.' + this.column_float_left_class).each(function() { jQuery(this).attr('class', 'column column' + cls + ' ' + that.column_float_left_class); }); r.children('.' + this.column_float_right_class).each(function() { jQuery(this).attr('class', 'column column' + cls + ' ' + that.column_float_right_class); }); this.createFloatColumnResizer(row); }; this.createFloatColumnResizer = function(row) { this._createFloatColumnResizer(row, "left"); this._createFloatColumnResizer(row, "right"); }; this._createFloatColumnResizer = function(row, size) { var t = jQuery(row); var l = 0; var that = this; var cl = this.column_float_left_class; if(size === "right") cl = this.column_float_right_class; t.children('.' + cl).each(function() { jQuery(this).children('.float_col_divider').remove(); var divider = jQuery('<div class="col_divider float_col_divider"/>'); divider.append('<div/>'); if(size === "left") jQuery(this).append(divider); else jQuery(this).prepend(divider); divider.css('position','absolute'); jQuery(divider).draggable( { axis: "x", stop: function(event, ui) { window.dragging = false; // var i = t.children('.col_divider').index(ui.helper); var col = ui.helper.parent();; var d = ui.position.left - ui.helper.originalPos; var move_direction = d < 0 ? 'left' : 'right'; if(move_direction == 'left') { if(size === "left") that.collapseFloatCol(col); else that.expandFloatCol(col); } else if(move_direction == 'right') { if(size === "left") that.expandFloatCol(col); else that.collapseFloatCol(col); } // that.pageObj.scanrowforedit(); // that.updateColumnResizer(t); jQuery(ui.helper).css("left", ""); }, drag: function(event, ui) { }, start: function(event, ui) { window.dragging = true; ui.helper.originalPos = ui.position.left; } }); }); }; this.get_max_index = function(arr) { var m = 0; var index = 0; for(var i = 0;i < arr.length;i++) { if(arr[i] > m) { m = arr[i]; index = i; } } return index; }; this.get_min_index = function(arr) { var m = arr[0]; var index = 0; for(var i = 0;i < arr.length;i++) { if(arr[i] < m) { m = arr[i]; index = i; } } return index; }; this.decrease_index = function(arr, i) { if(arr[i] && arr[i] >1) { arr[i]--; return true; } return false; }; this.increase_index = function(arr, i) { if(arr[i] && arr[i] < 12) { arr[i]++; return true } return false; }; this.decrease_all_index = function(arr) { for(var i = 0;i < arr.length;i++) { if(!this.decrease_index(arr, i)) return false; } return true; }; this.increase_all_index = function(arr) { for(var i = 0;i < arr.length;i++) { if(!this.increase_index(arr,i)) return false; } return true; }; this.adjustRowLayout = function(row) { var r = jQuery(row); var that = this; var l = r.children('.' + this.column_class).length; if(l == 0) return; var arr = [] r.children('.' + this.column_class).each(function() { var c = jQuery(this).attr('class').split(' ')[1] || that.column_class; var index = c.substring(that.column_class.length); index = parseInt(index); if(isNaN(index) ) index = 12; arr.push(index); }); arr.sort(function(a,b){ return a-b}); var tt = 0; for(var i = 0;i < arr.length;i++) { tt += this.column[arr[i]]; } if(tt > 100) { } else if(tt < 100) { } var p = 100; p = 100 / l; var index = 11; for(var i = this.columns.length - 1; i >= 0; i--) { if(this.columns[i] * l <= 100) { index = i; break; } } r.children('.' + this.column_class).each(function() { jQuery(this).attr('class', ''); jQuery(this).addClass(that.column_class); jQuery(this).addClass(that.column_class + (index + 1) ); that.resize_module_column(this); }); //this.createColumnResizer(r); }; this.wrap_zone = function(e) { var zone = jQuery('<div class="zone"></div>'); var id = pageEdit_function.getUniqueId('zone'); zone.attr('id', id); var c = jQuery('<div class="container"></div>'); zone.append(c); var b = this.wrap_row(e); c.append(b); return zone; }; this.wrap_row = function(e) { var row = jQuery('<div class=""></div>'); row.addClass(this.row_class); var id = pageEdit_function.getUniqueId('row'); row.attr('id', id); var c = jQuery('<div class="'+this.column_class + '"></div>'); var id = pageEdit_function.getUniqueId('column'); c.attr('id', id); row.append(c); var b = jQuery('<div class="block"></div>'); c.append(b); b.append(e); return row; }; this.wrap_module_row = function(e) { var row = jQuery('<div class="module ' + this.module_row_class + '"></div>'); var id = pageEdit_function.getUniqueId('module'); row.attr('id', id); var c = jQuery('<div class="'+this.column_class+'"></div>'); var id = pageEdit_function.getUniqueId('column'); c.attr('id', id); //c.addClass(this.column_float_class); row.append(c); e.after(row); var b = jQuery('<div class="block"></div>'); c.append(b); b.append(e); return row; }; this.wrap_column = function(e) { var c = jQuery('<div class="'+this.column_class+'"></div>'); var id = pageEdit_function.getUniqueId('column'); c.attr('id', id); var b = jQuery('<div class="block"></div>'); c.append(b); b.append(e); return c; }; }]); pagemanager_iframe_app .factory('pageEdit_trarsever',[ function() { return function(page_zone_function, zone_function, row_function, column_function, module_function, before_trarseve_function) { this.page_zone_function = page_zone_function; this.zone_function = zone_function; this.row_function = row_function; this.column_function = column_function; this.module_function = module_function; this.before_trarseve_function = before_trarseve_function; this.trarseve_body = function() { var that = this; jQuery('body').children('.page_zone').each(function(i) { that.trarseve_part(this); }); }; this.trarseve_module = function(module) { var box = jQuery(module).children('.box'); var tab = jQuery(module).children('.tabs').children('.navigation').children('li').children('a'); var tab_contents = jQuery(module).children('.tabs').children('.tab-contents'); var accordion = jQuery(module).children('.accordions').children('.accordion-header'); this.module_function(module); var that = this; box.each(function(i) { that.trarseve_innerzone(this); }); tab.each(function(i) { var href = jQuery(this).attr('href'); href = href.substring(1); href = '.' + href; var content = tab_contents.children(href); that.trarseve_innerzone(content); }); accordion.each(function(i) { var content = jQuery(this).next(); that.trarseve_innerzone(content); }); }; this.trarseve_column = function(column) { var that = this; var modules = jQuery(column).children('.block').children('.module'); this.column_function(column); if(modules.length > 0) { modules.each(function(i) { that.trarseve_module(this); }); } }; this.trarseve_row = function(row) { var columns = jQuery(row).children('.column'); this.row_function(row); var that = this; columns.each(function(i) { that.trarseve_column(this); }); }; this.trarseve_zone = function(zone) { var rows = jQuery(zone).children('.container').children('.row'); this.zone_function(zone); var that = this; rows.each(function(i) { that.trarseve_row(this); }); }; this.trarseve_innerzone = function(zone) { var that = this; var rows = jQuery(zone).children('.row'); this.zone_function(zone); rows.each(function(i) { that.trarseve_row(this); }); }; this.trarseve_part = function(part) { var that = this; var zones = jQuery(part).children('.zone'); this.page_zone_function(part); zones.each(function(i) { that.trarseve_zone(this); }); }; this.trarseve = function(element) { if(!element) this.trarseve_body(); else { var e = jQuery(element); if(e.hasClass('page_zone') ) this.trarseve_part(element); else if(e.hasClass('zone') ) this.trarseve_zone(element); else if(e.hasClass('row') ) this.trarseve_row(element); else if(e.hasClass('column') ) this.trarseve_column(element); else if(e.hasClass('module') ) this.trarseve_module(element); } }; } }]) .factory('pageEdit_reserve_trarsever',[ 'pageEdit_constanst',function(pageEdit_constanst) { return function(page_zone_function, zone_function, row_function, column_function, module_function, before_trarseve_function) { this.page_zone_function = page_zone_function; this.zone_function = zone_function; this.row_function = row_function; this.column_function = column_function; this.module_function = module_function; this.before_trarseve_function = before_trarseve_function; this.trarseve = function(element) { if(this.before_trarseve_function) this.before_trarseve_function(element); if(!element) this.trarseve_body(); else { var e = jQuery(element); if(e.hasClass('page_zone') ) this.trarseve_part(element); else if(e.hasClass('zone') ) this.trarseve_zone(element); else if(e.hasClass('row') ) this.trarseve_row(element); else if(e.hasClass('column') ) this.trarseve_column(element); else if(e.hasClass('module') ) this.trarseve_module(element); } }; this.trarseve_body = function() { }; this.trarseve_module = function(module) { var column = jQuery(module).parent().parent(); this.module_function(module); var that = this; this.trarseve_column(column); }; this.trarseve_column = function(column) { var that = this; var row = jQuery(column).parent(); this.column_function(column); if(row.hasClass(pageEdit_constanst.module_row_class) ) { this.trarseve_module_row(row); } else this.trarseve_row(row); }; this.trarseve_module_row = function(row) { this.trarseve_module(row); }; this.trarseve_row = function(row) { var parent = jQuery(row).parent(); this.row_function(row); var that = this; if(parent.hasClass('container') ) { var zone = parent.parent(); this.trarseve_zone(zone); } else if(parent.hasClass('box') ) { var module = parent.parent(); this.trarseve_module(module); } else if(parent.hasClass('accordion-content') ) { var module = parent.parent().parent(); this.trarseve_module(module); } else if(parent.hasClass('tab-content') ) { var module = parent.parent().parent().parent().parent(); this.trarseve_module(module); } }; this.trarseve_zone = function(zone) { var part = jQuery(zone).parent(); this.zone_function(zone); var that = this; this.trarseve_part(part); }; this.trarseve_part = function(part) { var that = this; this.page_zone_function(part); this.trarseve_body(); }; } }]) .service('pageEdit_ddManager', ['pageEdit_function','pageEdit_modules','pageEdit_layout', 'pageEdit','pageEdit_trarsever','$window','$q',function(pageEdit_function,pageEdit_modules,pageEdit_layout, pageEdit,pageEdit_trarsever,$window,$q) { this.bounder_class = 'ww_drag_helper_bounder'; this.header_pagezone_id = 'header_wrapper'; this.main_pagezone_id = 'main_wrapper'; this.footer_pagezone_id = 'footer_wrapper'; this.border_class = 'ww_drag_helper_border'; this.bounder_zone_class = 'ww_drag_helper_bounder_zone'; this.bounder_column_class = 'ww_drag_helper_bounder_column'; this.bounder_row_class = 'ww_drag_helper_bounder_row'; this.bounder_module_class = 'ww_drag_helper_bounder_module'; this.bounder_size = 10; this.drop_class = 'ww_drop'; this.none_create_bounder_element_class = 'no_bound'; this.getModules = function() { return pageEdit_layout.getModules(); } this.createZoneBound = function(zone) { var that = this; var trarsever = pageEdit_trarsever(null,function(e){that.boundZone(e)}, function(e){that.boundRow(e)}, function(e){that.boundColumn(e)}, function(e){that.boundModule(e)}); trarsever.trarseve(zone); }; this.createBound = function() { this.horizontalBound = {}; this.verticalBound = {}; var that = this; this.coordinates = []; var that = this; jQuery('body').children('.page_zone').children('.zone').each(function() { that.coordinates.push( { dom:this, bounded: false, }); }); }; this.getCoordinate = function(e) { var t = jQuery(e); var offset = {top: 0, left: 0}; if(typeof t['offset'] == 'function') offset = jQuery(e).offset(); if(offset == null) return {top: 0, left: 0, right:0, bottom:0, width:0, height:0}; var height = jQuery(e).outerHeight(); var width = jQuery(e).outerWidth(); return {top:offset.top, left:offset.left, right: offset.left + width, bottom: offset.top+ height, width: width, height: height}; }; this.removeBorder = function() { jQuery('.droppable').removeClass('droppable'); }; this.createElementBorder = function(e) { jQuery(e).addClass('droppable'); }; this.createBorder = function() { jQuery('.row').addClass('droppable'); jQuery('.column').addClass('droppable'); jQuery('.module').addClass('droppable'); }; this.elementFromPoint = function(x,y) { var check=false, isRelative=true; if(!this.pageObj.getDocument().elementFromPoint) return null; if(!check) { var sl; if((sl = jQuery(this.pageObj.getDocument()).scrollTop()) >0) { isRelative = (this.pageObj.getDocument().elementFromPoint(0, sl + jQuery(window).height() -1) == null); } else if((sl = jQuery(this.pageObj.getDocument()).scrollLeft()) >0) { isRelative = (this.pageObj.getDocument().elementFromPoint(sl + jQuery(window).width() -1, 0) == null); } check = (sl>0); } if(!isRelative) { x += jQuery(this.pageObj.getDocument()).scrollLeft(); y += jQuery(this.pageObj.getDocument()).scrollTop(); } return this.pageObj.getDocument().elementFromPoint(x,y); }; this.checkPointIn = function(x,y, element) { var coord = this.getCoordinate(element); return x <= coord.right && x >= coord.left && y <= coord.bottom && y >=coord.top; }; this.checkIntersection = function(x,y, bound_top, bound_left, bound_right, bound_bottom, direction) { var a = 0; var b = 0; if(direction == 'up') { a = bound_top <= y; b = x <= bound_right && x >= bound_left; } if(direction == 'down') { a = bound_top >= y; b = x <= bound_right && x >= bound_left; } if(direction == 'left') { a = bound_left <= x; b = y <= bound_bottom && y >= bound_top; } if(direction == 'right') { a = bound_left >= x; b = y <= bound_bottom && y >= bound_top; } if(a && b) return true; return false; }; this.checkCollision = function(top, left, side) { var e; if(side == 'top' || side == 'bottom') { var bounds = this.horizontalBound[top]; if(bounds) { for(var i in bounds) { if(!bounds.hasOwnProperty(i) ) continue; var ele = bounds[i]; var right = ele.right; if(left < right) return true; } } } else { var bounds = this.verticalBound[left]; if(bounds) { for(var i in bounds) { if(!bounds.hasOwnProperty(i) ) continue; var ele = bounds[i]; var bottom = ele.bottom;; if(top < bottom) return true; } } } return false; }; this.createModuleOverlay = function(e) { var cl = 'drop_module_overlay'; var coord = this.getCoordinate(e); var div = jQuery('<div class="' + cl + '"></div>'); jQuery('body').append(div); div.css( { width: coord.width ,height: coord.height, top: coord.top, left: coord.left,"z-index":2000} ); }; this.createModulesOverlay = function() { var that = this; var trarsever = new PageEditClass.Trarsever(function(e){},function(e){}, function(e){}, function(e){}, function(e){that.createModuleOverlay(e)}); trarsever.trarseve(); }; this.init = function() { var that = this; jQuery(".col_divider").hide(); jQuery('body').addClass("dragging"); pageEdit_layout.unhightlightAll(); this.dropBlockInfo = { moduleNode: null, ancestors: null, parentLayout: null }; $window.dragging = true; this.initModule(); }; this.initModule = function() { var modules = pageEdit_layout.getModules(); for(var i in modules) { if(!modules.hasOwnProperty(i)) continue; modules[i].initDrag(); } }; this.destroy = function() { pageEdit.getDocument().onmousemove = null; jQuery('#dump_element').remove(); jQuery('.droppable').removeClass('droppable'); jQuery('.' + this.none_create_bounder_element_class).removeClass(this.none_create_bounder_element_class); jQuery('.ww_drop').removeClass('ww_drop'); jQuery('.selecting').removeClass('selecting'); jQuery('.' + this.bounder_class).remove(); jQuery('.' + pageEdit_layout.pagezone_class).removeClass('dragging'); this.removeBorder(); jQuery('body').children('.page_zone').children('.zone').unbind('mousemove'); jQuery(".col_divider").show(); jQuery('body').removeClass("dragging"); $("." + pageEdit_layout.module_class).each(function() { var m = pageEdit.createModule(this); if(m) { m.destroyDragDrop(); } }); }; this._dragStart = function(event, ui) { }; this._dropOver = function(event, ui) { }; this.create_drag_notify = function(e) { }; this.dropModuleInfo = {}; this.getDropElement = function(event, ui) { var element ; var that = this; var arr = []; jQuery('.' + pageEdit_layout.module_class).each(function() { var dropped = that.inDragHandlerRegion(this); if(dropped) { arr.push(this); } }); arr.sort(function(l,m) { var n=1; var id = l.id; if(id == 'dump_element') return 1; if(jQuery.contains(m,l)) return -1; return n }); var e=arr[0]; return e }; this._dragDrag = function(event, ui) { if(!$window.dragging) return; this.mouseX = event.pageX; this.mouseY = event.pageY; var that = this; var arr = []; var modules = pageEdit_layout.getModules(); for(var i in modules) { if(!modules.hasOwnProperty(i)) continue; modules[i].handleDragEvent(event, ui); } }; this.handleInnerOver = function(event, a,ui) { if(!$window.dragging) return; this.dropElement == a; var edgeInfo = this.getEdgeInfo(event, a, ui); this.processEdgeInfo(event, edgeInfo,ui); this.alignInsertionMarker(); }; this._doalignInsertionMarker = function() { }; this.alignInsertionMarker = function() { var dropInfo = this.dropInfo; var scope = dropInfo.type; if(scope == undefined) return; var b = jQuery('#dump_element'); if(b.length == 0) { var b = jQuery('<div id="dump_element" class="ww_insertion_marker"></div>'); b.append('<div class="ww_insertion_marker_label"/>'); jQuery('body').append(b); } var element = jQuery(dropInfo.node); var coord = dropInfo.region; var f = dropInfo.direction; var width = ""; var height = ""; jQuery('.ww_insertion_marker_label', b).html(''); jQuery('.ww_insertion_marker_label', b).html(scope); if(dropInfo.shouldFloat) { width = coord.width / 2; height =coord.height !== 0 ? width *(coord.height / coord.width) : 0.5625 * width ; } else if(f == 'top' || f == 'bottom' ) { height = ''; if(scope == 'content') width = element.parents("." + pageEdit_layout.module_class + ":first-child").width(); else width = coord.width; } else { width = ''; height = coord.height; } b.css( {width: width, height: height} ); b.show(); var helper_width = b.width(); var helper_height = b.height(); var left,top; if(f == 'top') { left = coord.left; top = coord.top; } else if(f == 'bottom') { left = coord.left; top = coord.bottom - helper_height; } else if(f == 'right') { left = coord.right - helper_width; top = coord.top; } else if(f == 'left') { left = coord.left; top = coord.top; } b.css( { left: left, top: top} ); }; this.inDragHandlerRegion = function(element) { var element = jQuery(element); if(element.length == 0) return false; var coord = this.getCoordinate(element); return this.mouseX >= coord.left && this.mouseY > coord.top && this.mouseX <= coord.right && this.mouseY < coord.bottom; }; this.getType = function(element) { var e = jQuery(element); if(e.hasClass(pageEdit_layout.page_zone_class) ) { return 'page_zone'; } if(e.hasClass(pageEdit_layout.zone_class) ) { return 'zone'; } if(e.hasClass(pageEdit_layout.row_class) ) { return 'row'; } if(e.hasClass(pageEdit_layout.column_class) ) { return 'column'; } if(e.hasClass(pageEdit_layout.module_class) ) { return 'module'; } else if(e.is(pageEdit_layout.module_split_droppable_selector)) { return "content"; } return 'unknown'; }; this.getColumn = function(row) { return $(row).children().length; }; this.isModuleFloatable = function(ui_helper) { var moduleInstance = ui_helper.moduleInstance; if(moduleInstance != undefined) return moduleInstance.is_floatable; return false; }; this.isFloatingModule = function(e) { var r = jQuery(e) ; var t = !r.hasClass(pageEdit_layout.column_float_left_class) && !r.hasClass(pageEdit_layout.column_float_right_class); return !t; }; this.unFloatModule = function(e) { var r = jQuery(e) ; r.removeClass(pageEdit_layout.column_float_left_class); r.removeClass(pageEdit_layout.column_float_right_class); for(var i = 1;i<= 12;i++) { r.removeClass(pageEdit_layout.column_class + i); } }; this.isFloatingColumn = function(e) { var r = jQuery(e) ; return r.hasClass(pageEdit_layout.column_float_left_class) || r.hasClass(pageEdit_layout.column_float_right_class); }; this.getEdgeInfo = function(event, element) { var c = null; var coord = this.getCoordinate(element); var quad = { x: this.mouseX < coord.left + coord.width / 2 ? "left" : "right", y: this.mouseY < coord.top + coord.height / 2 ? "top" : "bottom" }; var left = "left" === quad.x ? this.mouseX - coord.left : coord.left + coord.width - this.mouseX; var top = "top" === quad.y ? this.mouseY - coord.top : coord.top + coord.height - this.mouseY, l = Math.min(coord.width, coord.height), k = 100 * (left / coord.width), p = 100 * (top / l), direction = k < p ? quad.x : quad.y, distance = k < p ? left : top; isNaN(distance) || (c = { node: element, direction: direction, distance: distance, quad: quad, region: coord }); return c; }; this.processedEdgeInfo = {}; this.processEdgeInfo = function(event, info, ui) { var e = this.dropModuleInfo, node = info.node, g = e.ancestors, h = e.parentLayout, k = this.isAdjacentToBlockEdge(node), direction = info.direction, p = info.region; var type = this.getType(node), r = "content" === type ? jQuery(node).parents("." + pageEdit_layout.module_class + ":first") : node; if (!e.moduleNode || !jQuery(e.moduleNode).is(r)) { g = jQuery(node).parents("." + pageEdit_layout.module_class + ",." + pageEdit_layout.column_class + ",." + pageEdit_layout.row_class).not(pageEdit_layout.module_row_class); g = g.toArray(); h = jQuery(node).parents("." + pageEdit_layout.page_zone_class); this.dropModuleInfo = { moduleNode: r, parentLayout: h, ancestors: g }; } e = this.isModuleFloatable(ui.helper) && "content" === type && this.isHorizontalDirection(direction); //if (!e && (this.forceSingleColumn || 1 === this.getColumn(h) )) //direction = info.quad.y; if (node.is('.'+pageEdit_layout.zone_class)) direction = info.quad.y; if(this.isTraversableDirection(direction,k) ) { var dnode = this.getTraversedDropNode(node, direction, info); if(dnode) { node = dnode; type = this.getType(node); if(e) e = "content" === type; } } if("content" === type) { if(!e && this.isHorizontalDirection(direction) ) { var md = jQuery(node).parents("." + pageEdit_layout.module_class + ':first'); if(md.length > 0) { node = md[0]; type = this.getType(node); } } } else if("module" === type && (this.isHorizontalDirection(direction) && this.isOnlyBlockInColumn(node))) { node = jQuery(node).parents("." + pageEdit_layout.column_class + ':first'); type = this.getType(node); } else if("module" === type && (this.isVerticalDirection(direction) && this.isFloatingModule(node))) { //type = this.getType(node); } !jQuery(node).is( info.node) && (p = this.getCoordinate(node)); var isself = jQuery(node).hasClass('ww_dragging'); this.dropInfo= { node: node, direction: direction, shouldFloat: e, type: type, region: p, isSelf:isself }; }; this.isOnlyBlockInColumn = function (b) { return 0 === jQuery(b).siblings("." + pageEdit_layout.module_class).length; }; this.isTraversableDirection = function(direction, adjacent) { var rs = !0; adjacent && void 0 !== adjacent[direction] && (rs = adjacent[direction]); return rs }; this.getTraversableDepth = function (element, direction, parents) { var h = 0; for (var g = -1; element && this.canTraverseToParent(element, direction) &&g < parents.length-1;h++,g++, element = parents[g]) { } return h }; this.canTraverseToParent = function (element, direction) { var d = jQuery(element).hasClass(pageEdit_layout.column_class), g = !this.forceSingleColumn; return d && this.isVerticalDirection(direction) || g && this.canTraverseHorizontallyFromColumn(direction, element) || !d && g && !jQuery(element).parent().hasClass(pageEdit_layout.zone_class) && this.isHorizontalDirection(direction) || this.canTraverseVerticallyFromModule(direction, element) || this.canTraverseVerticallyFromContent(direction, element) }; this.canTraverseHorizontallyFromColumn = function(direction, element) { return jQuery(element).hasClass(pageEdit_layout.column_class) && ("left" === direction && !jQuery(element).prev().length > 0 || "right" === direction && !jQuery(element).next().length > 0); }; this.canTraverseVerticallyFromModule = function(direction, element) { return jQuery(element).hasClass(pageEdit_layout.module_class) && ("top" === direction && !jQuery(element).prev("." + pageEdit_layout.module_class).length > 0 || "bottom" === direction && !jQuery(element).next("." + pageEdit_layout.module_class).length > 0); }; this.canTraverseVerticallyFromContent = function(direction, element) { return jQuery(element).is(pageEdit_layout.module_split_droppable_selector) && ("top" === direction && !jQuery(element).prev(pageEdit_layout.module_split_droppable_selector).length > 0 || "bottom" === direction && !jQuery(element).next(pageEdit_layout.module_split_droppable_selector).length > 0); }; this.canTraverseVerticallyFromRow = function(direction, element) { var rs = jQuery(element).hasClass(pageEdit_layout.row_class) &&("top" === direction && !jQuery(element).prev("." + pageEdit_layout.row_class).length > 0 || "bottom" === direction && !jQuery(element).next("." + pageEdit_layout.row_class).length > 0); if(rs) { var a =""; var dfdf= ""; } return rs; }; this.getTraversedDropNode = function (node, direction, info) { var ancestors = this.dropModuleInfo.ancestors; if(jQuery(ancestors[0]).is(node)) { ancestors.shift(); } this.forceSingleColumn && (ancestors = ancestors.filter("." + pageEdit_layout.module_class)); var g = this.getTraversableDepth(node, direction, ancestors); if (g) { var d = ancestors.length; var h = Math.min(info.region.width, info.region.height) / 3; var f = Math.floor(g * info.distance / h); f = g - f -1; c = Math.min(g-1, Math.min(g, f)); return ancestors.hasOwnProperty(c) ? ancestors[c] : node; } return node }; this.isHorizontalDirection = function (b) { return "left" === b || "right" === b }; this.isVerticalDirection = function (b) { return "top" === b || "bottom" === b }; this.isAdjacentToBlockEdge = function(element) { if(jQuery(element).is(pageEdit_layout.module_split_droppable_selector))// && jQuery(element).parents("." + pageEdit_layout.module_split_class).length > 0) { return {top: jQuery(element).is(':first-child'), last: jQuery(element).is(':last-child') }; } }; this._drop = function(event, ui) { var that = this; var d = this.dropInfo; if(d) { var type = ui.helper.attr('type'); type = type.substring(0,1).toUpperCase() + type.substring(1); var pos = d.direction; var element_id = jQuery(d.node).attr('id'); var element = d.node; return pageEdit.insertModule(element,type, d); } return false; }; this._drop_inner = function() { $window.dragging = false; var defered = $q.defer(); var d = this.dropInfo; if(d) { var scope = d.type; if(scope == undefined) { defered.reject(0); return defered.promise; } var pos = d.direction; var element = jQuery(d.node); defered.resolve({element:element, direction:pos,dropInfo:this.dropInfo}); } else defered.reject(0); return defered.promise; }; }]);
[+]
..
[-] pagemanager.js
[edit]
[-] customize.js
[edit]
[+]
viewer
[-] ecommerce.js
[edit]
[-] pagemanager.iframe.js
[edit]
[+]
popup
[-] pagemanager.modules.js
[edit]
[+]
customize
[+]
blog
[-] settings.js
[edit]
[+]
modules
[-] content.js
[edit]
[-] blog.js
[edit]
[-] base.js
[edit]
[+]
settings
[+]
ecommerce