| 1 |
|
| 2 |
jQuery(document).ready(function($) { |
| 3 |
|
| 4 |
mbsEditor = function () |
| 5 |
{ |
| 6 |
var maxAdmin; |
| 7 |
var mbIcons; |
| 8 |
} |
| 9 |
|
| 10 |
mbsEditor.prototype.init = function () |
| 11 |
{ |
| 12 |
this.maxAdmin = window.maxFoundry.maxadmin; |
| 13 |
|
| 14 |
$(document).on('maxajax_success_network-settings', $.proxy(this.showSettings, this) ); |
| 15 |
$(document).on('maxajax_success_save-network', $.proxy(this.settingsUpdated, this) ); |
| 16 |
$(document).on('maxajax_success_remove-networksettings', $.proxy(this.settingsUpdated, this)); |
| 17 |
$(document).on('maxajax_success_show-customnetworks', $.proxy(this.showCustomNetworks, this)); |
| 18 |
|
| 19 |
$(document).on('maxajax_success_import-customnetworks', $.proxy(this.networksImported, this)); |
| 20 |
|
| 21 |
this.mbIcons = window.maxFoundry.maxIcons; |
| 22 |
} |
| 23 |
|
| 24 |
mbsEditor.prototype.showSettings = function(e, result, status) |
| 25 |
{ |
| 26 |
result = JSON.parse(result); |
| 27 |
|
| 28 |
if (result.output) |
| 29 |
{ |
| 30 |
$('.network_editor .inside').html(result.output); |
| 31 |
if (result.title) |
| 32 |
{ |
| 33 |
$('.network_editor .title').html(result.title); |
| 34 |
} |
| 35 |
} |
| 36 |
|
| 37 |
this.doColorPicker(); |
| 38 |
$(document).trigger('mbsocial-editor-settings-loaded'); |
| 39 |
window.maxFoundry.maxadmin.initConditionials(); |
| 40 |
$('#icon_type').trigger('change'); // manual update, to fix |
| 41 |
window.maxFoundry.maxSocial.form_updated = false; // loading is not changing |
| 42 |
|
| 43 |
} |
| 44 |
|
| 45 |
mbsEditor.prototype.doColorPicker = function() |
| 46 |
{ |
| 47 |
colorPalette = (mbpro_options.colorPalette !== '' ? mbpro_options.colorPalette : true); |
| 48 |
|
| 49 |
// colors |
| 50 |
$('.maxbuttons-social .network_editor .mb-color-field').wpColorPicker( |
| 51 |
{ |
| 52 |
width: 300, |
| 53 |
palettes: colorPalette, |
| 54 |
change: $.proxy( _.throttle(function(event, ui) { |
| 55 |
event.preventDefault(); |
| 56 |
var target = $(event.target); |
| 57 |
var color = ui.color.toString(); |
| 58 |
|
| 59 |
if (color.indexOf('#') === -1) |
| 60 |
color = '#' + color; |
| 61 |
|
| 62 |
var id = target.attr('id'); |
| 63 |
$('#' + id).val(color).trigger('change'); |
| 64 |
|
| 65 |
}, 200), this), |
| 66 |
} |
| 67 |
); |
| 68 |
} |
| 69 |
|
| 70 |
mbsEditor.prototype.showCustomNetworks = function (e, result, status) |
| 71 |
{ |
| 72 |
var result = JSON.parse(result); |
| 73 |
if (result.status == 'error') |
| 74 |
{ |
| 75 |
$('.network_editor .inside').html('<h4 class="load-error">' + result.message + '</h4>'); |
| 76 |
} |
| 77 |
else { |
| 78 |
$('.network_editor .inside').html(result.output); |
| 79 |
|
| 80 |
if (result.title) |
| 81 |
{ |
| 82 |
$('.network_editor .title').html(result.title); |
| 83 |
} |
| 84 |
$('.network_editor ul li').off(); |
| 85 |
$('.network_editor ul li').on('click', $.proxy(this.toggleCustom, this)); |
| 86 |
|
| 87 |
} |
| 88 |
} |
| 89 |
|
| 90 |
mbsEditor.prototype.networksImported = function (e, result) |
| 91 |
{ |
| 92 |
|
| 93 |
this.notifySaved(e, result); |
| 94 |
window.location.reload(true); |
| 95 |
} |
| 96 |
|
| 97 |
mbsEditor.prototype.toggleCustom = function (e) |
| 98 |
{ |
| 99 |
var target = $(e.target); |
| 100 |
if (! $(target).hasClass('the_network')) |
| 101 |
{ |
| 102 |
target = $(target).parents('.the_network'); |
| 103 |
} |
| 104 |
|
| 105 |
if ( $(target).hasClass('selected')) |
| 106 |
{ |
| 107 |
$(target).removeClass('selected'); |
| 108 |
} |
| 109 |
else { |
| 110 |
$(target).addClass('selected'); |
| 111 |
} |
| 112 |
|
| 113 |
var selected = $('.network_editor ul li.selected'); |
| 114 |
var count = $(selected).length; |
| 115 |
|
| 116 |
$('.cns-toolbar .selected').html(count); |
| 117 |
|
| 118 |
if (count > 0) |
| 119 |
{ |
| 120 |
$('.cns-toolbar button').prop('disabled', false); |
| 121 |
} |
| 122 |
else { |
| 123 |
$('.cns-toolbar button').prop('disabled', true); |
| 124 |
} |
| 125 |
|
| 126 |
var networks = []; |
| 127 |
$(selected).each(function() |
| 128 |
{ |
| 129 |
networks.push($(this).data('network')); |
| 130 |
|
| 131 |
}) |
| 132 |
$('#selected_custom').val(networks.join(',')); |
| 133 |
|
| 134 |
} |
| 135 |
|
| 136 |
mbsEditor.prototype.settingsUpdated = function(e, result, status) |
| 137 |
{ |
| 138 |
if (typeof result !== 'object') |
| 139 |
var parsed_result = JSON.parse(result); |
| 140 |
|
| 141 |
if (parsed_result.output) |
| 142 |
this.showSettings(e, result, status); |
| 143 |
|
| 144 |
this.notifySaved(e, result, status); |
| 145 |
|
| 146 |
if (parsed_result.reload) |
| 147 |
{ |
| 148 |
window.location.reload(true); |
| 149 |
} |
| 150 |
} |
| 151 |
|
| 152 |
mbsEditor.prototype.networkRemoved = function(e, result, status) |
| 153 |
{ |
| 154 |
|
| 155 |
} |
| 156 |
|
| 157 |
mbsEditor.prototype.notifySaved = function(e,result,status) |
| 158 |
{ |
| 159 |
|
| 160 |
if (typeof result !== 'object') |
| 161 |
var result = JSON.parse(result); |
| 162 |
var modal = window.maxFoundry.maxmodal; |
| 163 |
|
| 164 |
modal.newModal('save_done'); |
| 165 |
modal.setTitle(result.title); |
| 166 |
modal.setContent(''); |
| 167 |
modal.show(); |
| 168 |
|
| 169 |
this.form_updated = false; // set updated to false |
| 170 |
window.maxFoundry.maxSocial.form_updated = false; |
| 171 |
window.setTimeout( function () { modal.fadeOut(); }, 1000); |
| 172 |
} |
| 173 |
|
| 174 |
if (typeof window.maxFoundry === 'undefined') |
| 175 |
window.maxFoundry = {}; |
| 176 |
|
| 177 |
window.maxFoundry.maxSocialSettings = new mbsEditor(); |
| 178 |
window.maxFoundry.maxSocialSettings.init(); |
| 179 |
}); // jquery |
| 180 |
|