iBooks JavaScript Environment - invalid element name - javascript

So, I've narrowed down my error (well, at least the first one) to this function:
var genArray = function () {
var arr, len, i;
if(arguments.length > 0) {
len = [].slice.call(arguments, 0, 1)[0];
arr = new Array(len);
for(i = 0; i < len; i++) {
arr[i] = genArray.apply(null, [].slice.call(arguments, 1));
}
} else {
return null; //or whatever you want to initialize values to.
}
return arr;
}
Then, I get a very unhelpful error:
error on line 71 at column 23: StartTag: invalid element name
Below is a rendering of the page up to the first error
Now, the function is decidedly not on line 71 (perhaps it is in the compiled ePub, but I have no idea how they correlate). Further, I have no idea what that error means in a JavaScript context. Also, this code works fine in a browser (Safari included).
Any ideas what could be causing the issue?
EDIT: On a whim, I checked whether [] was the problem by changing it to Array(). No luck.

Okay, so I discovered a solution to my problem. I just needed to surround my JavaScript in CDATA tags like so:
//<![CDATA[
var genArray = function () {
var arr, len, i;
if(arguments.length > 0) {
len = [].slice.call(arguments, 0, 1)[0];
arr = new Array(len);
for(i = 0; i < len; i++) {
arr[i] = genArray.apply(null, [].slice.call(arguments, 1));
}
} else {
return null; //or whatever you want to initialize values to.
}
return arr;
}
//]]>
I discovered this by using the epubcheck tool which said something to the effect that the file must have properly formed characters or something. I don't recall the exact message. Anyways, this reminded me of a problem I had in a script where I used some unicode characters. I remembered about CDATA which solved it. Then I found this stackoverflow question which basically says it's necessary for when your pages must be interpreted as XML/XHTML as well, which is the case for ePubs.
So, moral of the story is wrap javascript in CDATA tags for ePubs or iBooks.
EDIT: It should be noted that it's worth doing this around all of your JavaScript. The issue in my case was the < less than operator being interpreted as the start of a tag. However, it is probably cleaner to just include the CDATA tag around all of your JavaScript rather than trying to isolate sources of the issue.
EDIT 2: In the interest of aggregating information to whoever finds this answer useful, it should also be noted that having all of one's JavaScript in external files probably also works (according to the source linked in the answer to the question I've linked to). I don't care to test this at the moment, but it should work because the external JavaScript will not be parsed as XML like it is inside of a <script> tag.

The error you report indicates the XHTML file source is in error. I would take a look at, uhh, line 71 column 23 of the XHTML file in question. What's there? Could it possibly be <StartTag>? Is the XHTML being generated programatically somehow? EPUBs are not "compiled"; they are just zipped, and this line/column information refers to the actual position in the XHTML file in the EPUB. What does epubcheck say?
This kind of error message would not be generated by problems in any dynamic HTML created via script; those would result in a DOMError.
My guess is that iBooks is finding some error in the function at parse time, which terminates the parsing process before the XHTML parsing is completed and the XHTML error can be reported. However, I can't imagine what the error might be; I doubt it's the missing semi-colon at the end of the function, but could possibly be depending on what's on the next line.
Totally minor point, but
len = [].slice.call(arguments, 0, 1)[0];
is the same as
len = arguments[0];

Sounds to me more like an XHTML error. When you run in the browser if you are not opening it as an XHTML file, do so and see if it breaks. Browsers tend to be more lenient than EPUB readers. You are most likely creating some sort of invalid HTML element with your slices, it would be great to have the full page to identify exactly what 'getArray()' is returning...

Related

Reordering/move pages using Indesign script

