(function($){ var defaults = { id: 0, post: 0, text: 'Спасибо за раздачу!' } function _post(repXML, id, text){ status('LOADING'); $.ajax({ type: 'POST', url: '/index/', timeout: 10000, data: { a:23,t:1,act:2,ref: document.location.href, s:id, reason: text, code: $('#addReputation-code #secuCode').val(), seckey: $('#addReputation-code input[name="seckey"]').val(), ssid: $('input[name="ssid"]', repXML).val(), _tp_: 'xml' }, success: function(response){ response = $('cmd[p="innerHTML"]',response).text(); if(response.indexOf('myWinLoadSD') != -1){ status('OK'); _uWnd.close('reputation'); _uWnd.alert('<br>Вы успешно отблагодарили, пользователя!','',{close:1,w:250,h:80,tm:7000,align:'center'}); }else{ status('EROR'); _updateCaptcha(id); _uWnd.alert('<br>'+$(response).attr('title'),'',{close:1,w:250,h:80,tm:7000,align:'center'}); } }, error: function(){ status('EROR'); _uWnd.alert('<br>Ошибка, повторите запрос.','',{close:1,w:250,h:80,tm:7000,align:'center'}); } }); } function _get(id){ var documentHtml; $.ajax({url: '/index/23-'+id, async: 0}).done(function(resp){ documentHtml = $('cmd[p="content"]', resp).text(); }); return documentHtml; } /* Получение капчи */ function _getCaptcha(id, htmlNew){ var code_input = '<input type="text" id="secuCode" style="width:90px;height:30px;float:left;box-sizing: border-box;-moz-box-sizing: border-box;font-size:18px;">'; var code = $('input[name="seckey"]', htmlNew).size() ? '<div id="addReputation-code">'+code_input+$('#secuImg',htmlNew).prop('outerHTML')+$('input[name="seckey"]',htmlNew).prop('outerHTML')+'</div><style>#addReputation-code img{height:28px;padding: 1px 5px !important}</style>' : 0; return code; } /* Обновление капчи */ function _updateCaptcha(id){ var newCap = _getCaptcha(id); $('#addReputation-code').html(newCap); } /* Статус отправки */ function status(isType){ var type = {'OK': 'myWinLoadSD', 'EROR': 'myWinLoadSF', 'LOADING': 'myWinLoadS'} $('.addReputation .status').html('<div class="'+type[isType]+'"></div>'); } /* Плагин */ $.addReputation = function(options){ var settings = $.extend({}, defaults, options); var xml = _get(settings.id); if(settings.post){ _post(xml, settings.id, $('.addReputation #comment').val()); return false; } var button = _uButton(null,'button',{style:1,text:'Сказать спасибо',content:'onclick="$.addReputation({post:1,id:'+settings.id+'});"'}); var captcha = _getCaptcha(settings.id, xml); new _uWnd('reputation','Спасибо',260, captcha ? 180 : 150, {autosize:0,resize:0,notaskbar:1,fadetype:2,fadespeed:500,fadeclosetype:1,fadeclosespeed:500,align:'left'},'<div class="addReputation"><fieldset style="margin-top:5px;padding-bottom:5px;"><legend>Ваш комментарий</legend><input type="text" id="comment" value="'+settings.text+'" style="width:100%;box-sizing: border-box;-moz-box-sizing: border-box;"></fieldset>'+ (captcha ? '<fieldset><legend>Введите код безопасности</legend><div>'+captcha+'</div></fieldset>' : '') +'<fieldset style="margin-top:5px;padding:5px 5px"><div style="float:right" class="status"></div>'+button+'</fieldset></div>'); } })(window.jQuery);