-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
rewrite compileless field and the compiler
- Loading branch information
1 parent
3a1deb2
commit 31b18fe
Showing
3 changed files
with
51 additions
and
76 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,45 +1,43 @@ | ||
function sendCompileRequest(compileUrl) | ||
{ | ||
// Update the request form; | ||
var compilerForm = new Element('form'); | ||
var fields = ['baseFontSize', 'sansFontFamily', 'serifFontFamily', 'baseFontFamily', 'baseLineHeight', 'textColor', 'linkColor', 'linkColorHover']; | ||
|
||
for (var i = 0; i < fields.length; i++ ) | ||
{ | ||
$('compile_'+fields[i]).set('value', $('jform_params_'+fields[i]).get('value')); | ||
$('compile_'+fields[i]).clone().inject(compilerForm); | ||
} | ||
|
||
var imports = ['responsive-767px-max', 'responsive-768px-979px', 'responsive-1200px-min']; | ||
for (var i = 0; i < imports.length; i++) | ||
{ | ||
$('compile_' + imports[i]).set('value', isYes(imports[i])); | ||
$('compile_' + imports[i]).clone().inject(compilerForm); | ||
} | ||
|
||
var request = new Request({ | ||
url: compileUrl, | ||
onRequest: function() { | ||
$('compile_result').set('text', 'compiling....'); | ||
jQuery(document).ready(function() { | ||
jQuery('.btn-compile').on('click', function() { | ||
// Data skeleton | ||
var data = { | ||
compile: { | ||
variables: {}, | ||
imports: {} | ||
} | ||
}, | ||
onSuccess: function(responseText) { | ||
$('compile_result').set('html', responseText); | ||
}, | ||
onFailure: function(){ | ||
$('compile_result').set('text', 'Sorry, your request failed :('); | ||
variables = ['baseFontSize', 'sansFontFamily', 'serifFontFamily', 'baseFontFamily', 'baseLineHeight', 'textColor', 'linkColor', 'linkColorHover'], | ||
imports = ['responsive-767px-max', 'responsive-768px-979px', 'responsive-1200px-min'], | ||
alert_tpl = '<div class="alert fade in"><a class="close" data-dismiss="alert" href="#">×</a></div>'; | ||
|
||
// Prepare variables | ||
for (var i = 0; i < variables.length; i++) { | ||
data.compile.variables[variables[i]] = jQuery('#jform_params_' + variables[i]).val(); | ||
} | ||
|
||
// Prepare imports | ||
for (var i = 0; i < imports.length; i++) { | ||
data.compile.imports[imports[i] + '.less'] = jQuery('input[name="jform[params][' + imports[i]+']"]:checked').val(); | ||
} | ||
|
||
// Loading animation | ||
jQuery('#compile-result').html('<img src="../media/system/images/modal/spinner.gif" />'); | ||
|
||
// Send the data | ||
jQuery.ajax({ | ||
url: jQuery(this).data('compiler-href'), | ||
method: 'POST', | ||
data: data | ||
}).done(function(response) { | ||
var $alert = jQuery(alert_tpl).addClass('alert-success').append(response.message); | ||
jQuery('#compile-result').html($alert); | ||
}).error(function(jqXHR, textStatus, errorThrown) { | ||
var $alert = jQuery(alert_tpl).addClass('alert-danger').append(errorThrown); | ||
jQuery('#compile-result').html($alert); | ||
}); | ||
|
||
// Prevent form submission | ||
return false; | ||
}); | ||
|
||
request.post(compilerForm); | ||
} | ||
|
||
function isYes(field) | ||
{ | ||
field = field.replace(/-/g, '_'); | ||
field = field.replace(/\./g, '_'); | ||
|
||
if ($('jform_params_' + field + '0').get('checked') == true) | ||
return 0; | ||
else | ||
return 1; | ||
} | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters