Created
February 25, 2014 08:20
-
-
Save chappyhome/9204961 to your computer and use it in GitHub Desktop.
javascript, parent,弹出框js代码处理,点击按钮后返回数据到父窗口。
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| //tab | |
| $.fn.TabADS = function() { | |
| var obj = $(this); | |
| var currentClass = "select"; | |
| var tabs = obj.find(".tab_hd").find("li"); | |
| var conts = obj.find(".tab_cont"); | |
| var t; | |
| tabs.eq(0).addClass(currentClass); | |
| conts.hide(); | |
| conts.eq(0).show(); | |
| tabs.each(function(i) { | |
| $(this).bind("click", function() { | |
| conts.hide().eq(i).show(); | |
| tabs.removeClass(currentClass).eq(i).addClass(currentClass); | |
| }); | |
| }); | |
| } | |
| //新建分组 | |
| $.fn.CreateGroup = function() { | |
| var self = $(this); | |
| var tab = self.find("dd"); | |
| var cont = self.find(".create_new"); | |
| var create = self.find(".btn_02"); | |
| var edit = self.find(".ico_bj_small"); | |
| var ipt = self.find(".ipt_create"); | |
| tab.children(".edit_case").hide(); | |
| tab.children(".operate").hide(); | |
| cont.hide(); | |
| tab.mouseenter(function() { | |
| $(this).children(".operate").show(); | |
| }); | |
| tab.mouseleave(function() { | |
| $(this).children(".operate").hide(); | |
| }); | |
| edit.click(function() { | |
| $(this).parent().siblings('.link').hide(); | |
| $(this).parent().hide(); | |
| $(this).parent().siblings('.edit_case').show(); | |
| }); | |
| ipt.focusout(function() { | |
| $(this).parent().hide(); | |
| $(this).parent().siblings('.link').show(); | |
| }); | |
| create.click(function() { | |
| cont.show(); | |
| }); | |
| } | |
| //素材管理 | |
| $.fn.AppMsg = function() { | |
| var self = $(this); | |
| var obj = self.find('a'); | |
| obj.hide(); | |
| self.mouseenter(function() { | |
| $(this).children('.ico_create').hide(); | |
| obj.show(); | |
| }); | |
| self.mouseleave(function() { | |
| $(this).children('.ico_create').show(); | |
| obj.hide(); | |
| }); | |
| } | |
| //添加摘要 | |
| $.fn.AddURL = function() { | |
| var self = $(this); | |
| var obj = self.find('.js_addURL'); | |
| obj.click(function() { | |
| $(this).parent().hide(); | |
| $(this).parent().next().show(); | |
| }); | |
| } | |
| //多图文消息 | |
| $.fn.MultiMsg = function() { | |
| var self = $(this); | |
| var obj = self.find('.js_appmsg_item'); | |
| obj.hover(function() { | |
| $(this).toggleClass('show_mask'); | |
| }); | |
| } | |
| //显示详细资料 | |
| $.fn.DivShow = function() { | |
| var self = $(this); | |
| var obj = self.find('.js_obj'); | |
| obj.hover(function() { | |
| $(this).toggleClass('js_show'); | |
| }); | |
| } | |
| //选择素材 | |
| $.fn.AppmsgSelected = function() { | |
| var self = $(this); | |
| var obj = self.find('.appmsg'); | |
| obj.hover(function() { | |
| $(this).toggleClass('hover'); | |
| }); | |
| obj.click(function() { | |
| obj.removeClass('selected'); | |
| $(this).addClass('selected'); | |
| }); | |
| } | |
| //展开收起 | |
| $.fn.ShowMore = function() { | |
| var self = $(this); | |
| var obj = self.find('.ico_show'); | |
| var a = self.find('a'); | |
| obj.click(function() { | |
| $(this).parent().parent().toggleClass('open'); | |
| }); | |
| a.click(function() { | |
| $(this).parent().toggleClass('selected'); | |
| }); | |
| } | |
| //初始化左边 | |
| $(document).ready(function() { | |
| $('#mainList').ShowMore(); | |
| }); | |
| //golo | |
| window.golo = {}; | |
| golo.overlay = { | |
| show: function(id, zIndex) { | |
| id = id !== undefined ? id : ''; | |
| zIndex ? 0 : zIndex = 99; | |
| var o = $('#golo-overlay' + id); | |
| if (!o.length) { | |
| $("body").append('<div id="golo-overlay' + id + '" class="golo-overlay golo-overlay-hide" style="opacity:0.3"></div>'); | |
| o = $('#golo-overlay' + id); | |
| } | |
| o.addClass('golo-overlay-bg').css('zIndex', zIndex).fadeIn(100); | |
| return false; | |
| }, | |
| hide: function(id) { | |
| id = id !== undefined ? id : ''; | |
| var o = $('#golo-overlay' + id); | |
| o.fadeOut(100, function() { | |
| o.removeClass("golo-overlay-bg").remove() | |
| }); | |
| return false; | |
| } | |
| } | |
| golo.opener = { | |
| show: function(html, option) { | |
| var id = option.id !== undefined ? option.id : ''; | |
| var header = option.caption ? '<div class="header">' + option.caption + '</div><div class="clear"></div>' : ''; | |
| var opener = $('#opener_' + id); | |
| if (!opener.length) { | |
| var frame_html = '<div id="opener_' + id + '" class="golo-opener" style="display:none;"> \ | |
| <div class="popup">' + header + '\ | |
| <div class="content"></div> \ | |
| <a href="#" class="btn-remove" onclick="golo.opener.hide(\'' + id + '\');return false" title="关闭"></a> \ | |
| </div> \ | |
| </div>'; | |
| $('body').append(frame_html); | |
| if (header == '') { | |
| $('#opener_' + id + ' .content').addClass('content-noheader'); | |
| } | |
| var opener = $('#opener_' + id) | |
| if (option.zIndex) { | |
| opener.css('zIndex', option.zIndex); | |
| } | |
| $('#opener_' + id + ' .content').html(html); | |
| } | |
| else if (!option.cache) { | |
| $('#opener_' + id + ' .content').html(html); | |
| } | |
| //在未设置id的情况下,由于html被缓存了,可能会有标题错乱的情况,故需在这里才设置 | |
| if (option.caption) { | |
| opener.find('.header').html(option.caption); | |
| } | |
| //在未设置id的情况下,由于html被缓存了,可能会有宽度错乱的情况,故需在这里才设置 | |
| if (option.width) { | |
| $('.popup').width(option.width); | |
| } | |
| golo.overlay.show(id, option.zIndex ? option.zIndex - 1 : 0); | |
| var top_height = $(window).height() / 10; | |
| var box_width = $('#opener_' + id).width(); | |
| if (option.fixed) { | |
| opener.css({ | |
| position: 'fixed', | |
| top: (top_height > 50 ? top_height : 50), | |
| left: $(window).width() / 2 - box_width / 2 | |
| }); | |
| } | |
| else { | |
| opener.css({ | |
| top: (top_height > 50 ? top_height : 50) + $(document).scrollTop(), | |
| left: $(window).width() / 2 - box_width / 2 | |
| }); | |
| } | |
| //resize width | |
| var last_width = box_width; | |
| opener.show().resize(function() { | |
| var box_width = $('#opener_' + id).width(); | |
| //keep width max | |
| if (last_width > box_width) | |
| return; | |
| last_width = box_width; | |
| opener.css({ | |
| left: $(window).width() / 2 - box_width / 2 | |
| }); | |
| }); | |
| //on esc key down | |
| document.onkeydown = function(e) { | |
| if (e == null) { // ie | |
| keycode = event.keyCode; | |
| } else { // mozilla | |
| keycode = e.which; | |
| } | |
| //on esc keydown,close | |
| if (keycode == 27) { | |
| golo.opener.hide(id); | |
| } | |
| }; | |
| }, | |
| hide: function(id, remove) { | |
| document.onkeydown = ""; | |
| id = id ? id : ''; | |
| $('#opener_' + id).fadeOut(); | |
| golo.overlay.hide(id); | |
| if (remove) { | |
| $('#opener_' + id).remove(); | |
| } | |
| }, | |
| init: function(obj, p, type) {//type 1.pic 2.audio 3.video | |
| 'use strict'; | |
| obj.fileupload({ | |
| url: '?action=public_message.upload_files', | |
| dataType: 'json', | |
| done: function(e, data) { | |
| if (type == 1) { | |
| var html = '<li><div class="img"><img src="{image_url}" alt="{image_alt}"/></div><p class="pic_name" title="{title}">{image_name}</p><p><input class="radio f_r" type="radio" name="picture"/><span>{size}</span></p></li>'; | |
| } else if (type == 2) { | |
| var html = ''; | |
| } else if (type == 3) { | |
| var html = ''; | |
| } | |
| $.each(data.result.files, function(index, file) { | |
| if (type == 1) { | |
| var s = golo.opener.tmpl(html, {"image_alt": file.url, "image_url": file.thumbnailUrl, "image_name": file.name.substr(0, 14), "title": file.name, "size": golo.opener.trans(file.size)}); | |
| } else if (type == 2) { | |
| var s = ''; | |
| } else if (type == 3) { | |
| var s = ''; | |
| } | |
| $(s).appendTo(p.find("#files")); | |
| }); | |
| }, | |
| progressall: function(e, data) { | |
| var progress = parseInt(data.loaded / data.total * 100, 10); | |
| $('#progress .progress-bar').css( | |
| 'width', | |
| progress + '%' | |
| ); | |
| } | |
| }).prop('disabled', !$.support.fileInput) | |
| .parent().addClass($.support.fileInput ? undefined : 'disabled'); | |
| }, | |
| tmpl: function(temp, data) { | |
| return temp.replace(/\{([\w\.]*)\}/g, function(str, key) { | |
| var keys = key.split("."), v = data[keys.shift()]; | |
| for (var i = 0, l = keys.length; i < l; i++) | |
| v = v[keys[i]]; | |
| return (typeof v !== "undefined" && v !== null) ? v : ""; | |
| }); | |
| }, | |
| trans: function(byte) { | |
| var val = Math.ceil(byte / 1024); | |
| return (val < 1024) ? val + 'KB' : Math.ceil(val / 1024) + 'MB'; | |
| }, | |
| submit: function(obj, id, type) {//type 1.pic 2.audio 3.video | |
| document.onkeydown = ""; | |
| id = (typeof id !== "undefined" && id !== null) ? id : ''; | |
| $('#opener_' + id).fadeOut(); | |
| golo.overlay.hide(id); | |
| var radio_obj = $("input[type=radio]:checked"); | |
| var li_obj = radio_obj.parent().parent(); | |
| var image_url = li_obj.find("img").attr("src") | |
| if (type == 1) { | |
| var html = '<br/><img src="{image_url}" />'; | |
| } else if (type == 2) { | |
| var html = ''; | |
| } else if (type == 3) { | |
| var html = ''; | |
| } | |
| var s = golo.opener.tmpl(html, {"image_url": image_url}); | |
| parent.document.getElementById("edit_area_id").innerHTML += s; | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment