| 1 |
|
| 2 |
var mbResponsive = function ($) |
| 3 |
{ |
| 4 |
this.jquery = $; |
| 5 |
} |
| 6 |
|
| 7 |
|
| 8 |
mbResponsive.prototype = { |
| 9 |
jquery : null, |
| 10 |
mbAdmin: null, |
| 11 |
} |
| 12 |
|
| 13 |
mbResponsive.prototype.init = function (mbAdmin) |
| 14 |
{ |
| 15 |
$ = this.jquery; |
| 16 |
|
| 17 |
this.mbAdmin = mbAdmin; |
| 18 |
|
| 19 |
this.checkAutoQuery(); |
| 20 |
|
| 21 |
$('input[name="auto_responsive"]').on('click', $.proxy(this.checkAutoQuery,this)); |
| 22 |
$('.add_media_query').on('click', $.proxy(this.addMediaQuery, this)); |
| 23 |
//$('.removebutton').on('click', ); |
| 24 |
$(document).on('click', '.removebutton', $.proxy(this.removeMediaQuery, this)); |
| 25 |
} |
| 26 |
|
| 27 |
mbResponsive.prototype.checkAutoQuery = function() |
| 28 |
{ |
| 29 |
$ = this.jquery; |
| 30 |
|
| 31 |
if ( $('input[name="auto_responsive"]').is(':checked') ) |
| 32 |
{ |
| 33 |
|
| 34 |
$('.media_queries_options').hide(); |
| 35 |
$('.option-design.new-query').hide(); |
| 36 |
} |
| 37 |
else |
| 38 |
{ |
| 39 |
$('.media_queries_options').show(); |
| 40 |
$('.option-design.new-query').show(); |
| 41 |
} |
| 42 |
} |
| 43 |
|
| 44 |
mbResponsive.prototype.addMediaQuery = function() |
| 45 |
{ |
| 46 |
$ = this.jquery; |
| 47 |
|
| 48 |
this.mbAdmin.saveIndicator(true); |
| 49 |
var new_option = $('.media_option_prot').children().clone(); |
| 50 |
|
| 51 |
var new_query = $("#new_query").val(); |
| 52 |
var new_title = $("#new_query :selected").text(); |
| 53 |
var new_desc = $("#media_desc").children('#' + new_query).text(); |
| 54 |
|
| 55 |
$(new_option).data('query', new_query); |
| 56 |
$(new_option).children('input[name="media_query[]"]').val(new_query); |
| 57 |
$(new_option).children('.title').text(new_title); |
| 58 |
$(new_option).children('.description').text(new_desc); |
| 59 |
|
| 60 |
if (new_query == 'custom') |
| 61 |
{ |
| 62 |
|
| 63 |
$(new_option).find('.custom').removeClass('hidden'); |
| 64 |
} |
| 65 |
|
| 66 |
var new_index = $('input[name="next_media_index"]').val(); |
| 67 |
|
| 68 |
// rename new field to the proper ID |
| 69 |
$(new_option).find('label, select, input').each(function () { |
| 70 |
|
| 71 |
var name = $(this).attr('name'); |
| 72 |
var id = $(this).attr('id'); |
| 73 |
var data = $(this).data('field'); |
| 74 |
var tagname = $(this).prop('tagName').toLowerCase(); |
| 75 |
|
| 76 |
if (typeof id !== 'undefined') |
| 77 |
$(this).attr('id', id.replace('[]','[' + new_index + ']')); |
| 78 |
if (typeof name !== 'undefined') |
| 79 |
$(this).attr('name', name.replace('[]','[' + new_index + ']')); |
| 80 |
if (typeof data !== 'undefined') |
| 81 |
$(this).data('field', data.replace('[]','[' + new_index + ']')); |
| 82 |
if (tagname == 'label') |
| 83 |
{ |
| 84 |
var attrfor = $(this).attr('for'); |
| 85 |
if ( typeof attrfor != 'undefined') |
| 86 |
$(this).attr('for', attrfor.replace('[]','[' + new_index + ']')); |
| 87 |
} |
| 88 |
|
| 89 |
}) |
| 90 |
|
| 91 |
$(document).trigger('reinitConditionals'); |
| 92 |
|
| 93 |
new_index = parseInt(new_index); |
| 94 |
|
| 95 |
$('input[name="next_media_index"]').val( (new_index+1) ); |
| 96 |
|
| 97 |
if (new_query !== 'custom') |
| 98 |
{ |
| 99 |
$('#new_query :selected').prop('disabled', true); |
| 100 |
$('#new_query :selected').prop('selected', false); |
| 101 |
} |
| 102 |
|
| 103 |
$('.new_query_space').append(new_option); |
| 104 |
|
| 105 |
var pos = $('.new_query_space').offset().top; |
| 106 |
$(window).scrollTop( (pos-100) ); |
| 107 |
|
| 108 |
} |
| 109 |
|
| 110 |
mbResponsive.prototype.removeMediaQuery = function(e) |
| 111 |
{ |
| 112 |
$ = this.jquery; |
| 113 |
var target = e.target; |
| 114 |
|
| 115 |
var query = $(target).parents('.media_query').data('query'); |
| 116 |
$(target).parents('.media_query').fadeOut(function() { $(this).remove() } ); |
| 117 |
|
| 118 |
$('#new_query option[value="' + query + '"]').prop('disabled', false); |
| 119 |
} |
| 120 |
|
| 121 |
|
| 122 |
|