AX $(function() { /** * xbglay extend */ var xbgLay = function() { this.settings = { trigger_elm: '#layer_trigger', overlay: '#xbglay', bottom_layer: '#xbg_bottom', close_btn: '.close_image' , opacity: 0.6, lay_add_top: 0, lay_add_left: 0, closeImage: '//s.eximg.jp/exblog/user2/img/facebox/icon-close.gif?1490591799', loadingImage: '//s.eximg.jp/exblog/user2/img/facebox/img-loading.gif?1490591799', event_suffix: 'xbglay' }; }; $.extend(xbgLay.prototype, { init: function(settings) { // 初期値設定 $.extend(this.settings , settings); /** * @type {?{ * trigger_elm: {string}, * close_btn: {string}, * closeImage: {string}, * loadingImage: {string}, * overlay: {string} * }} */ var s = this.settings; // bind $(s.trigger_elm).bind('click', {'settings': s}, this.start); $(s.close_btn).bind('click', {'settings': s}, this.hidden); $(document).on('click', '.xbglay_bg', {'settings': s}, this.hidden); // preload var preload = [new Image(), new Image()]; preload[0].src = s.closeImage; preload[1].src = s.loadingImage; $(s.overlay).find('.b:first, .bl, .br, .tl, .tr').each(function() { var i = new Image(); i.src = $(this).css('background-image').replace(/url\(['"]?(.+?)['"]?\)/, '$1'); preload.push(i); }); }, start: function(event) { /** * @type {?{ * bottom_layer: {string}, * opacity: {number}, * lay_add_top: {number}, * lay_add_left: {number}, * event_suffix: {string}, * overlay: {string} * }} */ var op = event.data.settings; if ($(op.bottom_layer).length == 0) { $('body').append('
'); } // div#xbg_bottom を半透明でoverlay $(op.bottom_layer).hide().css('opacity', op.opacity).addClass('xbglay_bg').fadeIn(200); // $('select,object').hide(); $('object').hide(); // overlay contents at center $(document).trigger('before_show.' + op.event_suffix); var layer_top = $(document).scrollTop() + ($(window).height() - $(op.overlay).height()) / 2; layer_top += op.lay_add_top; var layer_left= $(document).scrollLeft() + ($(window).width() - $(op.overlay).width()) / 2; layer_left += op.lay_add_left; $(op.overlay).css('top', layer_top).css('left', layer_left).show(); // finish event $(document).trigger('after_show.' + op.event_suffix); return false; }, hidden: function(event) { /** * @type {?{ * bottom_layer: {string}, * opacity: {number}, * lay_add_top: {number}, * lay_add_left: {number}, * event_suffix: {string}, * overlay: {string} * }} */ var op = event.data.settings; $(document).trigger('before_hidden.' + op.event_suffix); // delete overlay $(op.overlay).fadeOut(200); $('select,object').show(); // delete bottom layer $(op.bottom_layer).fadeOut(200, function() { $(document).trigger('after_hidden.' + op.event_suffix); }); return false; } }); jQuery.fn.extend({}); $.fn.xbglay = function(settings) { return this.each(function() { (new xbgLay).init(settings); }); }; /** * exblogFan class */ var exblogFan = function() { this.reload_flag = 0; }; exblogFan.prototype = { reload: function() { if (this.reload_flag) { window.location.reload(); } }, updateReloadFlag: function() { if (!this.reload_flag) { this.reload_flag = 1; } }, formReset: function() { $('#fan_content').val(''); $('#fan_blogurl').val(''); }, rssResultMsg: function(msg, reload_flag) { $('#fan_result').css('display', 'block'); $('#fan_result_msg').text(msg); $('#fan_add').css('display', 'none'); $('#fan_cancel').css('display', 'none'); if (reload_flag) { this.updateReloadFlag() } }, formSubmit: function(f) { $(f).attr('action', ExBlog.Common.getRootUrl() + 'pg/api/entryfanmessage/'); $('#fan_blogurl').val(ExBlog.Common.getBlogUrl()); if (this.formCheck(f)) { f.submit(); this.formReset(); } return true; }, formCheck: function(f) { var COMMENT_MAX_LENGTH = 1024; var target = $(f).find('textarea[name=content]'); if (!target.val().trim()) { alert('この内容には必ず入力してください。'); return false; } if (target.val().length > COMMENT_MAX_LENGTH) { alert('内容が多すぎますので ' + (target.val().length - COMMENT_MAX_LENGTH) + '文字以上を減らした後、もう一度行ってください。'); return false; } return true; } }; /** * exblogRss class */ var exblogRss = function() { this.submitCount = 0; this.reload_flag = 0; }; exblogRss.prototype = { urlCheck: function (form) { var target = $(form).find(':text[name=rsslink]'); if (!target.val().trim()) { alert('この内容には必ず入力してください。'); return false; } var url = form.rsslink.value; // loading icon show $('#rss_info').css('display', 'block') .append('
'); // 登録ボタン $('#rss_add').css('display', 'none'); var obj = this; $.getJSON("https://query.yahooapis.com/v1/public/yql?q=select%20channel.title%2C%20channel.link%20from%20xml%20where%20url%20%3D%20'" + encodeURIComponent(url) + "'%20limit%201&format=json", function(result) { // loading icon delete $('.rss_loading').remove(); if (!result || result.error || !result.query.results) { form.rsslink.value = ''; obj.formReset(); $('#rss_name').text('無効なURLです。'); return false; } else { var feed = (result.query.results.RDF) ? result.query.results.RDF.channel : result.query.results.rss.channel; var description = feed.description; var link_top = typeof(feed.link) === 'object' ? feed.link.href : feed.link; var title_top = feed.title; $("#rss_name").text("サイト名 : " + title_top); $("#url").text("URL : " + link_top); $("#rss_url").text("RSS : " + url); $("#rss_blogname").val(title_top); $("#rss_blogurl").val(link_top); $("#rsslink").val(url); // 登録ボタン $('#rss_add').css('display', 'block'); } }); }, formSubmit: function(f) { $(f).attr('action', ExBlog.Common.getRootUrl() + 'parts/link/'); if (this.submitCount > 0) { return false; } if (this.formCheck(f)) { this.submitCount++; f.submit(); } return true; }, formSubmitCancel: function() { this.submitCount--; }, formReset: function() { $('.rss_border :text').val(''); $('#rss_name').text(''); $('#url').text(''); $('#rss_url').text(''); $('#rss_blogname').val(''); $('#rss_blogurl').val(''); $('#rss_add').css('display', 'none'); }, formCheck: function(f) { if (!f.rsslink.value) return false; if (!f.rssblogurl.value) return false; return f.blogname.value; }, reload: function() { if (this.reload_flag) { window.location.reload(); } }, rssResultMsg: function (msg, reload_flag) { this.submitCount--; $('#rss_result').css('display', 'block'); $('#rss_result_msg').text(msg); $('#rss_add').css('display', 'none'); if (reload_flag) { this.reload_flag = 1; } }, rssResultMsgClear: function() { $('#rss_result').css('display', 'none'); $('#rss_result_msg').text(''); this.formReset(); } }; /** * Set Event Listener */ // callbackで別ページから呼ばれるのでwindow配下に置く var xbg_fan = new exblogFan(); window.xbg_fan = xbg_fan; $('#xbgfan').xbglay({ trigger_elm: '#fan_trigger', overlay: '#xbgfan', event_suffix: 'xbgfan' }); $(document).bind('after_show.xbgfan', function() { $('#xbgfan :input[name=content]').focus(); }); $(document).bind('after_hidden.xbgfan', function() { xbg_fan.reload(); }); $('#fan_cancel').click(function() { $('#xbgfan .close_image').trigger('click'); }); $('#fan_add').click(function() { xbg_fan.formSubmit(document.frmfan); }); // callbackで別ページから呼ばれるのでwindow配下に置く var xbg_rss = new exblogRss(); window.xbg_rss = xbg_rss; $('#xbglay').xbglay(); $(document).bind('after_hidden.xbglay', function() { xbg_rss.rssResultMsgClear(); xbg_rss.reload(); }); $(document).bind('after_show.xbglay', function() { $('#layer_info :input[name=rsslink]').focus(); }); $('#url_check').click(function() { xbg_rss.urlCheck(document.frminslink); }); $('#rss_result').click(function() { xbg_rss.rssResultMsgClear(); $('#layer_info :input[name=rsslink]').focus(); }); $('#rss_add').click(function() { return xbg_rss.formSubmit(document.frminslink); }); // disable submit if press enter $(':text[name=rsslink]').on('keyup keypress', function(e) { var code = e.keyCode || e.which; if (code == 13) { e.preventDefault(); return false; } }); });