Fix annoucement preview image bug

This commit is contained in:
Manson Wang 2013-11-06 16:31:27 +08:00
parent 2d0fd1d2e4
commit ff6eb5d674
2 changed files with 73 additions and 84 deletions

View File

@ -1,93 +1,66 @@
//Preview need a link in form as Ex and a corresponding PUT action in controller
//Ex preview trigger:
// <%= link_to "NewPreview", realtime_preview_admin_ad_banner_path(ad_banner_tab) , :class=>'preview_trigger'%>
$(function() {
// $(".post_preview").click(function(e){
// $("#main-wrap").after("<span id='show_preview'></span>");
// e.preventDefault();
// var form = $(this).parents("form").first()
// //var cont = form["content"].value;
// // $.ajax({
// // type: 'POST',
// // url: $(this).attr("href")+'?preview=true',
// // data: form.serialize(),
// // dataType: "script",
// // success: function (msg) {
// // $("#"+start_modal_with_id).modal('show'); },
// // error: function(){
// // alert("ERROR");
// // }
// // });
// url = "/panel/news/back_end/news_bulletins/preview?preview=true"
// // alert(url)
// form.attr("action",url);
// form.submit();
// //return false;
// });
// /panel/announcement/back_end/bulletins/preview
$('#main-wrap').on(clickEvent, '.post_preview, .preview_trigger', function(e) {
$(".post_preview").click(function(){
$("#main-wrap").after("<span id='show_preview'></span>");
if($(this).hasClass('post_preview')) {
var attrs = e.target.attributes;
var url = attrs['url'];
$("form.previewable").ajaxSubmit({
beforeSubmit: function(a,f,o){
o.dataType = 'script';
o.url = url.nodeValue;
o.type = 'post';
},success: function(msg) {
$('#show_preview .modal').modal()
$('#show_preview .modal').height(function() {
return $(window).height() * 0.7;
});
}
$.post($(this).attr('url'), $(".previewable").serialize() ,function(data){
$('#show_preview .modal').modal();
$('#show_preview .modal').height(function() {
return $(window).height() * 0.7;
});
} else if($(this).hasClass('preview_trigger')) {
$.ajax({
type: 'PUT',
url: $(this).attr("href"),
data: $(this).parents("form").serialize(),
success: function (msg) {
$('#show_preview .modal').modal();
$('#show_preview .modal').height(function() {
return $(window).height() * 0.7;
});
},
error: function(){
alert("ERROR");
}
});
return false;
}
},'script');
});
// $("a.preview_trigger").on('click',function(){
$(".preview_trigger").click(function(){
$("#main-wrap").after("<span id='show_preview'></span>");
$.ajax({
type: 'PUT',
url: $(this).attr("href"),
data: $(this).parents("form").serialize(),
success: function (msg) {
$('#show_preview .modal').modal();
$('#show_preview .modal').height(function() {
return $(window).height() * 0.7;
});
},
error: function(){
alert("ERROR");
}
});
return false;
});
// $('#main-wrap').on(clickEvent, '.post_preview, .preview_trigger', function(e) {
// $("#main-wrap").after("<span id='show_preview'></span>");
// $.ajax({
// type: 'PUT',
// url:$(this).attr("href"),
// data:$(this).parents("form").serialize(),
// success: function (msg) {
// $("#"+start_modal_with_id).modal('show'); },
// error: function(){
// alert("ERROR");
// if($(this).hasClass('post_preview')) {
// var attrs = e.target.attributes;
// var url = attrs['url'];
// $("form.previewable").ajaxSubmit({
// beforeSubmit: function(a,f,o){
// o.dataType = 'script';
// o.url = url.nodeValue;
// o.type = 'post';
// },success: function(msg) {
// $('#show_preview .modal').modal()
// $('#show_preview .modal').height(function() {
// return $(window).height() * 0.7;
// });
// }
// });
// } else if($(this).hasClass('preview_trigger')) {
// $.ajax({
// type: 'PUT',
// url: $(this).attr("href"),
// data: $(this).parents("form").serialize(),
// success: function (msg) {
// $('#show_preview .modal').modal();
// $('#show_preview .modal').height(function() {
// return $(window).height() * 0.7;
// });
// },
// error: function(){
// alert("ERROR");
// }
// });
// return false;
// });
// return false;
// }
// });
// $("form.nccu_ajax_form").ajaxForm({
// beforeSubmit: function(a,f,o) {
// // if(clicked_what.hasClass("post_preview")){
// // $("#main-wrap").after("<span id='show_preview'></span>");
// // o.dataType = 'script';
// // o.url = clicked_what.attr("url");
// // }
// },
// success: function(data) {
// // if(!clicked_what.hasClass("post_preview")){
// // window.location = data.redirect_url;
// // }
// }
// })
});

View File

@ -13,13 +13,21 @@
<div>
<script type="text/javascript" src="/assets/kernel.js"></script>
<script type="text/javascript">
var preview_img;
$(function() {
$("iframe").load(function() {
// Get the body element
var frameBody = $("iframe").contents().find('body');
// Get all links inside the BODY tag
$("iframe").contents().find('#orbit-bar').hide();
$('.thumbnail').each(function(){
if($(this).children('img').length) preview_img = $(this).children('img').attr('src');
});
InsertPreviewImage();
frameBody.find('a').click(function(e){
//Disable all default actions
e.preventDefault();
@ -30,6 +38,14 @@
$("#show_preview").remove();
});
});
function InsertPreviewImage(){
if($("iframe").contents().find('.news_image').length){
$("iframe").contents().find('.news_image').append("<a href='' target='_blank'><img src='"+preview_img+"' width='320' height='240' /></a>");
}else{
setTimeout(InsertPreviewImage,1000);
}
}
</script>
</div>
</div>