Error while paginating html in UIWebView using css Multicolumns - iphone

Here is my Problem:
I'm currently writing an ebook reader in objective-c and want to use multicolumns to paginate my xhtml file in my webview.
Unfortunately when I add Multicolumns to my css, my html seems to be only 2 "pages" long, which is exactly the first two tags.
Does anyone know what I'm doing wrong?.
here is the code with which i inject the new settings into my css:
NSString *varMySheet = #"var mySheet = document.styleSheets[0];";
NSString *addCSSRule = #""
"function addCSSRule(selector, newRule) {"
"if (mySheet.addRule) {"
"mySheet.addRule(selector, newRule);" // For Internet Explorer
"} else {"
"ruleIndex = mySheet.cssRules.length;"
"mySheet.insertRule(selector + '{' + newRule + ';}', ruleIndex);" // For Firefox, Chrome, etc.
"}" // endif mySheet.addRule
"}"; // end addCSSRule()
NSString *insertColumns = [NSString stringWithFormat:#"addCSSRule('div', 'height: 370px; -webkit-column-width: 320px');"];
[wv_reader stringByEvaluatingJavaScriptFromString:varMySheet];
[wv_reader stringByEvaluatingJavaScriptFromString:addCSSRule];
[wv_reader stringByEvaluatingJavaScriptFromString:insertColumns];
For scrolling i use the following code:
int i_scrollTo = ([AppState sharedInstance].i_myselectedPage -1) * wv_reader.frame.size.height;
[wv_reader stringByEvaluatingJavaScriptFromString:[NSString stringWithFormat:#"window.scrollTo(0,%d);", i_scrollTo]];
which works perfect if i don't set Multicolumns in my css.
I also tested, if my html is somehow cut off after adding multicolumns, but a NSLog of the content of the webview showed, that the whole ebook is loaded.
When getting the maximum scrollheight though i found out, that without columns it is 79061, and after inserting columns into my css it is reduced to 424 for some reason i don't know.
Can somebody please help me to fix this? I'm working on this problem for about a week now and couldn't find a solution.
Thx in advance.
Maverick
*UPDATE**
Scrolling horizontally doesn't work either, because my document.scrollWidth is stuck to the width of my Columns, which is pretty odd I think.

https://github.com/fedefrappi/AePubReader
Maybe this sample can help you ?

Related

Why is IOS 7.0.3 picker goofing up my LiveCode webform?

I don't know where the best place to ask about this is. My problem seems to be with IOS 7.0.3 and how Safari is handling the picker in a web form. I've created a web form with LiveCode that works just fine in every browser I've tried. But on the iPhone, the picker malfunctions. If you choose one item and press Done, it reverts to 0 items chosen. If you choose two items and press done, it shows one item chosen. The same goes for three, four, and so on. Has anyone else had this experience? Here is a snippet of one of the multiple choice buttons.
<label for="authors[]">
Select Author(s)
<select name="authors[]" id="authors" multiple="yes" size="7" >
<?lc
put the number of lines in tAuthorList into tTotalAuthors
repeat with x = 1 to tTotalAuthors
put "<option value=" & q(line x of tAuthorList)
put lineOffset(line x of tAuthorList,tPrevAuthors) into tLineHit
if bDataSubmitted and line x of tAuthorList is line tLineHit of tPrevAuthors then
put " selected"
end if
put ">" & line x of tAuthorList & "</option>" & return
end repeat
?>
</select>
</label>
This is the URL:
http://lc.scs.earlham.edu/soul_therapy3.lc
Incidentally, I use it with an iframe in my Drupal 7 site:
http://soulshare.org/soul_therapy/tool
There is an issue (design choice?) in iOS7 where you need to not only scroll to the correct value but also tap your selected value. I don't know if this is your problem though...
In some forms you only needs to scroll to the correct value but in many, you need to scroll and THEN select. As you probably have guessed this has nothing to do with LiveCode...
This is a bug in IOS and has been reported to apple. Currently the best solution I've found uses jQuery to fix the selected items upon closing the picker. Simply paste this into your JS file and away you go.
// hack for iPhone 7.0.3 multiselects bug
if(navigator.userAgent.match(/iPhone/i)) {
$('select[multiple]').each(function(){
var select = $(this).on({
"focusout": function(){
var values = select.val() || [];
setTimeout(function(){
select.val(values.length ? values : ['']).change();
}, 1000);
}
});
var firstOption = '<option value="" disabled="disabled"';
firstOption += (select.val() || []).length > 0 ? '' : ' selected="selected"';
firstOption += '>« Select ' + (select.attr('title') || 'Options') + ' »';
firstOption += '</option>';
select.prepend(firstOption);
});
}
Multiple select in Safari iOS 7

Evo Pdf - Page numbering from within HTML

I know it is possible to render "Page X of Y" in a header/footer using the C# API like this:
//write the page number
TextElement footerText = new TextElement(0, pdfConverter.PdfFooterOptions.FooterHeight - 15, "This is page &p; of &P; ",
new System.Drawing.Font(new System.Drawing.FontFamily("Times New Roman"), 10, System.Drawing.GraphicsUnit.Point));
footerText.EmbedSysFont = true;
footerText.TextAlign = HorizontalTextAlign.Right;
pdfConverter.PdfFooterOptions.AddElement(footerText);
..but i'd rather position and style it directly in html using:
HtmlToPdfElement footerHtml = new HtmlToPdfElement(pdfOptions.DocumentFooterHtmlString, pdfOptions.BaseUrl);
footerHtml.FitHeight = true;
pdfConverter.PdfFooterOptions.AddElement(footerHtml);
where pdfOptions.DocumentFooterHtmlString looks something like this:
<div class="clearfix">
<span class="pull-right">This is page &p; of &P;</span>
</div>
Is this something that is possible? If I try this I just get the: This is page &p; of &P; rendered in the footer.
I struggled with this briefly. For the sake of others who find this through search, the trick is that when you add the HTML element, it has to be a HtmlToPdfVariableElement instead of a HtmlToPdfElement.
HtmlToPdfVariableElement footerHtml = new HtmlToPdfVariableElement(pdfOptions.DocumentFooterHtmlString, pdfOptions.BaseUrl);
footerHtml.FitHeight = true;
pdfConverter.PdfFooterOptions.AddElement(footerHtml);
It looks like you can do this. See http://www.evopdf.com/demo/PDF_Creator/Headers_and_Footers/Page_Numbers_in_HTML.aspx
In the sample code Evo Provides they use HtmlToPdfVariableElement.

Pagebreak in UIWebview in iphone sdk

I am creating Rich Text editor using UIWebView in iOs sdk.I am using java script & HTML code to implement all functionality & using webview as editable content. Now my problem is that I want to insert page break in UIWebView using java-script/Html but page break option is not working in UIWebView.How I can insert page break option in UIWebview?
I have done this after too much search with JS
function makePageBreak(){
insertHtmlAtCursor('<div id="MyInsertPageBreak" class="pagebreak" ></div>');
}
function insertHtmlAtCursor(html) {
var range, node;
if (window.getSelection && window.getSelection().getRangeAt) {
range = window.getSelection().getRangeAt(0);
node = range.createContextualFragment(html);
range.insertNode(node);
} else if (document.selection && document.selection.createRange) {
document.selection.createRange().pasteHTML(html);
}
}
This worked for me. Hope will help you.

Can we load basic javascript function in a webview?

I have implemented a function in webview. I put the javascript function in the html head then load it through web.loadUrl but the webview does not take the function into consideration. Is it possible to load it this way ? or am I on the wrong track ?
"<td><a href='' onclick=\"displaying('image url')\" id=/image"+my_image[i] +"/"+"
class='popup-open'><img
src='"+my_image[i]+"'"+
"width='80' height='65'></a></td></tr><tr>";
the hmtl content
String webData = "<!DOCTYPE html>" +
"<head> "+
"<script>"+"function displaying(url)
{document.getElementById('image').innerHTML =\"<img src=\"url\" width=\"100\" height=\"105\">\";}"+"</script>"
+
" </head><body>"+ html_content +"</tr></table></body></html>";
Maybe is your JavaScript or some syntax shit. First of all, try to figure out what's the error message from WebKit engine.
To display webview's javascript messages, put onConsoleMessage in implementation.
myWebView.setWebChromeClient(new WebChromeClient() {
public boolean onConsoleMessage(ConsoleMessage cm) {
Log.d(cm.message() + " -- From line "
+ cm.lineNumber() + " of "
+ cm.sourceId());
return true;
}
});
Make sure you have following enabled
WebSettings webSettings = webView.getSettings();
webSettings.setJavaScriptEnabled(true);

non-english chars in google charts label?

Does non-english characters work in google charts labels/legends ?
This works, the legends shows up fine:
var chart_url = 'http://chart.apis.google.com/chart?' + 'cht=bvs' + ...some other stuff... + '&chdl=Lowest price|Average price';
This doesn't work, the legends don't show at all:
var chart_url = 'http://chart.apis.google.com/chart?' + 'cht=bvs' + ...some other stuff... + '&chdl=L' + unescape("%E4") + 'gsta pris|Genomsnittligt pris';
Any ideas? Thanks in advance!
/toby
-----------edit-----------
Neither of these works:
'&chdl=Lägsta pris|Genomsnittligt pris'
'&chdl=L& auml;gsta pris|Genomsnittligt pris' (without the space after &)
'&chdl=L%E4gsta pris|Genomsnittligt pris'
%E4 == ä urlencoded.
My guess is that most letters will work, but you have to do the equivalent of urlencoding them (see urlencode()).
Struggled with the same problem and it turned out that google charts want the texts urlencoded in UTF-8 (of course...)
So "Lägsta pris" should be == L%C3%A4gsta+pris