View Full Version : Crawler v1.5 help
siluet
05-18-2012, 07:43 PM
1) Text and Image Crawler v1.5
2) http://www.dynamicdrive.com/dynamicindex2/crawler/index.htm
3) the above Crawler v1.5 script not works for me..
Page sample:
http://www.expireurl.com/go.php?id=RCicjJXH
jscheuer1
05-19-2012, 03:53 PM
.
Your page is in violation of Dynamic Drive's usage terms (http://www.dynamicdrive.com/notice.htm), which, among other things, state that the script credit must appear in the source code of the page(s) using the script. Please reinstate the notice first.
That said, this works:
<!DOCTYPE html>
<html>
<head>
<title></title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<script type="text/javascript" src="crawler.js">
// Text and/or Image Crawler Script v1.5 (c)2009-2011 John Davenport Scheuer
// as first seen in http://www.dynamicdrive.com/forums/
// username: jscheuer1 - This Notice Must Remain for Legal Use
// updated: 4/2011 for random order option, more (see demo page)
</script>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.7/jquery.min.js"></script>
<script type="text/javascript">
// Import and Update Content to Crawler Script (c)2012 John Davenport Scheuer
// as first seen in http://www.dynamicdrive.com/forums/showthread.php?p=274638#post274638
// username: jscheuer1 - This Notice Must Remain for Legal Use
// requires Text and/or Image Crawler Script v1.5, and jQuery
jQuery(function($){
// do not edit this line:
var $tempcont = $('<span style="display: none;"></span>').appendTo('body'), tc, count, marq, $omarkup,
// filename (include path if different than this page) of the data generating page, must be on the same domain:
contentpage = 'track.php',
// jQuery type of css class selector of nested span in crawler that receives updates:
contentselector = '.scroll',
specs = { // init specs for crawler:
uniqueid: 'mycrawler',
style: {
'padding': '5px',
'width': '300px',
'background': '#ffffe0',
'border': '1px solid #c30'
},
inc: 8, // speed or 'cursor driven' top speed - pixel increment for each iteration of this marquee's movement
mouse: 'cursor driven', // mouseover behavior ('pause' 'cursor driven' or false)
moveatleast: 1, // if 'cursor driven' minimum speed when cursor is off marquee
neutral: 50, // size of neutral area in the center of 'cursor driven' marquee
savedirection: true
}; // end crawler init specs
////////////////////////// No Need to Edit Below Here //////////////////////////
$omarkup = $('#' + specs.uniqueid).clone();
$.ajaxSetup({cache: false});
$(contentselector).load(contentpage, function(){count = marqueeInit.ar.length; marqueeInit($.extend({}, specs));});
function update(){
$tempcont.load(contentpage, function(){
if((tc = $tempcont.html()) !== $('.marquee' + count + ' ' + contentselector).html()){
marq = marqueeInit.ar[count].setup;
marq.runit = function(){return;};
marq.c.onmouseover = marq.c.onmousemove = marq.c.onmouseout = null;
$(marq.c.parentNode).css({display: 'none'}).after($omarkup.clone().find(contentselector).html(tc).end()).remove();
count = marqueeInit.ar.length;
marqueeInit($.extend({}, specs));
}
});
}
setInterval(update, 10000);
});
</script>
</head>
<body>
<div class="marquee" id="mycrawler">
<span class="scroll"></span>
</div>
</body>
</html>
Notes:
Some browsers require a standards invoking DOCTYPE.
Even though it still checks every 10 seconds, it will only update the crawler if the contents of track.php have changed. This allows the user to have time to interact with the crawler between updates, and for a slower moveatleast speed for the crawler.
I think you can see where specifications for the crawler go, but any questions on that or the rest of it, feel free to ask.
siluet
05-20-2012, 10:58 PM
Hi John,
Sorry for accidentally removing credit notice, maybe I accidentally deleted it, when I moved code blocks on test page and doing various modifications. Surely I understand.
Thank you for adjusting script, it works fine. Some amplifications: for applying font style, can it be applied to existing css block for div, or we should set new css for <span class="scroll">?
For setInterval, I can reduce the server polling frequency to 20-25sec, it will be fully enough. However, if script can determine if the contents of track.php have changed, that's cool..
Would it be possible to adjust script for using input as PHP include? <? include "track.php" ?>
jscheuer1
05-21-2012, 04:37 AM
The bit about the credit is forum rules, and since it's my own work, also personal. But I know how easy it is when experimenting with code to leave off the credit notice on a mock up. I do it. I try to remember to reinstate it for production though.
The proper way to style the class="scroll" span would be in a stylesheet using a .scroll selector. However, it can be done inline using inline style:
<span class="scroll" style="font: bold 14px sans-serif; color: red;"></span>
not by putting font or any tags inside it though. A font tag or tags could go around it maybe, but font tags are deprecated anyway, so might cause an error or not get read properly. Or it could be done via inheritance, either by setting inheritable styles in the crawler's style object or by putting a container div around the crawler and setting inheritable styles for it.
The interval is immaterial to the script itself. However, checking more frequently will mean less potential lag time once the content does change. I'd be inclined to reduce it to like 2 seconds. But, the more frequently you check, the more load is put on the server. For something like this though, it's minimal. If there are restrictions on the number of requests per hour or similar imposed by the host, then you would have to poll less often.
You could include the track.php file:
<div class="marquee" id="mycrawler">
<span class="scroll"><?php include "track.php" ?></span>
</div>
And then in theory at least you could get rid of this line from the script:
$(contentselector).load(contentpage, function(){count = marqueeInit.ar.length; marqueeInit($.extend({}, specs));});
But not exactly. You would have to find a way to set the count and initialize the crawler independent of an initial AJAX import (doable), and since the exact way the innerHTML of the scroll div would look to the browser might not be equivalent to the way it would look when imported, it's safest to leave it as is. Updating could not be done via an include anyway. Though the updating page - the one that's fetched via AJAX could itself have an include or a file_get_contents() on it if you were fetching the data from another domain. But legal and/or bandwidth/request limit issues might apply in a situation like that.
Since none of this will work without javascript there's little reason for an include on the 'top' page, it might be better to do something like so:
<div class="marquee" id="mycrawler">
<span class="scroll">Loading . . . Javascript Required</span>
</div>
siluet
05-21-2012, 10:02 PM
So using include method has no advantages over calling track.php here? If updating could not be done via PHP include, then using include will not be suitable in this case, as the main purpose of this script is to display dynamic data, current audio track. PHP script uses file_get_contents() and SimpleXML to parse the data from a remote xml file.
jscheuer1
05-22-2012, 12:58 AM
PHP is static unless the page is reloaded/re-requested. You can periodically request a PHP page/script via AJAX, which is what we are currently doing, to see if there's any new or different content there and then import it to your page.
And/or you can periodically refresh the page via a meta tag. Care should be taken to not allow the the page to be cached*. Or should be obvious, to do and would require the judicious use of noscript tags. One around the meta refresh tag and another around the include, with the rest of the page more or less as we've already got it, using javascript to import the content. A third noscript tag could be around a style section or link that would render the javascript markup display: none;.
*I haven't actually done this, but it looks as though, if you use the absolute path to the include, you could add a time stamp as a cache busting query string, something like:
include ('http://www.example.com/file.php?fbustcache=' . time());
Powered by vBulletin® Version 4.2.2 Copyright © 2021 vBulletin Solutions, Inc. All rights reserved.