I have a nearly 400 page document that I need to [randomly] reorder the pages. (If you need to know, this is a book of single page stories that need to be randomly distributed. I created a random list of pages to input into the script.)
I've been working with a modified script I found elsewhere on the internet that creates an array and moves the pages around:
var order="...list of new page numbers...";
// Create an array out of the list:
ranges = toSeparate (order);
if (ranges.length != app.activeDocument.pages.length)
{
alert ("Page number mismatch -- "+ranges.length+" given, "+app.activeDocument.pages.length+" in document");
exit(0);
}
// Consistency check:
sorted = ranges.slice().sort(numericSort);
for (a=0; a<sorted.length-1; a++)
{
if (sorted[a] < sorted[a+1]-1 ||
sorted[a] == sorted[a+1])
alert ("Mismatch from "+sorted[a]+" to "+sorted[a+1]);
}
// alert ("New order for "+order+"\nis "+ranges.join(", "));
// Convert from 1..x to 0..x-1:
for (moveThis=0; moveThis<ranges.length; moveThis++)
ranges[moveThis]--;
for (moveThis=0; moveThis<ranges.length; moveThis++)
{
if (moveThis != ranges[moveThis])
{
try{
app.activeDocument.pages[ranges[moveThis]].move (LocationOptions.BEFORE, app.activeDocument.pages[moveThis]);
} catch(_) { alert ("problem with page "+moveThis+"/index "+ranges[moveThis]); }
}
for (updateRest=moveThis+1; updateRest<ranges.length; updateRest++)
if (ranges[updateRest] < ranges[moveThis])
ranges[updateRest]++;
}
function toSeparate (list)
{
s = list.split(",");
for (l=0; l<s.length; l++)
{
try {
if (s[l].indexOf("-") > -1)
{
indexes = s[l].split("-");
from = Number(indexes[0]);
to = Number(indexes[indexes.length-1]);
if (from >= to)
{
alert ("Cannot create a range from "+from+" to "+to+"!");
exit(0);
}
s[l] = from;
while (from < to)
s.splice (++l,0,++from);
}} catch(_){}
}
// s.sort (numericSort);
return s;
}
function numericSort(a,b)
{
return Number(a) - Number(b);
}
This code worked, except that it was consistently rearranging them into the wrong random order, which, at the end of the day, is workable, but it'll just be a bigger pain in the ass to index the stories.
I suspected the problem might be caused by starting at the begginning of the document rather than the end, so I modified the script to start at the end, but then app.activeDocument.pages[ranges[moveThis]] kept coming up as undefined.
So I gave up and tried this:
app.activeDocument.pages[298].move (LocationOptions.BEFORE, app.activeDocument.pages[366]);
app.activeDocument.pages[33].move (LocationOptions.BEFORE, app.activeDocument.pages[365]);
app.activeDocument.pages[292].move (LocationOptions.BEFORE, app.activeDocument.pages[364]);
And so on for every page. (This reminds me of my time in junior high using sendKeys to create programs in Visual Basic. Had I bothered to seriously learn JavaScript instead of creating shitty AOL chatroom scrollers, I probably wouldn't be on here today.)
Nevertheless, I received the following error:
Error Number: 30477
Error String: Invalid value for parameter 'reference' of method 'move'. Expected Page or Spread, but received nothing.
I'm trying to avoid having to manually move the pages, especially considering the amount of time I've already been working on this. Any suggestions on what I need to change? Thank you!
The issue might be that you are using more than one page per spread and then trying to shuffle them across spread. The better way is to use single page per spread.
Here is a small snippet that works on my machine
var doc = app.activeDocument;
doc.documentPreferences.facingPages = false;
for (var i =0; i < 100; i++){
var index = parseInt((Math.random() * doc.spreads.length) % doc.spreads.length + '' , 10);
doc.spreads[index].move();
}
What this does is
Disables the facing pages options and makes one page per spread. A desirable condition as you mentioned that your stories are one page each(I am assuming that your stories will not violate this assumption).
Takes a random spread from the doc and sends it to the end of the spreads in the doc. It does so 100 times.
The result is what you wanted. A script to shuffle the current SPREADS randomly.

How can I decode a javascript snippet that is obfuscated with what appears to be a unicode or regex string with an eval() function?

So I came across an interesting piece of javascript that I can't quit figure out. It appears to me at first to be either regex function or a unicode string, that is then passed onto an eval function for processing. I have been trying for quite some time to decode it, but I don't seem to be making any headway. I'm hoping someone might be able to tell me what is going on here, and maybe show me how to decode it.
Edit: So it turns out that the code I posted before was flawed from a previous decoding attempt. This is the corrected code.
$(window).load(function() {
var d = '960';
var d1 = '960';
var q = 'u94';
var uw = $("#u94");
var _0xf924 = ["1m B=[\"\\a\\l\\v\\e\\k\\t\\d\\s\\9\\a\\a\\9\\a\\e\\9\\h\\g\\9\\i\\j\\9\\a\\g\\9\\a\\e\\9\\a\\g\\9\\f\\l\\9\\a\\j\\9\\h\\h\\9\\i\\b\\9\\h\\e\\9\\a\\k\\9\\a\\i\\9\\h\\e\\9\\h\\k\\9\\b\\b\\l\\9\\k\\b\\9\\a\\a\\9\\a\\e\\9\\h\\g\\9\\i\\j\\9\\a\\g\\9\\a\\e\\9\\a\\g\\9\\f\\l\\9\\a\\j\\9\\h\\h\\9\\i\\b\\9\\h\\e\\9\\k\\g\\9\\k\\j\\9\\h\\e\\9\\h\\k\\s\\m\\s\\9\\a\\g\\9\\a\\e\\9\\a\\g\\9\\f\\l\\9\\a\\j\\s\\m\\s\\9\\a\\f\\9\\a\\g\\9\\a\\g\\9\\a\\k\\s\\m\\s\\9\\b\\g\\f\\9\\f\\j\\9\\a\\f\\9\\h\\b\\9\\a\\j\\s\\m\\s\\9\\h\\g\\9\\a\\e\\9\\f\\e\\9\\a\\e\\9\\h\\l\\9\\f\\l\\9\\a\\j\\s\\m\\s\\9\\h\\f\\9\\f\\e\\9\\f\\e\\s\\m\\s\\9\\h\\a\\9\\h\\b\\9\\a\\k\\9\\f\\j\\9\\a\\j\\9\\f\\l\\9\\a\\j\\9\\f\\k\\s\\m\\s\\9\\b\\b\\g\\9\\a\\e\\9\\f\\i\\9\\a\\a\\s\\m\\s\\9\\h\\a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,H,14){H=U(C){O C};18(!B[5][B[4]](/^/,1j)){17(C--){14[C]=I[C]||C};I=[U(H){O 14[H]}];H=U(){O B[6]};C=1};17(C--){18(I[C]){P=P[B[4]](1i 1h(B[7]+H(C)+B[7],B[8]),I[C])}};O P}(B[0],10,1e,B[3][B[2]](B[1]),0,{}))", "|", "split", "|||||||||x5C|x35|x31|x5D|x5B|x34|x36|x30|x37|x38|x32|x39|x33|x2C|x7C|x78|x65|x29|x28|x22|x3D|x3B|x20|x5F|x24|x2B|x7B|x7D|_0xaced|_0x985ex3|x2F|x64|x6E|x61|_0x985ex5|_0x985ex4|x6C|x69|x73|x66|x44|return|_0x985ex1|x26|x63|x2D|x77|function|x62|x74|x21|x2A|x41||x72|x75|x70|_0x985ex6|x6F|x45|while|if|x43|x67|x42|x71|x3E|144|x3A|x3C|RegExp|new|String|x46|x49|var|x7A|x68|x6D|eval|_0x985ex2|x76", "", "fromCharCode", "replace", "\\w+", "\\b", "g"];
eval(function(_0x4a22x1, _0x4a22x2, _0x4a22x3, _0x4a22x4, _0x4a22x5, _0x4a22x6) {
_0x4a22x5 = function(_0x4a22x3) {
return (_0x4a22x3 < _0x4a22x2 ? _0xf924[4] : _0x4a22x5(parseInt(_0x4a22x3 / _0x4a22x2))) + ((_0x4a22x3 = _0x4a22x3 % _0x4a22x2) > 35 ? String[_0xf924[5]](_0x4a22x3 + 29) : _0x4a22x3.toString(36))
};
if (!_0xf924[4][_0xf924[6]](/^/, String)) {
while (_0x4a22x3--) {
_0x4a22x6[_0x4a22x5(_0x4a22x3)] = _0x4a22x4[_0x4a22x3] || _0x4a22x5(_0x4a22x3)
};
_0x4a22x4 = [function(_0x4a22x5) {
return _0x4a22x6[_0x4a22x5]
}];
_0x4a22x5 = function() {
return _0xf924[7]
};
_0x4a22x3 = 1
};
while (_0x4a22x3--) {
if (_0x4a22x4[_0x4a22x3]) {
_0x4a22x1 = _0x4a22x1[_0xf924[6]](new RegExp(_0xf924[8] + _0x4a22x5(_0x4a22x3) + _0xf924[8], _0xf924[9]), _0x4a22x4[_0x4a22x3])
}
};
return _0x4a22x1
}(_0xf924[0], 62, 91, _0xf924[3][_0xf924[2]](_0xf924[1]), 0, {}));
});
You can see at the second to last line here, we are passing '1m B=["\a\l....' to the function inside the eval. When I first saw this, I thought it was a Regex of some kind that was then converted by the browser as text, but to my knowledge, there isn't a way to convert it back? Looking into this further, I was told that it could all be unicode, but trying to convert the string back into characters has failed in ever converter I have tried. Am I way off base here?
EDIT: See below for update! I exceeded the character limit, lol!
This line var uw = $("#u94"); almost certainly means it's using content from the page itself to do the decoding.
The easiest way I can think of to try to get the code that is actually running is to return to where you found the code and open up your dev tools. Find the code again (I am guessing it's probably dynamically generated) and then without leaving the page copy/paste it into the text editor of your choice and do the following:
1) Change the first line like this
$(window).load(function() { -> (function() {
2) Change the last line like this:
}); -> })() (now you have a self-calling function)
3) Just before the last return add a console.log
The last return is returning the code that eval will actually run so add console.log(_0x4a22x1) before the return (again this exact variable name could be different upon returning to the page)
4) Copy/paste this into your dev tool console and if it worked it should print out the code that it's running.
NOTE: It's entirely possible that once the code runs the first time it removes the element (currently #u94) that contains something you need to run the code (so it could not work). So if it doesn't log the code out, then the first thing I would do it is a normal View page source (or curl the html) and find out what the #u94 element contains and adapt the code as necessary.
Good luck!

