[indesign][js] dialog or palette - not show up - javascript

have problem with script.
need open a window with some information, which will automatically disappear after 3 seconds.
my code:
#targetengine "session"
var windowX = new Window("dialog"); // v2 palette
windowX.orientation = "row";
windowX.preferredSize.width = 200;
windowX.preferredSize.height = 200;
windowX.alignChildren = ["center","center"];
windowX.spacing = 15;
windowX.margins = 16;
var image1_imgString = "%C2%89PNG%0D%0A%1A..."
var image1 = windowX.add("image", undefined, File.decode(image1_imgString), {name: "image1"});
windowX.show();
dialog show, palette not
if I add ...
var timerBreak = new Date().getTime() + 3000;
var now = new Date().getTime();
while(now<timerBreak){
now = new Date().getTime()
}
windowX.close();
nothing happend (happend: first: loop, next: window show and close at the same time) - why?
if i add ...
windowX.addEventListener('show',function(){
...
}
same ...
but if i add alert("dhgkjsd") ... for check ... dialog (or palette) show and wait for click on messagaebox
how to make a timer that will close the displayed window 3 seconds after opening?

Unfortunately, I do not have a copy of InDesign to test this, but the code below works in AfterEffects.
#targetengine "session"
// To be called later
function closeMe() {
windowX.close();
}
// Timer as a variable
var delay = 3000;
// a pallette, and not a modal, like in your
// original code, because the modal is UI blocking
var windowX = new Window("palette");
windowX.orientation = "row";
windowX.preferredSize.width = 200;
windowX.preferredSize.height = 200;
windowX.alignChildren = ["center","center"];
windowX.spacing = 15;
windowX.margins = 16;
windowX.show();
// This is the key part
app.setTimeout(closeMe,delay);
app.setTimeout() has been suggested as a way of delaying code execution, which is what you need in this case (delaying of windowX.close()). Please note the author's comments (check the link) - app.setTimeout() has been made available from AE version CC 2015.

It can be done this way:
var windowX = new Window("palette");
windowX.orientation = "row";
windowX.preferredSize.width = 200;
windowX.preferredSize.height = 200;
windowX.alignChildren = ["center","center"];
windowX.spacing = 15;
windowX.margins = 16;
// var image1_imgString = "%C2%89PNG%0D%0A%1A..."
// var image1 = windowX.add("image", undefined, File.decode(image1_imgString), {name: "image1"});
windowX.show();
// here is the magic
windowX.update();
$.sleep(3000); // 3 seconds
windowX.hide();
windowX = null;
Based on the example from here: https://community.adobe.com/t5/illustrator-discussions/auto-close-alert-message/td-p/9398258

#Yuri ... windowX don't show before $.sleep (use instead var timerBreak...) - but only my Mac. Another Mac - your code works.
I write something like this:
//create windowX
var oneIdleTask = app.idleTasks.add({
name: "one_idle_task",
sleep: 1
}); // sleep not working here - write 3000 and nothing change
var onIdleEventListener = oneIdleTask.addEventListener(IdleEvent.ON_IDLE,
function() {
var oneIdleTaskName = "one_idle_task";
var oneIdleTask = app.idleTasks.itemByName(oneIdleTaskName);
if (oneIdleTask != null) {
oneIdleTask.remove();
$.sleep(3000) //<- write sleep here ... but deley is ok (for me) without this
windowX.hide();
}
}
);
windowX.show();

Related

Acrobat dynamic stamp popup window to reflect stamp comment

I am creating an application with an acrobat dynamic stamp pop up window and I would like it to reflect the stamp comment. My dynamic stamp has some JavaScript that will generate a pop-up window. The information on the pop-up window text field will become part of the stamp. I'm trying to add the contents of the pop-up window in two areas.
On the Dynamic stamp (done)
On the Stamp Comments (need help)
Below I added the JavaScript I currently have. If anyone here can help me find a solution, I'd really appreciate it.
var builder =
{
// These map to Text Fields in the Stamp
textBoxes :
[
{ field:"IsoNum", description:"Isometric Number:", default:function() { return Collab.user; } }
]
}
/*********** belongs to: AcroForm:Calculation:Calculate ***********/
// SEE GLOBAL JAVASCRIPT SECTION FOR CUSTOMIZATION
if (event.source.forReal)
{
var stampDialog = CreateDialog(builder);
app.execDialog(stampDialog);
for (var i = 0; i < builder.textBoxes.length; ++i)
{
var t = builder.textBoxes[i];
this.getField(t.field).value = stampDialog.textBoxResults[i];
}
}
function CreateDialog(dialogBuilder)
{
var sd = new Object();
sd.builder = dialogBuilder;
sd.textBoxResults = new Array();
var optionsElements = new Array();
for (var i = 0; i < dialogBuilder.textBoxes.length; ++i)
{
var view = new Object();
view.type = "view";
view.align_children = "align_row";
view.elements = new Array();
var t = dialogBuilder.textBoxes[i];
var s = new Object();
s.type = "static_text";
s.item_id = "sta" + i;
s.name = t.description;
s.width = 110;
var e = new Object();
e.type = "edit_text";
e.item_id = "edt" + i;
e.width = 150;
view.elements[0] = s;
view.elements[1] = e;
optionsElements[i] = view;
}
var optionsCluster =
{
type: "cluster",
name: "Options",
elements: optionsElements
};
sd.initialize = function(dialog)
{
var init = new Object();
for (var i = 0; i < this.builder.textBoxes.length; ++i)
{
var t = this.builder.textBoxes[i];
var id = "edt" + i;
init[id] = t.default();
}
dialog.load(init);
};
sd.commit = function(dialog)
{
var res = dialog.store();
for (var i = 0; i < this.builder.textBoxes.length; ++i)
{
var t = this.builder.textBoxes[i];
var id = "edt" + i;
this.textBoxResults[i] = res[id];
}
};
sd.description =
{
name: "Stamp Dialog",
elements:
[
{
type: "view",
align_children: "align_fill",
elements:
[
optionsCluster
]
},
{
type: "ok"
}
]
};
return sd;
}
I don't have any specific code but it seems you understand enough Acrobat JavaScript to understand my instructions.
The dialog code runs between the time you select and position the stamp and when the stamp actually gets created. For that reason, you can't set the contents of the note directly in your code because the stamp annotation doesn't actually exist until your commit function finishes. What you have to do instead is create a function that sets the contents of the note inside a timeOut and use a delay of about a half second.

JS - Get new element after click event

I'm working on a chrome extension to automate some work of mine. Currently it enters a value into a input, then clicks the button.
I want to get a new div element when it gets to the next page (once loaded). But it always looking a div before click event.
I hope that you understanded my problem.
Here is a code:
bSzukaj.onclick = function()
{
var url = "/game.php?screen=place";
var coords = [];
var loaded = false;
var n = inputZakres.value;
var x = parseInt(inputPobierz.value.split("|")[0] - parseInt(n/2+1));
var y = parseInt(inputPobierz.value.split("|")[1] - parseInt(n/2+1));
var newWindow = window.open(url);
var currentX = x;
var currentY = y;
var coord = currentX+"|"+currentY;
var sender = newWindow.addEventListener('load', function(){
var spearInput = newWindow.document.getElementById("unit_input_spear");
spearInput.value = 10;
var coordClass = newWindow.document.getElementsByClassName("target-input-field target-input-autocomplete")[0];
coordClass.value = coord;
var send = newWindow.document.getElementById("target_attack").click();
// NOW SCRIPT RELOAD PAGE AND CREATING SOME COMUNICATS
// AND I WANT TO GET THIS COMUNICATS TO VARIABLE
// BUT EVEN THIS ALERT BELOW DOESN'T WORK :/
newWindow.addEventListener('load', function() {
alert("now");
});
}, false);
//}
//}
}
}

