这是我的 fiddle Check
任何帮助将不胜感激
实际上我正在做的是我创建了一个文本编辑器,我在其中添加了页眉页脚和内容编辑器,但现在我想添加一个具有相同页眉和页脚的新页面,但想附加我当前的页面内容 -编辑器
var margin;
var pageSize;
var headerHeight;
var footerHeight;
var marginTopBottom;
var marginLeftRight;
var marginArray;
var reportHeight;
var reportWidth;
$(function () {
GetPage();
jQuery("#btnGetSize").on('click', function () {
var h = $('#Template').height();
var w = $('#Template').width();
var h1 = $('#ReportPage').height();
var w1 = $('#ReportPage').width();
alert("Template : h=" + (parseFloat(h) / 3.76) + " w=" + (parseFloat(w) / 3.76) + " ReportPage : h1=" + (parseFloat(h1) / 3.76) + " w1=" + (parseFloat(w1) / 3.76) + "");
});
jQuery("#ddlSize").change(function () {
GetPage();
});
jQuery("#ddlMargin").change(function () {
GetPage();
});
$("#btnPrint1").on('click', function () {
var divContents = $("#ReportPage").html();
var printWindow = window.open('', '', 'height=1000px,width=1000px');
printWindow.document.write('<html><head>');
printWindow.document.write('</head><body >');
printWindow.document.write(divContents);
printWindow.document.write('</body></html>');
printWindow.document.close();
printWindow.print();
});
// -------------------------
$("#btnPrint").on('click', function () {
$('#main').addClass("page").css("display", "none");
$('#main').addClass("print page ")
var content_height = $('#TemplateSubPage').height();
var page = 1;
function buildReport() {
if ($('#TemplateSubPage').contents().length > 0) {
$page = $("#TemplatePage").clone();
$page.find(".subpage").empty();
$page.find(".footer span").append(page);
$("#ReportPage").append($page);
$('.subpage').attr('disabled', 'disabled');
$("#TemplateSubPage").prop('disabled', true);
page++;
$('#TemplateSubPage').columnize({
columns: 1,
target: ".page:last .subpage",
overflow: {
height: content_height,
id: "#TemplateSubPage",
doneFunc: function () {
console.log("done with page");
buildReport();
}
}
});
}
}
setTimeout(buildReport, 1000);
});
});
//=------------------------
function GetPage() {
pageSize = $('#ddlSize option:selected').text();
margin = $('#ddlMargin option:selected').text();
headerHeight = $('.header').height();
footerHeight = $('.footer').height();
marginArray = new Array();
marginArray = GetMargins();
marginTopBottom = parseFloat(marginArray[0]) + parseFloat(marginArray[2]) + (parseFloat(headerHeight) / 3.7) + (parseFloat(footerHeight) / 3.7);
marginLeftRight = parseFloat(marginArray[1]) + parseFloat(marginArray[3]);
if (pageSize == "--Select--") {
//$("#TemplatePage .divOuter").css("width", "210mm").css("height", "290mm");
$(".page").css("width", "210mm").css("min-height", "290mm");
$(".subpage").css("height", 277 + "mm").css("max-height", 290 + "mm").css("width", 187 + "mm");
// $("div .subpage").css("height", (290) + "mm").css("max-height", (290) + "mm").css("width", (210) + "mm");
}
else if (pageSize == "A0") {
$(" .page").css("width", "841mm").css("min-height", "1175mm"); /*page margins top right bottom left */
$(".subpage").css("height", 1155 + "mm").css("max-height", 1175 + "mm").css("width", 820 + "mm");
// $("div .subpage").css("height", (1175) + "mm").css("max-height", (1175) + "mm").css("width", (841) + "mm");
}
else if (pageSize == "A1") {
$(".page").css("width", "594mm").css("min-height", "830mm");
$(".subpage").css("height", 810 + "mm").css("max-height", 830 + "mm").css("width", 574 + "mm");
//$("div .subpage").css("height", (830) + "mm").css("max-height", (830) + "mm").css("width", (594) + "mm");
}
else if (pageSize == "A2") {
$(".page").css("width", "420mm").css("min-height", "585mm");
$(".subpage").css("height", 565 + "mm").css("max-height", 585 + "mm").css("width", 400 + "mm");
// $("div .subpage").css("height", (585) + "mm").css("max-height", (585 ) + "mm").css("width", (420 - marginLeftRight) + "mm");
}
else if (pageSize == "A3") {
$("div .page").css("width", "297mm").css("min-height", "413mm");
// $("div .subpage").css("height", (413 - marginTopBottom) + "mm").css("max-height", (413 - marginTopBottom) + "mm").css("width", (297 - marginLeftRight) + "mm");
}
else if (pageSize == "A4") {
// $("#TemplatePage .divOuter").css("width", "210mm").css("height", "290mm");
$(".page").css("width", "210mm").css("min-height", "297mm");
$(".subpage").css("height", 277 + "mm").css("max-height", 297 + "mm").css("width", 187 + "mm");
// $("div .subpage").css("height", (290 - marginTopBottom) + "mm").css("max-height", (290 - marginTopBottom) + "mm").css("width", (210 - marginLeftRight) + "mm");
}
else if (pageSize == "A4 LandScape") {
// $("#TemplatePage .divOuter").css("width", "297mm").css("height", "200mm");
$(".page").css("width", "297mm").css("min-height", "200mm");
$(".subpage").css("height", 180 + "mm").css("max-height", 200 + "mm").css("width", 277 + "mm");
// $("div .subpage").css("height", (200 - marginTopBottom) + "mm").css("max-height", (200 - marginTopBottom) + "mm").css("width", (299 - marginLeftRight) + "mm");
}
else if (pageSize == "A5") {
$(".page").css("width", "148mm").css("min-height", "200mm");
$(".subpage").css("height", 180 + "mm").css("max-height", 200 + "mm").css("width", 126 + "mm");
}
else if (pageSize == "A6") {
$(".page").css("width", "105mm").css("min-height", "142mm");
$(".subpage").css("height", 122 + "mm").css("max-height", 142 + "mm").css("width", 83 + "mm");
//$("div .subpage").css("height", (142 - marginTopBottom) + "mm").css("max-height", (142 - marginTopBottom) + "mm").css("width", (105 - marginLeftRight) + "mm");
}
else if (pageSize == "A7") {
$(".page").css("width", "74mm").css("min-height", "101mm");
$(".subpage").css("height", 81 + "mm").css("max-height", 101 + "mm").css("width", 51.30 + "mm");
// $("div .subpage").css("height", (101 - marginTopBottom) + "mm").css("max-height", (101 - marginTopBottom) + "mm").css("width", (74 - marginLeftRight) + "mm");
}
else if (pageSize == "A8") {
$(".page").css("width", "52mm").css("min-height", "71mm");
$(".subpage").css("height", 51 + "mm").css("max-height", 71 + "mm").css("width", 29.60 + "mm");
// $("div .subpage").css("height", (71 - marginTopBottom) + "mm").css("max-height", (71 - marginTopBottom) + "mm").css("width", (52 - marginLeftRight) + "mm");
}
}
function GetMargins() {
var marginArray = new Array();
margin = $('#ddlMargin').val();
if (margin == 0) {
$(".page").css("padding", "25.4mm 25.4mm 25.4mm 25.4mm");
marginArray = ["25.4", "25.4", "25.4", "25.4"];
return marginArray;
}
else if (margin == 1) {
$(".page").css("padding", "12.7mm 12.7mm 12.7mm 12.7mm"); /*page margins top right bottom left */
marginArray = ["12.7", "12.7", "12.7", "12.7"];
return marginArray;
}
else if (margin == 2) {
$(".page").css("padding", "25.4mm 25.4mm 25.4mm 25.4mm");
marginArray = ["25.4", "25.4", "25.4", "25.4"];
return marginArray;
}
else if (margin == 3) {
$(".page").css("padding", "25.4mm 19.05mm 25.4mm 19.05mm");
marginArray = ["25.4", "19.05", "25.4", "19.05"];
return marginArray;
}
else if (margin == 4) {
$(".page").css("padding", "25.4mm 12.7mm 25.4mm 12.7mm");
marginArray = ["25.4", "12.7", "25.4", "12.7"];
return marginArray;
}
else if (margin == 5) {
$(".page").css("padding", "0mm 0mm 0mm 0mm");
marginArray = ["0", "0", "0", "0"];
return marginArray;
}
} body
{
margin: 0;
padding: 0;
font: 12pt "Tahoma";
}
.page
{
padding: 20mm;
border: 1px solid black;
border-radius: 5px;
background: white;
margin-top: 0px;
margin-bottom: 0px;
}
.subpage
{
min-width: 10mm;
word-break: break-all;
cursor: text;
overflow: hidden;
top: 0px;
padding: 1cm;
border: 1px solid red;
}
@page
{
margin: 0;
}
@media print
{
/* html, body
{
width: 210mm;
height: 297mm;
}
.page
{
margin: 0;
border: initial;
border-radius: initial;
width: initial;
min-height: initial;
box-shadow: initial;
background: initial;
page-break-after: always;
}
*/
}<script src="https://dl.dropboxusercontent.com/u/285608/Miscellaneous/JS%20Libraries/columnizer/jquery.columnizer.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
<div id="controls">
<div style="text-align: center; float: left; font-size: medium">
<select id="ddlSize">
<option id="A" value="0">--Select--</option>
<option id="A0" value="841mm X 1189mm">A0</option>
<option id="A1" value="594mm X 841mm">A1</option>
<option id="A2" value="420mm X 594mm">A2</option>
<option id="A3" value="297mm X 420mm">A3</option>
<option id="A4" value="210mm X 297mm">A4</option>
<option id="A4Landscape" value="297mm X 210mm">A4 LandScape</option>
<option id="A5" value="148mm X 210mm">A5</option>
<option id="A6" value="105mm X 148mm">A6</option>
<option id="A7" value="74mm X 105mm">A7</option>
<option id="A8" value="52mm X 74mm">A8</option>
</select>
</div>
<button id="btnPrint">
Print preview</button>
<button id="btnPrint1">
Print</button>
<button id="btnGetSize">
Get divSize</button>
<div style="text-align: center; float: left; padding-bottom: 50px; font-size: medium;
width: 300px">
<select id="ddlMargin">
<option id="No" value="0">--Select--</option>
<option id="Narrow" value="1">0.5" 0.5" 0.5" 0.5" </option>
<option id="Normal" value="2">1" 1" 1" 1"</option>
<option id="Moderate" value="3">1" 0.75" 1" 0.75" </option>
<option id="Other" value="4">1" 0.5" 1" 0.5" </option>
<option id="NoMargin" value="5">0" 0" 0" 0"</option>
</select>
</div>
</div>
<!--tyle="border: 1px solid black;"-->
<div id="main">
<div class="page" id="TemplatePage" style="page-break-after: always;">
<div id="header">
<center>
This is header</center>
<br />
</div>
<div class="subpage" contenteditable="true" id="TemplateSubPage">
<br />
</div>
<div id="footer">
<br />
<center>
This is Footer</center>
</div>
</div>
</div>
<div id="ReportPage" class="divOuter">
</div>
最佳答案
一个可能的解决方案是计算换行符的数量(\r\n 和 \n 在 textArea 输入元素的情况下),然后创建一个新的“页面”元素,编辑旧文本区域和新文本区域的值并将焦点更改到新文本区域。这是一个伪 JS 事件处理程序:
function onPageInput(event){
//count lines in original page
var lines = page.value.split(/\r*\n/);
if (lines.length > linesPerPage){
var newPage = addPage(); //returns the new page
page.insertAfter(newPage);
//reset original textArea value
page.value = "";
//populate old textarea and new textarea
page.value = lines.slice(0, linesPerPage).join("\n");
newPage.value = lines.slice(linesPerPage, lines.length).join("\n");
newPage.focus();
}
}
这是一个有效的 example implementation
请注意,我使用 textAreas 进行简化。如果您想使用 ContentEditable div,您将需要一种方法来计算内容行数,并根据您想要的换行符将内容分成两个单独的 block 。一些现有的 WYSIWYG 库可能已经提供了用于行计数/拆分内容的 API,您无需解决 pitfalls of ContentEditable 问题。 .
当然 - 您仍然需要处理特殊情况,例如当用户在空白页面上按退格键时删除页面,或者您想要的任何其他行为。
关于javascript - 如何打破内容编辑器并将其附加到下一页,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38761649/
我正在学习如何使用Nokogiri,根据这段代码我遇到了一些问题:require'rubygems'require'mechanize'post_agent=WWW::Mechanize.newpost_page=post_agent.get('http://www.vbulletin.org/forum/showthread.php?t=230708')puts"\nabsolutepathwithtbodygivesnil"putspost_page.parser.xpath('/html/body/div/div/div/div/div/table/tbody/tr/td/div
总的来说,我对ruby还比较陌生,我正在为我正在创建的对象编写一些rspec测试用例。许多测试用例都非常基础,我只是想确保正确填充和返回值。我想知道是否有办法使用循环结构来执行此操作。不必为我要测试的每个方法都设置一个assertEquals。例如:describeitem,"TestingtheItem"doit"willhaveanullvaluetostart"doitem=Item.new#HereIcoulddotheitem.name.shouldbe_nil#thenIcoulddoitem.category.shouldbe_nilendend但我想要一些方法来使用
关闭。这个问题是opinion-based.它目前不接受答案。想要改进这个问题?更新问题,以便editingthispost可以用事实和引用来回答它.关闭4年前。Improvethisquestion我想在固定时间创建一系列低音和高音调的哔哔声。例如:在150毫秒时发出高音调的蜂鸣声在151毫秒时发出低音调的蜂鸣声200毫秒时发出低音调的蜂鸣声250毫秒的高音调蜂鸣声有没有办法在Ruby或Python中做到这一点?我真的不在乎输出编码是什么(.wav、.mp3、.ogg等等),但我确实想创建一个输出文件。
给定这段代码defcreate@upgrades=User.update_all(["role=?","upgraded"],:id=>params[:upgrade])redirect_toadmin_upgrades_path,:notice=>"Successfullyupgradeduser."end我如何在该操作中实际验证它们是否已保存或未重定向到适当的页面和消息? 最佳答案 在Rails3中,update_all不返回任何有意义的信息,除了已更新的记录数(这可能取决于您的DBMS是否返回该信息)。http://ar.ru
我在我的项目目录中完成了compasscreate.和compassinitrails。几个问题:我已将我的.sass文件放在public/stylesheets中。这是放置它们的正确位置吗?当我运行compasswatch时,它不会自动编译这些.sass文件。我必须手动指定文件:compasswatchpublic/stylesheets/myfile.sass等。如何让它自动运行?文件ie.css、print.css和screen.css已放在stylesheets/compiled。如何在编译后不让它们重新出现的情况下删除它们?我自己编译的.sass文件编译成compiled/t
我正在寻找执行以下操作的正确语法(在Perl、Shell或Ruby中):#variabletoaccessthedatalinesappendedasafileEND_OF_SCRIPT_MARKERrawdatastartshereanditcontinues. 最佳答案 Perl用__DATA__做这个:#!/usr/bin/perlusestrict;usewarnings;while(){print;}__DATA__Texttoprintgoeshere 关于ruby-如何将脚
Rackup通过Rack的默认处理程序成功运行任何Rack应用程序。例如:classRackAppdefcall(environment)['200',{'Content-Type'=>'text/html'},["Helloworld"]]endendrunRackApp.new但是当最后一行更改为使用Rack的内置CGI处理程序时,rackup给出“NoMethodErrorat/undefinedmethod`call'fornil:NilClass”:Rack::Handler::CGI.runRackApp.newRack的其他内置处理程序也提出了同样的反对意见。例如Rack
我需要读入一个包含数字列表的文件。此代码读取文件并将其放入二维数组中。现在我需要获取数组中所有数字的平均值,但我需要将数组的内容更改为int。有什么想法可以将to_i方法放在哪里吗?ClassTerraindefinitializefile_name@input=IO.readlines(file_name)#readinfile@size=@input[0].to_i@land=[@size]x=1whilex 最佳答案 只需将数组映射为整数:@land边注如果你想得到一条线的平均值,你可以这样做:values=@input[x]
在选择我想要运行操作的频率时,唯一的选项是“每天”、“每小时”和“每10分钟”。谢谢!我想为我的Rails3.1应用程序运行调度程序。 最佳答案 这不是一个优雅的解决方案,但您可以安排它每天运行,并在实际开始工作之前检查日期是否为当月的第一天。 关于ruby-如何每月在Heroku运行一次Scheduler插件?,我们在StackOverflow上找到一个类似的问题: https://stackoverflow.com/questions/8692687/
我有一个对象has_many应呈现为xml的子对象。这不是问题。我的问题是我创建了一个Hash包含此数据,就像解析器需要它一样。但是rails自动将整个文件包含在.........我需要摆脱type="array"和我该如何处理?我没有在文档中找到任何内容。 最佳答案 我遇到了同样的问题;这是我的XML:我在用这个:entries.to_xml将散列数据转换为XML,但这会将条目的数据包装到中所以我修改了:entries.to_xml(root:"Contacts")但这仍然将转换后的XML包装在“联系人”中,将我的XML代码修改为