| 1 |
|
| 2 |
function mbResponsive() |
| 3 |
{ |
| 4 |
|
| 5 |
} |
| 6 |
|
| 7 |
mbResponsive.prototype = { |
| 8 |
mbAdmin: null, |
| 9 |
responsiveMap: null, |
| 10 |
} |
| 11 |
|
| 12 |
mbResponsive.prototype.init = function (mbAdmin) |
| 13 |
{ |
| 14 |
|
| 15 |
this.mbAdmin = mbAdmin; |
| 16 |
|
| 17 |
if ($('#new-button-form').length == 0) // Don't load outside button editor |
| 18 |
return; |
| 19 |
|
| 20 |
this.checkAutoQuery(); |
| 21 |
|
| 22 |
$('input[name="auto_responsive"]').on('click', $.proxy(this.checkAutoQuery,this)); |
| 23 |
$('.add_media_query').on('click', $.proxy(this.addMediaQuery, this)); |
| 24 |
|
| 25 |
this.responsiveMap = JSON.parse(responsiveMap); |
| 26 |
|
| 27 |
$(document).on('click', '.removebutton', $.proxy(this.removeMediaQuery, this)); |
| 28 |
//$(document).on('click', '.responsive_preview', $.proxy(this.toggleResponsivePreview, this)); |
| 29 |
|
| 30 |
} |
| 31 |
|
| 32 |
mbResponsive.prototype.checkAutoQuery = function() |
| 33 |
{ |
| 34 |
|
| 35 |
if ( $('input[name="auto_responsive"]').is(':checked') ) |
| 36 |
{ |
| 37 |
|
| 38 |
$('.media_queries_options').hide(); |
| 39 |
$('.option-design.new-query').hide(); |
| 40 |
} |
| 41 |
else |
| 42 |
{ |
| 43 |
$('.media_queries_options').show(); |
| 44 |
$('.option-design.new-query').show(); |
| 45 |
} |
| 46 |
} |
| 47 |
|
| 48 |
mbResponsive.prototype.addMediaQuery = function() |
| 49 |
{ |
| 50 |
|
| 51 |
this.mbAdmin.saveIndicator(true); |
| 52 |
var new_option = $('.media_option_prot').children().clone(); |
| 53 |
|
| 54 |
var new_query = $("#new_query").val(); |
| 55 |
var new_title = $("#new_query :selected").text(); |
| 56 |
var new_desc = $("#media_desc").children('#' + new_query).text(); |
| 57 |
|
| 58 |
$(new_option).data('query', new_query); |
| 59 |
$(new_option).children('input[name="media_query[]"]').val(new_query); |
| 60 |
$(new_option).children('.title').text(new_title); |
| 61 |
$(new_option).children('.description').text(new_desc); |
| 62 |
|
| 63 |
if (new_query == 'custom') |
| 64 |
{ |
| 65 |
|
| 66 |
$(new_option).find('.custom').removeClass('hidden'); |
| 67 |
} |
| 68 |
|
| 69 |
var new_index = $('input[name="next_media_index"]').val(); |
| 70 |
|
| 71 |
// rename new field to the proper ID |
| 72 |
$(new_option).find('label, select, input').each(function () { |
| 73 |
|
| 74 |
var name = $(this).attr('name'); |
| 75 |
var id = $(this).attr('id'); |
| 76 |
var data = $(this).data('field'); |
| 77 |
var tagname = $(this).prop('tagName').toLowerCase(); |
| 78 |
|
| 79 |
if (typeof id !== 'undefined') |
| 80 |
$(this).attr('id', id.replace('[]','[' + new_index + ']')); |
| 81 |
if (typeof name !== 'undefined') |
| 82 |
$(this).attr('name', name.replace('[]','[' + new_index + ']')); |
| 83 |
if (typeof data !== 'undefined') |
| 84 |
$(this).data('field', data.replace('[]','[' + new_index + ']')); |
| 85 |
if (tagname == 'label') |
| 86 |
{ |
| 87 |
var attrfor = $(this).attr('for'); |
| 88 |
if ( typeof attrfor != 'undefined') |
| 89 |
$(this).attr('for', attrfor.replace('[]','[' + new_index + ']')); |
| 90 |
} |
| 91 |
|
| 92 |
}) |
| 93 |
|
| 94 |
$(document).trigger('reinitConditionals'); |
| 95 |
|
| 96 |
new_index = parseInt(new_index); |
| 97 |
|
| 98 |
$('input[name="next_media_index"]').val( (new_index+1) ); |
| 99 |
|
| 100 |
if (new_query !== 'custom') |
| 101 |
{ |
| 102 |
$('#new_query :selected').prop('disabled', true); |
| 103 |
$('#new_query :selected').prop('selected', false); |
| 104 |
} |
| 105 |
|
| 106 |
$('.new_query_space').append(new_option); |
| 107 |
|
| 108 |
var pos = $('.new_query_space').offset().top; |
| 109 |
$(window).scrollTop( (pos-100) ); |
| 110 |
|
| 111 |
} |
| 112 |
|
| 113 |
mbResponsive.prototype.removeMediaQuery = function(e) |
| 114 |
{ |
| 115 |
var target = e.target; |
| 116 |
|
| 117 |
var query = $(target).parents('.media_query').data('query'); |
| 118 |
$(target).parents('.media_query').fadeOut(function() { $(this).remove() } ); |
| 119 |
|
| 120 |
$('#new_query option[value="' + query + '"]').prop('disabled', false); |
| 121 |
} |
| 122 |
|
| 123 |
mbResponsive.prototype.toggleResponsivePreview = function(e) |
| 124 |
{ |
| 125 |
var target = $(e.target); |
| 126 |
var id = target.attr('id') |
| 127 |
id = id.replace('mq_preview[',''); |
| 128 |
id = id.replace(']', ''); |
| 129 |
this.renderPreview(id); |
| 130 |
} |
| 131 |
|
| 132 |
|
| 133 |
mbResponsive.prototype.renderPreview = function (id) |
| 134 |
{ |
| 135 |
var excluded = ['mq_container_width', 'mq_container_float','mq_custom_minwidth','mq_custom_minheight', 'mq_hide']; |
| 136 |
var responsiveMap = this.responsiveMap; |
| 137 |
var self = this; |
| 138 |
|
| 139 |
$.each(responsiveMap, function (index) { |
| 140 |
|
| 141 |
var css = this.css; |
| 142 |
var field_pattern = '[id^="' + index + '["]'; |
| 143 |
var unit_pattern = '[id^="' + index + '_unit["]'; |
| 144 |
var $field = $(field_pattern).eq(id); |
| 145 |
|
| 146 |
var field_id = $field.attr('id'); |
| 147 |
field_id = field_id.replace(/\[[0-9]\]/gi, ''); |
| 148 |
|
| 149 |
if ($.inArray(field_id, excluded) >= 0 ) |
| 150 |
{ |
| 151 |
return true; // continue |
| 152 |
} |
| 153 |
if (field_id.indexOf('_unit') >= 0 ) |
| 154 |
{ |
| 155 |
return true; |
| 156 |
} |
| 157 |
|
| 158 |
var value= $field.val(); |
| 159 |
var unit_val = ''; |
| 160 |
|
| 161 |
if (typeof responsiveMap[index + '_unit'] !== 'undefined') |
| 162 |
{ |
| 163 |
var unit_val = $(unit_pattern).eq(id).val(); |
| 164 |
} |
| 165 |
|
| 166 |
|
| 167 |
var data = { css: css }; |
| 168 |
if (css == 'font-size') |
| 169 |
{ |
| 170 |
data.csspart = 'mb-text,mb-text2'; |
| 171 |
} |
| 172 |
|
| 173 |
self.mbAdmin.putCSS(data, value + unit_val) |
| 174 |
|
| 175 |
|
| 176 |
}); |
| 177 |
} |
| 178 |
|