Same code, same browser, different behavior for users

I have a piece of JS code which parses through a file, then associated the array with a key-value pair map, and then iterates it through it to find the proper city name with a .includes method. My problem is that the final field (where the function in question is called) works fine on my end for both Chrome and Firefox. It does not work for some reason for my group members.
This is the JS snippet that does the iterating:
Edit: this is how the file is being opened:
var rawFile = new XMLHttpRequest();
rawFile.open("GET", "../data/myFile.txt", false);
for (var i = 0; i < allText.length; i++) {
if (i % 2 == 0) {
myMap[allText[i]] = allText[i + 1];
}
}
var city = document.getElementById("city").value;
for (var key in myMap) {
if (myMap.hasOwnProperty(key)) {
if (myMap[key].toLowerCase().includes(city.toLowerCase())) {
document.getElementById("city").value = myMap[key]
document.getElementById("zipcode").value = key;
}
}
}
This is the html part that calls it:
<label for="myLabel">City: </label>
<input type="text" name="myLabel" id="myLabel" onblur="readTextFile()">
What exactly is the problem and how can I troubleshoot it as it makes no sense to me, coming from the world of Java and C++, where I have never faced such an issue before. If you are wondering why the JS might be kinda ugly, it is the result of a student with a teacher who thinks that showing W3Schools examples is equivalent to good teaching.
Javascript includes function may work erratically due to some browsers not supporting it. You need to be wise while choosing the javascript functions specially when mozilla may have some functions which are not supported on some browsers. W3schools also provides a list of Browser support for a function. Check the link below for that list for includes function:
http://www.w3schools.com/jsref/jsref_includes.asp
Alternatively, you can use indexOf function like:
myMap[key].toLowerCase().indexOf(city.toLowerCase()) >= 0
I have myself faced issues with includes function hence providing you a workaround. Happy programming.

IE Issue with Javascript Regex replacement

r = r.replace(/<TR><TD><\/TD><\/TR>/gi, rider_html);
...does not work in IE but works in all other browsers.
Any ideas or alternatives?
I've come to the conclusion that the variable r must not have the value in it you expect because the regex replacement should work fine if there is actually a match. You can see in this jsFiddle that the replace works fine if "r" actually has a match in it.
This is the code from fiddle and it shows the proper replacement in IE.
var r = "aa<TR><TD></TD></TR>bb";
var rider_html = " foo ";
r = r.replace(/<TR><TD><\/TD><\/TR>/gi, rider_html);
alert(r);
So, we can't really go further to diagnose without knowing what the value of "r" is and where it came from or knowing something more specific about the version of IE that you're running in (in which case you can just try the fiddle in that version yourself).
If r came from the HTML of the document, then string matching on it is a bad thing because IE does not keep the original HTML around. Instead it reconstitutes it when needed from the parsed page and it puts some things in different order (like attributes), different or no quotes around attributes, different capitalization, different spacing, etc...
You could do something like this:
var rows = document.getElementsByTagName('tr');
for (var i = 0; i < rows.length; i++) {
var children = rows[i].children;
if (children.length === 1 && children[0].nodeName.toLowerCase() === 'td') {
children[0].innerHTML = someHTMLdata
}
}
Note that this sets the value of the table cell, rather than replacing the whole row. If you want to do something other than this, you'll have to use DOM methods rather than innerHTML and specify exactly what you actually want.

