-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Commit
- Loading branch information
There are no files selected for viewing
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,115 @@ | ||
var presetsFactory; | ||
|
||
presetsFactory = { | ||
|
||
getPresetsDictionary: function() { | ||
return { | ||
11: 100 / 9, | ||
12: 100 / 8, | ||
14: 100 / 7, | ||
16: 100 / 6, | ||
33: 100 / 3, | ||
66: 2 / 3 * 100, | ||
83: 5 / 6 * 100 | ||
}; | ||
}, | ||
|
||
getAbsolutePresetValues: function( preset ) { | ||
var clonedPreset = elementor.helpers.cloneObject( preset ), | ||
presetDictionary = this.getPresetsDictionary(); | ||
|
||
_.each( clonedPreset, function( unitValue, unitIndex ) { | ||
if ( presetDictionary[ unitValue ] ) { | ||
clonedPreset[ unitIndex ] = presetDictionary[ unitValue ]; | ||
} | ||
} ); | ||
|
||
return clonedPreset; | ||
}, | ||
|
||
getPresets: function( columnsCount, presetIndex ) { | ||
var presets = elementor.helpers.cloneObject( elementor.config.elements.section.presets ); | ||
|
||
if ( columnsCount ) { | ||
presets = presets[ columnsCount ]; | ||
} | ||
|
||
if ( presetIndex ) { | ||
presets = presets[ presetIndex ]; | ||
} | ||
|
||
return presets; | ||
}, | ||
|
||
getPresetByStructure: function( structure ) { | ||
var parsedStructure = this.getParsedStructure( structure ); | ||
|
||
return this.getPresets( parsedStructure.columnsCount, parsedStructure.presetIndex ); | ||
}, | ||
|
||
getParsedStructure: function( structure ) { | ||
structure += ''; // Make sure this is a string | ||
|
||
return { | ||
columnsCount: structure.slice( 0, -1 ), | ||
presetIndex: structure.substr( -1 ) | ||
}; | ||
}, | ||
|
||
getPresetSVG: function( preset, svgWidth, svgHeight, separatorWidth ) { | ||
svgWidth = svgWidth || 100; | ||
svgHeight = svgHeight || 50; | ||
separatorWidth = separatorWidth || 2; | ||
|
||
var absolutePresetValues = this.getAbsolutePresetValues( preset ), | ||
presetSVGPath = this._generatePresetSVGPath( absolutePresetValues, svgWidth, svgHeight, separatorWidth ); | ||
|
||
return this._createSVGPreset( presetSVGPath, svgWidth, svgHeight ); | ||
}, | ||
|
||
_createSVGPreset: function( presetPath, svgWidth, svgHeight ) { | ||
var svg = document.createElementNS( 'http://www.w3.org/2000/svg', 'svg' ); | ||
|
||
svg.setAttributeNS( 'http://www.w3.org/2000/xmlns/', 'xmlns:xlink', 'http://www.w3.org/1999/xlink' ); | ||
svg.setAttribute( 'viewBox', '0 0 ' + svgWidth + ' ' + svgHeight ); | ||
|
||
var path = document.createElementNS( 'http://www.w3.org/2000/svg', 'path' ); | ||
|
||
path.setAttribute( 'd', presetPath ); | ||
|
||
svg.appendChild( path ); | ||
|
||
return svg; | ||
}, | ||
|
||
_generatePresetSVGPath: function( preset, svgWidth, svgHeight, separatorWidth ) { | ||
var DRAW_SIZE = svgWidth - separatorWidth * ( preset.length - 1 ); | ||
|
||
var xPointer = 0, | ||
dOutput = ''; | ||
|
||
for ( var i = 0; i < preset.length; i++ ) { | ||
if ( i ) { | ||
dOutput += ' '; | ||
} | ||
|
||
var increment = preset[ i ] / 100 * DRAW_SIZE; | ||
|
||
xPointer += increment; | ||
|
||
dOutput += 'M' + ( +xPointer.toFixed( 4 ) ) + ',0'; | ||
|
||
dOutput += 'V' + svgHeight; | ||
|
||
dOutput += 'H' + ( +( xPointer - increment ).toFixed( 4 ) ); | ||
|
||
dOutput += 'V0Z'; | ||
|
||
xPointer += separatorWidth; | ||
} | ||
|
||
return dOutput; | ||
} | ||
}; | ||
|
||
module.exports = presetsFactory; |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Large diffs are not rendered by default.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Large diffs are not rendered by default.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Large diffs are not rendered by default.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Large diffs are not rendered by default.