Js function always return the same values

Js beginner here.
I have a function like this:
generateSteps: function() {
var stepsLength = this.data.steps.length;
var dataStepsInit = this.data.steps;
for (var i = 0; i < stepsLength; i++) {
var stepsItem = dataStepsInit[i].ITEM;
var arrayItem = this.animationNodes[stepsItem - 1];
var transition = this.animationParameters[i].transition;
var options = this.animationParameters[i].options;
var speed = this.animationParameters[i].speed;
var delay = this.animationParameters[i].delay;
arrayItem.delay(delay).show(transition, options, speed);
if (dataStepsInit[i].AUDIOID) {
var audioClass = dataStepsInit[i].AUDIOID;
var audioPlayer = this.template.find("audio." + audioClass);
setTimeout(playAudioOnDelay,delay);
};
var playAudioOnDelay = function() {
audioPlayer[0].pause();
audioPlayer[0].currentTime = 0;
audioPlayer[0].play();
};
}
}
What it does is generate data from JSON and display animated elements one by one on delay. Animation part work fine. I can assign required animations and delay to DOM elements and show them in right order.
But what I want to do in the same time is also to play an audio on delay (so I use setTimeout). Everything is almost fine, I play audio in right time (correct delay value) but I always play the same audio (which is last element) because audioPlayer always is the same DOM node.
I think this have something to do with this or I mixed a scope?
Try this:
generateSteps: function() {
var stepsLength = this.data.steps.length;
var dataStepsInit = this.data.steps;
for (var i = 0; i < stepsLength; i++) {
var stepsItem = dataStepsInit[i].ITEM;
var arrayItem = this.animationNodes[stepsItem - 1];
var transition = this.animationParameters[i].transition;
var options = this.animationParameters[i].options;
var speed = this.animationParameters[i].speed;
var delay = this.animationParameters[i].delay;
arrayItem.delay(delay).show(transition, options, speed);
if (dataStepsInit[i].AUDIOID) {
var audioClass = dataStepsInit[i].AUDIOID;
var audioPlayer = this.template.find("audio." + audioClass);
setTimeout(playAudioOnDelay(audioPlayer),delay);
};
}
function playAudioOnDelay(audioPlayer){
return function(){
audioPlayer[0].pause();
audioPlayer[0].currentTime = 0;
audioPlayer[0].play();
}
}
}
Essentially, your problem looks like this: http://jsfiddle.net/po0rLnwo/
The solution is : http://jsfiddle.net/gpfuo1s8/
Check the console in your browser.

Animate XML data in Flash with Actionscript 3

I have a question about getting a specific animation added to some xml data I'm pulling. I need some advice on how to make the data move from left to right or vise versa.Just for example I downloaded a rss feed from BBC world news, so it's just an xml file. Both the flash and xml are saved in the same folder and I can get in flash and display the data. Here's are the code so far:
import flash.text.TextField;
import flash.sampler.StackFrame;
import flash.display.MovieClip;
var yPlacement:int = 20;
var xPlacement:int = 30;
var distance:int = 60;
var loader:URLLoader = new URLLoader();
loader.load(new URLRequest("bbc-worldnews-rss.xml"));
loader.addEventListener(Event.COMPLETE, handleComplete);
function handleComplete(event:Event):void
{
var rawXML:XML = new XML(loader.data);
rawXML.ignoreWhite = true;
//trace(rawXML.channel.image.url);
var items:XMLList = rawXML.channel.item;
//trace("Total new items", items.length());
for each (var item:XML in items)
{
//trace(item.title);
var feedTitle:String = item.title.toString();
var myText:TextField = new TextField();
myText.text = feedTitle;
myText.autoSize = TextFieldAutoSize.LEFT;
myText.x = 2;
myText.y = 2;
var clip_mc = new MovieClip();
clip_mc.addChild(myText);
addChild(clip_mc);
clip_mc.y = yPlacement;
clip_mc.x = xPlacement;
yPlacement = yPlacement + distance;
}
//trace("First item title:", item[0].title);
}
I also know the code that makes text move side to side but I don't know how to incorporate it my codes above:
onClipEvent ( load ) {
startPoint = 1280; //this is where the clip will start
endPoint = -1080; //this is where the clip will end, and restart to the startPoint.
speed = 5; //this is how many pixels the text will move each frame.
}
onClipEvent ( enterFrame ) {
this._x -= speed; //you are telling the MC to move to the left 5 pixels each frame.
if (this._x <= endPoint ) { //if your clip goes beyond the end point.
this._x = startPoint; //go back to the starting point.
}
}
I hope I'm not confusing anyone, I just need to get the data I get from xml file to move side to side... I may be complete off course but I would GREATLY appreciate anyone's help!
Thank you,
For starters, the second snippet of code you posted is actually ActionScript 2, not 3.
You'd need to update that snippet to AS3 in order for this to work. Try something like this:
var startPoint:int = 1280;
var endPoint:int = -1080;
var speed:int = 5;
function moveMC(mc:MovieClip):void {
mc.addEventListener(Event.ENTER_FRAME, tick);
}
function tick(e:Event):void {
e.currentTarget.x -= speed;
if (e.currentTarget.x <= endPoint) {
e.currentTarget.x = startPoint;
}
}
You could then call moveMC() after you've added your newly created MovieClip to the stage.
Edit: You can use that snippet right in your for each loop like this:
for each (var item:XML in items)
{
//trace(item.title);
var feedTitle:String = item.title.toString();
var myText:TextField = new TextField();
myText.text = feedTitle;
myText.autoSize = TextFieldAutoSize.LEFT;
myText.x = 2;
myText.y = 2;
var clip_mc = new MovieClip();
clip_mc.addChild(myText);
addChild(clip_mc);
clip_mc.y = yPlacement;
clip_mc.x = xPlacement;
yPlacement = yPlacement + distance;
//takes in reference to MovieClip, start point, end point and speed
moveMC(clip_mc, 1280, -1080, 5);
}
function moveMC(mc:MovieClip, startPoint:int, endPoint:int, speed:int):void {
mc.startPoint = startPoint;
mc.endPoint = endPoint;
mc.speed = speed;
mc.addEventListener(Event.ENTER_FRAME, tick);
}
function tick(e:Event):void {
var mc:MovieClip = e.currentTarget as MovieClip;
mc.x -= mc.speed;
if (mc.x <= mc.endPoint) {
mc.x = mc.startPoint;
}
}

