public void AppendPageContent(UIWebView webView, string content, string direction) { if (content != null) { content = ContentFormatUtil.Format(content); content = content.Replace("\"", "##"); content = Regex.Replace(content, @"[\r|\n]", ""); webView.EvaluateJavascript("appendPageContent(\"" + content + "\", \"" + direction + "\");"); } }
/// <summary> /// Update when content which are going to to be displayed changed /// </summary> /// <param name="s">S.</param> public async void Update(Subject s) { var hud = new MTMBProgressHUD(View) { LabelText = "Loading", RemoveFromSuperViewOnHide = true }; View.AddSubview(hud); hud.Show(animated: true); OpenedPublication pcs = (OpenedPublication)s; ContentNavigationBar.PopNavigationItem(false); string content = ""; string htmlFilePath = NSBundle.MainBundle.PathForResource("Html/htmlDoc", "html"); string htmlStr = File.ReadAllText(htmlFilePath); NSUrl url = new NSUrl(htmlFilePath); if (pcs.OpendContentType == PublicationContentTypeEnum.TOC) { if (await PageSearchUtil.Instance.IsPBO(AppDataUtil.Instance.GetCurrentPublication().BookId)) { GotoBarButton.Hidden = false; PageNumLabel.Hidden = false; } ContentNavigationBar.PushNavigationItem(ContentNavigationItem, false); content = await PublicationContentUtil.Instance.GetContentFromTOC(pcs.P.BookId, pcs.OpendTOCNode); content = string.Format("<div data-tocid='{0}' data-toctitle='{1}' class='page_container'>{2}</div>", pcs.OpendTOCNode.ID, pcs.OpendTOCNode.Title, content); ContentNavigationItem.LeftBarButtonItems [1].Enabled = AppDataUtil.Instance.CanBack() == true; ContentNavigationItem.LeftBarButtonItems [2].Enabled = AppDataUtil.Instance.CanForward() == true; TOCNode nextPageNode = AppDataUtil.Instance.GetNextOfTOCNodeWithId(pcs.OpendTOCNode.ID, "next"); if (nextPageNode != null) { htmlStr = htmlStr.Replace("#NEXT_PAGE_TITLE#", nextPageNode.Title).Replace("#NEXT_PAGE_TOCID#", nextPageNode.ID.ToString()); } else { htmlStr = htmlStr.Replace("#NEXT_PAGE_TITLE#", "You are on the end.").Replace("#NEXT_PAGE_TOCID#", "-1"); //"-1" here means no next page any more } TOCNode previousPageNode = AppDataUtil.Instance.GetNextOfTOCNodeWithId(pcs.OpendTOCNode.ID, "previous"); if (previousPageNode != null) { htmlStr = htmlStr.Replace("#PREVIOUS_PAGE_TITLE#", previousPageNode.Title).Replace("#PREVIOUS_PAGE_TOCID#", previousPageNode.ID.ToString()); } else { htmlStr = htmlStr.Replace("#PREVIOUS_PAGE_TITLE#", "You are on the begining.").Replace("#PREVIOUS_PAGE_TOCID#", "-1"); //"-1" here means no next page any more } htmlStr = htmlStr.Replace("#PLACE_HOLDER_HIGHLIGHTED_TOCID#", pcs.OpendTOCNode.ID.ToString()); htmlStr = htmlStr.Replace("#PLACE_HOLDER_HIGHLIGHTED_KEYWORD#", AppDataUtil.Instance.HighlightSearchKeyword); AppDataUtil.Instance.HighlightSearchKeyword = ""; // htmlStr = htmlStr.Replace("#PLACE_HOLDER_SCROLL_SCRIPT#", "<script type='text/javascript' src='./JS/infinitescroll.js'></script>"); //When jump to content from index by click content link, selected index of tab bar supposed to be changed to "Contents" NSNotificationCenter.DefaultCenter.PostNotificationName("ChangeContentTabBarSelectedIndex", this, new NSDictionary()); //Suppose to be handled by ContentLeftTabBarController } else if (pcs.OpendContentType == PublicationContentTypeEnum.Index) { //TODO, GotoBarButton.Hidden = true; PageNumLabel.Hidden = true; ContentNavigationBar.PushNavigationItem(IndexNavigationItem, false); if (pcs.OpendIndex == null) { IndexNavigationItem.LeftBarButtonItem.Title = ""; content = "<div class='nocontent'><span>No Index Files Available</span><div>"; } else { IndexNavigationItem.LeftBarButtonItem.Title = pcs.OpendIndex.Title [0].ToString(); content = await PublicationContentUtil.Instance.GetContentFromIndex(pcs.P.BookId, pcs.OpendIndex); content = string.Format("<div class='page_container'>{0}</div>", content); //Scroll to selected index var scrollToSelectedIndexJS = "(function(){if($(\".main\").first().data(\"filename\") != '" + pcs.OpendIndex.FileName + "'){$(window).scrollTo($(\".main[data-filename='" + pcs.OpendIndex.FileName + "']\"), 300);}})();"; htmlStr = htmlStr.Replace("#DOCUMENT_READY_SCRIPT#", scrollToSelectedIndexJS); } htmlStr = htmlStr.Replace("#PLACE_HOLDER_SCROLL_SCRIPT#", ""); } else if (pcs.OpendContentType == PublicationContentTypeEnum.Annotation) { //TODO GotoBarButton.Hidden = true; PageNumLabel.Hidden = true; htmlStr = htmlStr.Replace("#PLACE_HOLDER_SCROLL_SCRIPT#", ""); content = "<div class='nocontent'><span>You have no annotations, highlight text in your publications to add one</span><div>"; } if (content != null) { float defaultFontSize = SettingsUtil.Instance.GetFontSize() > 0 ? SettingsUtil.Instance.GetFontSize() : 14; htmlStr = htmlStr.Replace("#PLACEHOLDER_DEFAULT_FONT_SIZE#", "" + defaultFontSize); htmlStr = htmlStr.Replace("#PLACE_HOLDER_SCROLL_TO_ID#", AppDataUtil.Instance.ScrollToHtmlTagId); htmlStr = htmlStr.Replace("#PLACE_HOLDER_HIGHLIGHTED_KEYWORD#", AppDataUtil.Instance.HighlightSearchKeyword); content = ContentFormatUtil.Format(content); content = Regex.Replace(content, @"<td />", ""); content = Regex.Replace(content, @"<div[^/^>]*?/>", ""); htmlStr = htmlStr.Replace("#CONTENT#", content); ContentWebView.LoadHtmlString(htmlStr, url); } hud.Hide(animated: true, delay: 0.2); }