📄 studio2.js
字号:
// destination.appendChild(element.parentNode.removeChild(element)); destination.appendChild(element); Studio2.resetFieldWidth(element); } else { element.parentNode.removeChild(element); } } else { for (var i=0;i<element.childNodes.length;i++) { var child = element.childNodes[i]; if (child.nodeName == 'DIV') { // a subelement Studio2.reclaimFields(child); } } } }, highlightElement: function(field) { Dom.setStyle(field,'visibility','hidden'); }, /* FIELD WIDTH FUNCTIONS */ getSpacing: function(field) { var leftMargin = parseInt(Dom.getStyle(field,'margin-left')); var rightMargin = parseInt(Dom.getStyle(field,'margin-right')); var leftPadding = parseInt(Dom.getStyle(field,'padding-left')); var rightPadding = parseInt(Dom.getStyle(field,'padding-right'));// alert("in width:"+leftMargin + " " +rightMargin + " "+leftPadding + " "+rightPadding + " "); if (Studio2.isIE) { return (leftMargin + rightMargin); } else { return (leftMargin + rightMargin + leftPadding + rightPadding + 2); } }, resetFieldWidth: function(field) { Dom.setStyle(field,'width',Studio2.fieldwidth + 'px' ); }, /* a hack function, purely because Firefox has a problem with field widths during the init function */ /* so rather than relying on the style values we just set the width directly to the final value */ adjustWidth: function(field,columns) { var newWidth = columns * (Studio2.fieldwidth + Studio2.getSpacing(field)); Dom.setStyle(field,'width',newWidth + 'px' ); }, increaseFieldWidth: function(field) { var newWidth;// var currentWidth = parseInt(field.clientWidth); var currentWidth = Studio2.getFieldWidth(field); newWidth = currentWidth + Studio2.fieldwidth + Studio2.getSpacing(field);// field.style.width = newWidth+'px'; Dom.setStyle(field,'width',newWidth + 'px' ); }, reduceFieldWidth: function(field) { var newWidth; var currentWidth = parseInt(Dom.getStyle(field,'width')); newWidth = currentWidth - Studio2.fieldwidth - Studio2.getSpacing(field); Dom.setStyle(field,'width',newWidth + 'px' ); }, getFieldWidth: function(field) { var width = parseInt(Dom.getStyle(field,'width')); // computed style value of the field width (or currentStyle in IE - same result) if (isNaN(width)) { width = Studio2.fieldwidth; // if field width is set to something like 'auto' we need to take a better guess } return width; }, setFieldWidth: function(field,width) { Dom.setStyle(field,'width',width); }, getColumnWidth: function(field) { return Math.floor(Studio2.getFieldWidth(field)/Studio2.fieldwidth); }, setColumnWidth: function(field,columns) { var spacing = Studio2.getSpacing(field); var newWidth = columns * (Studio2.fieldwidth + spacing) - spacing; Dom.setStyle(field,'width',newWidth + 'px' ); }, firstField: function(row) { var firstfield = row.firstChild; while (firstfield.nodeName != 'DIV') { firstfield = firstfield.nextSibling; } return firstfield; }, getColumn: function(field) { var firstfield = Studio2.firstField(field.parentNode);// //console.log(Dom.getX(field) + "," + Dom.getX(firstfield) + "," + Studio2.fieldwidth ); return Math.ceil((Dom.getX(field)-Dom.getX(firstfield))/Studio2.fieldwidth); }, getRow: function(field) { // find our parent row // find how many previous siblings we have that are also rows // our row is that + 1 var row = field.parentNode; var count = 1; while ((row = row.previousSibling) !== null) { if (row.nodeName == 'DIV') { count++; } } return count; }, prevField: function(field){ var prev = field.previousSibling; while( (null !== prev) && (prev.nodeName != 'DIV')){ prev = prev.previousSibling; } return prev; }, nextField: function(field) { var next = field.nextSibling; while (typeof(next)!='undefined' && (next !== null) && (next.nodeName != 'DIV')) { next = next.nextSibling; } return next; }, /* ELEMENT FUNCTIONS */ // TODO: rewrite tidyPanels, tidyRows and tidyFields as a recursive tidy tidyPanels: function() { var panels = document.getElementById('panels'); if (Studio2.count(panels) <= 0) { var newPanel = Studio2.newPanel(); newPanel.appendChild(Studio2.newRow(false)); panels.appendChild(newPanel); Studio2.activateElement(newPanel); } }, tidyRows: function(panel) { if (Studio2.count(panel) <= 0) { // no rows left if (Studio2.count(panel.parentNode)>1) { Studio2.removeElement(panel); Studio2.tidyPanels(); } else { // add a blank row back in var newRow = Studio2.newRow(false); panel.appendChild(newRow); Studio2.activateElement(newRow);// debugger; } } }, tidyFields: function(row) { if (Studio2.count(row) <= 0) { // no fields left var panel = row.parentNode; Studio2.removeElement(row); Studio2.tidyRows(panel); } }, removeElement: function(element) { Studio2.reclaimIds(element); Studio2.reclaimFields(element); if (element.className.indexOf('le_field') == -1) { // all fields have been moved to availablefields in Studio2.reclaimFields element.parentNode.removeChild(element); } }, swapElements: function(el1,el2) { // TODO: record this swap in TRANSACTION var el1Width = Studio2.getFieldWidth(el1); var el2Width = Studio2.getFieldWidth(el2); Ext.dd.DragDropMgr.swapNode(el1, el2); Studio2.setFieldWidth(el1,el2Width); Studio2.setFieldWidth(el2,el1Width); }, activateElement: function(element) { if (!document.getElementById(element.id)) { Ext.getBody().appendChild(element); } if (element.className.indexOf('le_panel') != -1) { new Studio2.PanelDD(element.id,'studio2.panels'); new Ext.dd.DDTarget(element.id,'studio2.rows'); // add so a background for row moves } if (element.className.indexOf('le_row') != -1) { new Studio2.RowDD(element.id,'studio2.rows'); } if (element.className.indexOf('le_field') != -1) { new Studio2.FieldDD(element,'studio2.fields'); } for (var i=0;i<element.childNodes.length;i++) { var child = element.childNodes[i]; if (child.nodeName == 'DIV') { // a valid child Studio2.activateElement(child); } } }, /** * A substitute for cloneNode that is Yahoo Drag-and-Drop compatible. * Using document.cloneNode causes Yahoo DnD to fail as the ID is also cloned, leading to duplicate IDs in the document * This substitute doesn't copy the ID */ copyElement: function(element) { var copy = document.createElement(element.nodeName); if (element.attributes.length > 0) {// if (element.hasAttributes()) { // IE doesn't like hasAttributes() var attrs = element.attributes; for(var i=0;i<attrs.length;i++) { if (attrs[i].name != 'id') { // check to see if this attribute is actually set in the document, or just a default - IE's attributes array contains both, and we only want the specified attributes var a = element.getAttributeNode(attrs[i].name); if (a.specified) { if (attrs[i].name == 'class') { // Needed for IE copy.className = attrs[i].value; } copy.setAttribute(attrs[i].name,attrs[i].value); } } } } copy.innerHTML = element.innerHTML; copy.id = Studio2.nextId();// alert("parent ="+ copy.parentNode.id); return copy; }, setCopy: function(copy) { Studio2.copyId = copy.id; }, copy: function() { if (Studio2.copyId != null) { return document.getElementById(Studio2.copyId); } else { return false; } }, activateCopy: function() { Studio2.activateElement(document.getElementById(Studio2.copyId)); }, removeCopy: function() { if (Studio2.copyId != null) { Studio2.removeElement(Studio2.copy()); } Studio2.copyId = null; }, // Copy all the slot content across to a temporary form table for submitting to the backend for the save // We could have made all the slots be hidden fields within a form, (ala the original Portal editor), but then we'd have to do a lot of work during // editing that really only needs to be done once per save prepareForSave: function() { // create a new saveForm var panels = document.getElementById('panels'); var saveForm = document.getElementById('prepareForSave'); if (! saveForm) { saveForm = document.createElement('form'); saveForm.id = 'prepareForSave'; Dom.setStyle(saveForm.id, "visibility", "hidden"); panels.parentNode.appendChild(saveForm); } // remove any existing slot information, but importantly, preserve any non-slot stuff needed for form submittal var length = saveForm.childNodes.length; var index = 0; for( var i=0; i<length; i++) { if (saveForm.childNodes[index].nodeName != 'INPUT') { index++; } else { if (saveForm.childNodes[index].getAttribute('name').substr(0,4) == "slot") { saveForm.removeChild(saveForm.childNodes[index]); } else { index++; } } } // convert to input name='slot-{panel}-{slot}-{type}' value={value} var panelid = 0; var panels = document.getElementById('panels'); for( var i=0;i<panels.childNodes.length;i++) { var panel = panels.childNodes[i]; if (panel.nodeName == 'DIV') { // a panel panelid++; var fieldid = -1; for (var j=0;j<panel.childNodes.length;j++) { var row = panel.childNodes[j]; // save the panel name and label if (row.id && row.id.indexOf('le_panellabel') != -1) { // a panel label var inputField = document.createElement('input'); inputField.setAttribute('type','hidden'); inputField.setAttribute('name','panel-'+panelid+'-name'); inputField.setAttribute('value',document.getElementById('le_panelname_'+row.id.substr(14,row.id.length)).innerHTML); saveForm.appendChild(inputField); var inputField = document.createElement('input'); inputField.setAttribute('type','hidden'); inputField.setAttribute('name','panel-'+panelid+'-label'); inputField.setAttribute('value',document.getElementById('le_panelid_'+row.id.substr(14,row.id.length)).innerHTML); saveForm.appendChild(inputField); } // now for the rows if (row.nodeName == 'DIV') { // a row for (var k=0;k<row.childNodes.length;k++) { var field = row.childNodes[k]; if (field.nodeName == 'DIV') { // a field fieldid++; for ( var l=0; l < field.childNodes.length; l++ ) { var property = field.childNodes[l]; if (property.nodeName == 'SPAN') { // a property of a field if (property.attributes.length > 0) {// if (property.hasAttributes) { var type = property.className; if ((type.length>5) && (type.substr(0,5) == 'field') && (property.childNodes.length != 0)) { var value = property.firstChild.nodeValue; var inputField = document.createElement('input'); inputField.setAttribute('type','hidden'); inputField.setAttribute('name','slot-'+panelid+'-'+fieldid+'-'+type.substr(6,type.length)); inputField.setAttribute('value',value); saveForm.appendChild(inputField); } } } } // check fieldwidth in the layout; if more than one, then add an (empty) for each (so the parser can keep track of the slots) var endId = fieldid+Studio2.getColumnWidth(field)-1; while (fieldid<endId) { fieldid++; var inputField = document.createElement('input'); inputField.setAttribute('type','hidden'); inputField.setAttribute('name','slot-'+panelid+'-'+fieldid+'-name'); inputField.setAttribute('value','(empty)'); saveForm.appendChild(inputField); } } } } } } } }, handleSave: function() { ajaxStatus.showStatus('Saving...'); ModuleBuilder.state.isDirty=false; this.prepareForSave(); // set <input type='hidden' name='action' value='saveLayout'> var saveForm = document.forms['prepareForSave']; var inputField = document.createElement('input'); inputField.setAttribute('type','hidden'); inputField.setAttribute('name','action'); inputField.setAttribute('value','saveLayout'); saveForm.appendChild(inputField); ModuleBuilder.submitForm('prepareForSave'); ajaxStatus.flashStatus('Save complete',5000); }, handlePublish: function() { ajaxStatus.showStatus('Saving...'); ModuleBuilder.state.isDirty=false; this.prepareForSave(); // set <input type='hidden' name='action' value='saveAndPublishLayout'> var saveForm = document.forms['prepareForSave']; var inputField = document.createElement('input'); inputField.setAttribute('type','hidden'); inputField.setAttribute('name','action'); inputField.setAttribute('value','saveAndPublishLayout'); saveForm.appendChild(inputField); ModuleBuilder.submitForm('prepareForSave'); ajaxStatus.flashStatus('Deploy complete',5000); }};
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -