Folder level script referencing document level script - javascript

I have the following javascript code that works at the document level in Adobe Acrobat 10 when the document is opened (enveloped in this.addScript):
var nNumFields = this.numFields;
var cFieldName;
var oField;
for(i = 0; i < nNumFields; i++)
{
cFieldName = this.getNthFieldName(i);
oField = this.getField(cFieldName);
oField.textFont = \"PTSans\";
}
I want to avoid going through multiple documents and adding this script to all of them. Is there a way to adapt this code to the folder level so it works for all acrobat opened documents?? If so what would it be?
Or is there a way to add this script for a list of documents quickly (programmatically) instead of manually?? (manually as in by opening the document, inserting the script into the debugger, running it, then saving the document, then repeating for every document)

Related

Google App Script , find file's parent id if exist in a Sheets

I'm trying to find (in a Google Sheets list of file Id) file's parent ID in a loop, until it's present in another Google Sheets. All is ok for the first parent but it doesn't work when i'm trying to get 2nd or 3rd parent's generation higher. My fileParent is "undefined" , i don't know why cause row 3 my var file return the correct first parent ID.
`
//all var are initialized before
var files = DriveApp.getFileById(*My File ID*);
var myFiles = files.getParents()
var file = myFiles.next().getId();
for(var rowRef in tab_ref){
if(file != tab_ref[rowRef][9]){
while(tab_ref[rowRef][9] != file && files.hasNext()){
var fileParent = DriveApp.getFolderById(file);
files = fileParent.getParents();
file = files.next().getId();
}
if(tab_ref[rowRef][9] == id_file){
sheet_files.activate();
sheet_files.getActiveCell().offset(2,10).setValue(file);
}
}
}
I'm not sure this is the easiest way to find what your looking but I think it is a way to do it. I use these sorts of loops to build directory trees for access to all sorts of hierarchical data and I also incorporate JQuery jstree to create an easy to use UI for anybody that's use to navigating on a computer. So here's the code. If your not familiar with this kind of coding it may take you a while to figure it out. Have fun with it. I incorporated comments that refer to a parentsArray[]. The parentsArray[] could be used as kind of stack where you push and pop current folder names onto and off of the stack in order to keep track of your current path or parental ancestry of folders.
function traverseFolder(folderObj)
{
//parentsArray[parentsArray.length-1] is the immediate parent of the current folderObj.
//Put folderObj name, size info here
//Push folderobj name on to parentsArray
var subs = folderObj.getFolders();
var files = folderObj.getFiles();
if(files)
{
while(files.hasNext())
{
var fi = files.next();;
//Put file name,size,info here
//parentsArray[parentsArray.length-1] is the immediate parent of all of these files
//parentsArray[0]/parentsArray[1].../parentsArray[parentsArray.length-1] is the path to this file.
}
}
while (subs.hasNext())
{
traverseFolder(subs.next());
}
//Pop last folderobj off of the parentsArray
}

Can I fetch a title of an external page in my domain using JavaScript?

I have several pages (all reside in the same directory as master page) that are loaded into the parent via iFrame. I would like to fetch each one of the child pages titles and load them into an array. Is that possible?
Best I could do so far is to pass the tile from a child page when the page is loaded into an iFrame, but I need to preload all the titles from the start in order to populate the table of contents as shown below:
Parent code:
var pages = new Array("page1.html", "page2.html", "page3.html");
var maxPages = pages.length;
function pageTitle(title){ //called from inside a child HTML
document.getElementById("titleText").innerHTML = title;
};
child code:
window.onload = function passTitle(){
var title = $(document).find("title").text();
parent.pageTitle(title);
};
You want to use window.frames - this is a list of frame objects (not an array - important to know for the second solution)
Then, the simplest way is this
var pageTitles = [];
for (i = 0; i < window.frames.length; i++) {
if( !!window.frames[i].document) { // only frames in same domain
pageTitles.push(window.frames[i].document.title);
}
}
Or, little more advanced, but in my opinion the nicer way
var pageTitles = [].filter.call(window.frames, function(frame) {
return !!frame.document; // return only frames in same domain
}).map(function(frame) {
return frame.document.title;
});
actually you could use just window without the .frames - at least in firefox, because window.frames === window - however, I'd recommend using window.frames for clarity in code

Jump to page in PDF.js with javascript

I'm trying to use PDF.js' viewer to display pdf files on a page.
I've gotten everything working, but I would like to be able to 'jump to' a specific page in the pdf. I know you can set the page with the url, but I would like to do this in javascript if it's possible.
I have noticed that there is a PDFJS object in the global scope, and it seems that I should be able to get access to things like page setting there, but it's a rather massive object. Anyone know how to do this?
You can set the page via JavaScript with:
var desiredPage = [the page you want];
PDFViewerApplication.page = desiredPage;
There is an event handler on this, and the UI will be adjusted accordingly. You may want to ensure this is not out of bounds:
function goToPage(desiredPage){
var numPages = PDFViewerApplication.pagesCount;
if((desiredPage > numPages) || (desiredPage < 1)){
return;
}
PDFViewerApplication.page = desiredPage;
}
In my case I was loading pdf file inside iframe so I had to do it in other way around.
function goToPage(desiredPage){
var frame_1 = window.frames["iframe-name"];
var frameObject = document.getElementById("iframe-id").contentWindow;
frameObject.PDFViewerApplication.page = desired page;
}
if Pdf shown into iframe and you want to navigate to page then use below code. 'docIfram' is iframe tag Id.
document.getElementById("docIframe").contentWindow.PDFViewerApplication.page=2

How to find if a javascript is already loaded or not?

I am developing a chrome extension to ajaxify every non ajax website like wikipedia. etc. It works fine but it fail to load the js files. So, I have written a script to load js files thats are required for the page by getting src attribute from tag. But the problem is when i am loading another page of that website every scripts are loaded again. So it is useless to make it with a purpose to reduce bandwidth.
So, I want to know whether there is any way to match the script array of the new with its previous page. and to identify which scripts are new and load only them.
var array1 = [];
for (var i = 0; i < jsn; i++) {
var jssrc = document.getElementsByTagName("script")[i].src;
array1.push(jssrc);
}
var array2 = [how to find out array script source of the new page]
Array.prototype.diff = function(array2) {
var ret = [];
for(i in this) {
if(array2.indexOf( this[i] ) > -1){
ret.push( this[i] );
}
}
return ret;
};
ajaxpagefetcher.load("ajax-script", "", true, array1.diff(array2);)
How to find script src array of the new page that is to be loaded..
one more question, with out reloading the page if i delete the body tag through remove() function, are the scripts that already loaded also removed?
Thanks
I am waiting with eager for your replay....
At the end of the JS file:
window.iAmLoadedOnThisWindow = true;
And in the loader part:
if(! window.iAmLoadedOnThisWindow) {
// append the script with some dom method
}
If the JS file is a library, test the library : if(jQuery), if(_), etc.

how can Firefox add-on access user's bookmarks folders

I'm writing some Firefox add-on code that manipulates the user's bookmarks.
I started with the "Searching Bookmarks" code from https://developer.mozilla.org/En/Places_Developer_Guide, and ended up writing the following code, which works...
var folders = [bookmarksService.bookmarksMenuFolder, bookmarksService.toolbarFolder, bookmarksService.unfiledBookmarksFolder];
var bookmarks = [];
for (var i = 0; i < 3; i++) {
query.setFolders([folders[i]], 1);
var result = historyService.executeQuery(query, options);
var rootNode = result.root;
rootNode.containerOpen = true;
getNode(rootNode, bookmarks);
rootNode.containerOpen = false;
}
The problem with this code is that it hard-codes the 3 default bookmark folders. I'd like the code to handle the case in which the user has created their own bookmark folders.
How can this code be changed so that it loops over all of the bookmark folders?
I think you're getting confused with the "folder" terminology here. The three hard-coded items you have in your code block are all you need. Any bookmarks the user creates will be located in one of these three places. You can see this in action by opening up the bookmarks editor in Firefox (Ctrl + Shift + B). In the tree pane on the left, select the All Bookmarks item, and note that there are only 3 (possibly 4) items underneath it:
Bookmarks Toolbar
Bookmarks Menu
Unsorted Bookmarks
If you right-click the "All Bookmarks" top-level item, you'll note that there is no "Create Folder" option at this level. Any user-created bookmarks are below the sub-items listed at this level.
The Places Developer Guide lists one additional top-level folder (tagsFolder), but I don't think you need to worry about that one. I can't imagine a bookmark existing there and not in one of the other three locations.

Categories