#targetengine "session"
#target indesign
function SnpCreateSlider () {
this.windowRef = null;
}
SnpCreateSlider.prototype.run = function() {
var retval = true;
// Create a palette-type window (a modeless or floating dialog),
var win = new Window("palette", "SnpCreateSlider", [150, 150, 600, 300]);
this.windowRef = win;
// Add a panel to contain the components
win.pnl = win.add("panel", [10, 10, 440, 100], "Move slider around");
// Add some labels that describe the state of the slider
win.pnl.minLbl = win.pnl.add("statictext", [10, 47, 35, 60], "-180");
win.pnl.curLbl = win.pnl.add("statictext", [121, 47, 170, 60], "0");
win.pnl.maxLbl = win.pnl.add("statictext", [210, 47, 250, 60], "180");
win.pnl.displayTextLbl = win.pnl.add("statictext", [290, 20, 380, 40], "Current value:");
win.pnl.displayLbl = win.pnl.add("statictext", [385, 20, 425, 40], "0");
// Add a slider control
win.pnl.sliderCtrl = win.pnl.add("slider", [20, 20, 230, 45], 0, -180, 180);
// Add buttons
win.doneButton = win.add("button",[320, 110, 420, 140] , "Close");
// Define behavior for when the slider value changes
win.pnl.sliderCtrl.onChanging = function() {
var val = Math.round(win.pnl.sliderCtrl.value);
// Update the label text with the current slider value.
win.pnl.displayLbl.text = val;
};
// Define behavior for when the slider is released
win.pnl.sliderCtrl.onChange = function() {
var val = Math.round(win.pnl.sliderCtrl.value);
rotateIt(val);
};
// Define behavior for the "Exit" button
win.doneButton.onClick = function () {
win.close();
};
// Display the window
win.center();
win.show();
return retval;
}
function checkSelection() {
if (app.documents.length == 0 || app.selection.length == 0) {
alert("Please select an object."); return false;
}
return true;
}
function rotateIt(Angle) {
if (!checkSelection()) return;
var myItems = app.selection;
var myAnchor = app.layoutWindows[0].transformReferencePoint;
for (var j = myItems.length - 1; j >= 0; j--) {
var myItem = myItems[j];
var myTransformationMatrix = app.transformationMatrices.add();
var itemAngle = myItem.rotationAngle;
myTransformationMatrix = myTransformationMatrix.rotateMatrix(Angle-itemAngle);
myItem.transform(CoordinateSpaces.pasteboardCoordinates, myAnchor, myTransformationMatrix);
}
}
/**
"main program": construct an anonymous instance and run it
as long as we are not unit-testing this snippet.
*/
if(typeof(SnpCreateSlider_unitTest) == "undefined") {
new SnpCreateSlider().run();
}