fill jQuery mobile page with long text like an e-reader - php

Okay, so this is what I am trying to do with jQuery Mobile
I have a long text file. I am trying to display it on a mobile device so that it fills the entire screen. I have been trying to put the text into a div and then keep creating new divs until all of the text are in divs one following another.
"Just like you would view with an e-reader."
Of course, this has to be dynamic because of the different mobile screen sizes.
The best I can come up with is adding one character at a time until it reaches the height of the div but the often characters don't end at the left margin. They end somewhere in between.
I have tried PHP, jQuery, and plugins that use ellipses. I'm stuck. I would be happy if I could get the overflow into a new div and then that overflow into a new div and so on...
If anyone has a solution and maybe put it in a Fiddle, you would make my year!
Thanks!

Related

Iframe vertical scrollbar appearing right after submit button is pushed

I have a contact form displayed in an iframe in an overlay div that I have adjusted to fit the div within the guidelines of the div dimensions. There are no scrollbars showing when the div first appears. Then I fill out the form, hit send, and there is a moment right after I hit send that the vertical scrollbar appears, obviously while the form is sending, and then the scrollbar disappears again after I get the confirmation screen.
Now I don't really know where to start, except that I believe my css is good. I have two css files attached to my contact.php. I also have a process_form.php and three javascript files (two of which are jquery references). I don't want to paste all of them here because of all the code. Like I said, I have went through the css up and down, but I am not as experience with js or php to see if it is something in the code there. If anyone can point me in the right direction as to where to look, that would be great. If you want me to post a certain section of code, I will. But like I said, I don't want to just post random code here. In the image above, the top screenshot is before I hit submit, the second image down is seconds after hitting send, and then the last image is my confirmation. The scrollbar is only vertical for a second. And I have already applied the following class to my iframe, which does not help:
.restrict{
width: 700px;
height: 380px;
overflow-y: hidden;
}
What is peculiar about that also, is that I had to adjust the width of all the elements in my contact form perfectly to get it to fit into my display div because the vertical scrollbar kept showing anyways with the above class. So I am not sure why the overflow property wasn't working before I adjusted the width in my css of my elements, but I could not get rid of that vertical scrollbar until I got my form to fit inside my display div.
Any suggestion as to how I can just get the vertical scrollbar not to show up at all would be great if it is too difficult to examine my code to find the problem in the first place.
Instead of using css you can use html to hide scroll bars. Like this-
<iframe scrolling="no"></iframe>
I hope this helps.

Creating a Preview box

I have made a small div box, just enough to contain 2 and a half line of sentence. But actually what I want to do is, I am just showing the preview (few lines of sentence ). And I want to add "read more..." at the end of the sentence, which when clicked by the user would lead to another page showing the whole article.
I am extracting these article from the database. My problem is, how to extract just a few line from the database and preview it in the small div box...?
what is the best way to do it? how should I control the amount of the text as a preview to be shown in a div box.
can it be controlled with Javascript, PhpMysql extraction code, CSS ? what is the best way ?
note:
(I am extracting article from database. As a test bed I am using the wamp server along with its mysql database)
What you can do is extract the whole text from the database, and run the following javascript on your text nodes:
Cutter.js
From their documentation:
Cutter.run( oApplyTo, oTarget, nWords, oTexts, oClasses )
You can do something like excerpt column in your database and show it in your div box and when user clicks on read more you can load full text from db. Or you can write simple js script which will be cut everything you don't need. Or you can give your div box an size via css and set overflow property to hidden:
.excerpt {
width: xx px;
height: xx px;
overflow: hidden;
}
Not the ANSWER, but some hints:
You may try ajax, to fetch the entire article & clip it using js.
Alternately, provide a server side support to provide clipped article & fetch that using ajax.
After you have got the clipped part of the article, it should be fairly easy to display it in the div, using innerHTML.
To fix the location of the div box, you can either use js or css.

php page scraping task

I use Simple HTML DOM library in my Drupal custom module to do a task in my project.
The task simply is imitating the Facebook action, when we paste an article url, FB scrap the url and return back with part of the article as a description and an image.
My question is, what is the used algorithm to pick the first part of the article between a lot of <p> tags and also pick the right picture between all the pics in the page!
I know that FB use a :OG tag, but I need to develop an algorithm which pick these info if the OG tag is not there.
Thank you guys for support and have a nice day.
Regards.
I think with the image it is the dimensions of the image. Th takes the first image with more than say 100x100 pixels or so.
With the text it might be something similar. Strip the inline HTML tags, get the first block element text (or maybe just paragraphs) and there you go.

Why first two images load incorrectly in jquery

I know that the question I have is quite complex, and I really hope someone can help me. I have created an image gallery qih jquery and php. Firstly I am grabbing all the image names from a MySql database, then taking them from the server folder and resizing them with php. It creates the thumbnails, then I created a pop up window with jquery which shows the image in large. After that I place a previous and next button and told jquery to grab the array of image results from php and echo them into the jquery using json. Then it goes through the array to create the next and previous effect. I then centered each individual image when the next and previous button were clicked. When you load the first and second picture it is not centered and it goes to the right. I CAN NOT figure out why this is happening. I really need some help here. There is too much code to post here so I am giving you the website and you can see pretty much everything in the source code. Remember that I am using php so if you are wondering how it is iterating through the pictures that why. Thanks if anyone can help me at all.
http://www.oceanphotostudio.com/test/collection/before-and-after.php
The reason it's getting offset is that the margins that center the popup div are being calculated before the image is loaded. Notice that on the first click, it will have margins of -37px and -30px. After one image is loaded, calling another one will use the width and height of the last image that was loaded in, which is why you can get unpredictable results.
Take a look at JQuery's load event handler for information on how to create a callback to resize after the image has been set to load, rather than before.
Your description totally overcomplicates the issue. Browser could care less how you generate the array or html on server, or what language it is
Your position problem is a simple css issue. You've set the top and left of your popup to 50%. This means top left corner of popup will start at dead center of page, and go right and down from there.
Use a browser console to inspect the html elements and the css rules that apply to them and adjust accordingly. WIthin the console you can make live edits to see impact of the adjustments in real time

DIV resizing in JS : can this be done before the page is displayed?

In my page I give a certain size to a DIV with jQuery, based on the size of the last tweet that I retrieve through PHP.
Problem : I need to use jQuery(window).bind("load", function() in order for jQuery to "see" the size of the tweet, but then, I can see the resizing (perfomed my jQuery) in front of my eyes and I dislike it. I want the page to appear in its final state.
Is that possible ?
You have two options. 1) Start off with your tweet element hidden, then show/fade it in when everything is loaded.
2) My preferred solution is to call the $.blockUI() plugin as soon possible, and then $.unblockUI when everything has loaded. The blockUI plugin also has a facility for blocking only certain elements rather than the whole page, there is a demo here
You can always let it render at a top margin of -1000px and then pop it back down, or perhaps z-index it underneath something else.
Some browsers have problems "seeing" hidden divs while some can do it, but it's unrelible so best bet is to render it outside the canvas.

Categories