Adding a counter to a prev/next image slideshow(javascript/css only)?

I have created a "prev/next" slideshow using javascript, now I want to add a counter(1/10, 2/10, 3/10...) beside my "prev/next" buttons but nothing seemed to work.
This is my first time attempting to make a website, I know nothing about jQuery, so please stick with html+javascript if possible. Here is my script
var image = new Array(
"http://i990.photobucket.com/albums/af24/callmeaaaaj/AJ/_MG_7747.jpg",
"http://i990.photobucket.com/albums/af24/callmeaaaaj/AJ/1109163s.jpg")
var imgNumber=1
var numberOfImg=2
function previousImage(){
if(imgNumber>1){
imgNumber--
}
else{
imgNumber = numberOfImg
}
document.slideImage.src = image[imgNumber-1]
}
function nextImage(){
if(imgNumber < numberOfImg){
imgNumber++
}
else{
imgNumber = 1
}
document.slideImage.src = image[imgNumber-1]
}
if(document.images){
var image1 = new Image()
image1.src = "http://i990.photobucket.com/albums/af24/callmeaaaaj/AJ/_MG_7747.jpg"
var image2 = new Image()
image2.src = "http://i990.photobucket.com/albums/af24/callmeaaaaj/AJ/1109163s.jpg"
}
Script+html: http://jsfiddle.net/nLHY9/5/
(Prev/Next buttons seem not to be working on this----they work fine when I launched them from laptop to browser.)
you could have used some existing javascript image sliders, for example, sliderman slider, for your current code, you can do like, add an element like span, to hold the count, and you could add a function like:
function changeCounter(cur, total) {
document.getElementById("counter").innerHTML = cur + "/" + total;
}
and call it in your previousImage() and nextImage() functions, as in this demo jsfiddle
There are many pure css slideshows that are beautiful and can do impressive things. However, as you try to support older browsers, the pure css slideshows get less and less impressive or even impossible. JavaScript is the most flexible and powerful way to go. That being, I wanted to help you clean up your code. I only had a few minutes, so this is a quickly thrown together plugin, but it should get you on the right track.
First, a few notes on your code:
//you're missing semicolons everywhere. ";"
/* "var image" is very unclear.
* it's an array, so it should be plural "images"
* there aren't images in this array - it's image urls or sources
* instead of "new Array" you could just use "[]"
*/
var image = new Array(
"http://i990.photobucket.com/albums/af24/callmeaaaaj/AJ/_MG_7747.jpg",
"http://i990.photobucket.com/albums/af24/callmeaaaaj/AJ/1109163s.jpg")
var imgNumber=1 //the name doesn't mean anything. I have to assume that you mean "currentImgNumber" or something to that effect
var numberOfImg=2 //this could be determined by checking the length of your array - myArray.length
And here's my exampe plugin:
Live demo here (click).
/***** This section is how you use the plugin. I start writing with the usage and then I make it mean something *****/
window.onload = function() { //when the page is loaded
var fooElem = document.getElementById('foo'); //get an element where we will attach the plugin
var foo = Object.create(slideshow); //create a new slideshow object
foo.create({ //create a slideshow with the given options
element: fooElem, //the element where the slideshow will be
sources: [ //image urls
"http://i990.photobucket.com/albums/af24/callmeaaaaj/AJ/_MG_7747.jpg",
"http://i990.photobucket.com/albums/af24/callmeaaaaj/AJ/1109163s.jpg"
]
});
//we can make more of these and with different options
var barElem = document.getElementById('bar');
var bar = Object.create(slideshow);
bar.create({
element: barElem,
sources: [
"http://eggboss.com/wp-content/uploads/2013/09/The-Gentleman-233x300.png",
"http://fc07.deviantart.net/fs71/f/2013/040/8/a/profile_picture_by_classy_like_a_sir-d5uf426.jpg"
]
});
};
/**** now let's create the plugin and make it work as it is used above *****/
var slideshow = {
currentIndex: 0,
imgs: [],
create: function(options) {
options.element.className+= ' slideshow'; //add a class to the main element for styling
this.imgs = this.getImgs(options.sources); //make img html
var controls = this.getControls(); //make controls
//add the html to the element from the options
var frag = document.createDocumentFragment();
this.imgs.forEach(function(img) {
frag.appendChild(img);
});
frag.appendChild(controls);
options.element.appendChild(frag);
},
getImgs: function(sources) {
var imgs = [];
sources.forEach(function(src, i) {
var img = document.createElement('img');
img.src = src;
imgs.push(img);
if (i > 0) {
img.style.display = 'none'; //hide all but first image
}
});
return imgs;
},
getControls: function() {
var that = this; //so that we can access "this" within the click functions
var controls = document.createElement('div');
controls.className = 'controls';
var counter = document.createElement('span');
counter.className = 'counter';
this.setCounter(counter);
var prev = document.createElement('a');
prev.textContent = 'Prev';
prev.className = 'prev';
prev.addEventListener('click', function() {
newIndex = (that.currentIndex) ? that.currentIndex-1 : that.imgs.length-1;
that.changeImg(newIndex, counter);
});
var next = document.createElement('a');
next.textContent = 'Next';
next.className = 'next';
next.addEventListener('click', function() {
newIndex = (that.currentIndex !== that.imgs.length-1) ? that.currentIndex+1 : 0;
that.changeImg(newIndex, counter);
});
controls.appendChild(prev);
controls.appendChild(next);
controls.appendChild(counter);
return controls;
},
changeImg: function(newIndex, counter) {
this.imgs[this.currentIndex].style.display = 'none';
this.imgs[newIndex].style.display = 'inline';
this.currentIndex = newIndex;
this.setCounter(counter);
},
setCounter: function(counter) {
counter.textContent = (this.currentIndex+1)+' / '+this.imgs.length;
}
};

Categories