JQuery "Constrain" plugin - Weird Javascript Error

Background: Our web app uses the jquery.constrain.js plugin to handle data entry in some text boxes, to only allow valid characters to be added. This plugin allows various constraints upon the data, using regular expressions, whitelist/blacklist characters, etc. Until today, we were running the 1.0 release of this plugin, unmodified.
I noticed a few days ago that some of the text boxes still allowed invalid data entry. For example, a numeric-only textbox allowed alpha characters, etc. It also displayed a javascript error "Object doesn't support this property or method". I tracked it down to the following function in the jquery.constrain plugin.
function match(item, input, e) {
var arr = item.chars.split("");
for (var i in arr) {
var token = arr[i];
if (token.charCodeAt(0) == e.which) {
return true;
}
}
if (item.regex) {
var re = new RegExp(item.regex);
if (re.test(String.fromCharCode(e.which))) {
return true;
}
}
return false;
};
Debugging through this block of code, I determined the following:
item is an object with two string properties: chars and regex
item.chars is an empty string ("") at the time of failure.
arr, the result of item.chars.split("") is, as expected, an empty array.
Here's where it's weird. Even though arr is an empty array, the for loop assigns a valid value to i. The value is "remove". So we drop into the loop. token is obviously null, because arr["remove"] is null. So token.charCodeAt(0) throws.
I corrected the error by adding an if statement around the for loop, as follows:
if (arr.length > 0) {
for (var i in arr) {
var token = arr[i];
if (token.charCodeAt(0) == e.which) {
return true;
}
}
}
However, I'm completely baffled as to why this was even necessary - is this an IE bug, a bug in the plugin, or am I just holding my breath wrong when I compile the app?
You should never use for(i in arr) to loop over Arrays. If scripts add methods to the Array prototype these too will be iterated using the for(i in arr) loop. This is probably what is causing your errors. You probably have added a script that modifies the Array.prototype chain.
Also read here under "Why you should stop using for…in to iterate (or never take it up)"
http://www.prototypejs.org/api/array

Categories

Resources