Showing posts with label Javascript. Show all posts
Showing posts with label Javascript. Show all posts

Wednesday, 4 April 2012

Illustrator - Automate export of objects to PNG files

Automate export of illustrator objects to individual PNG files.

Save the following script into a new js file.
Open you illustrator file, then goto File > Scripts > Other Scripts or hit F12


var msg =""
if(app.documents.length > 0)
{
var pgItems = app.activeDocument.pageItems;
tot_obj=pgItems.length ;
alert("Total Object are " + tot_obj);
if( pgItems.length > 0 )
{
  var msg = "Items are ";

  for( var i =0; i
  {
 
   pgItems[i].hidden =true;
   //msg   = pgItems[i].visible
  }
for( var i =0; i
  {
   pgItems[i].hidden =false;
   var exportOptions = new ExportOptionsPNG24();
   var type = ExportType.PNG24;
   var fileSpec = new File(i+"sample.png");
   exportOptions.antiAliasing = false;
   exportOptions.transparency = true;
   exportOptions.saveAsHTML = false;
   app.activeDocument.exportFile( fileSpec, type, exportOptions );
   pgItems[i].hidden =true;

  }
}
else
{
  msg = "No document Open";
}
alert(msg);
}

Thursday, 11 November 2010

Bookmarklets: List of javascript bookmarklets

ASTEROIDS!!!
Play asteroids on any webage.

javascript:var%20s%20=%20document.createElement('script');s.type='text/javascript';document.body.appendChild(s);s.src='http://erkie.github.com/asteroids.min.js';void(0);

SPRITE ME
Generates sprite image from any website.

javascript:(function(){spritemejs=document.createElement('SCRIPT');spritemejs.type='text/javascript';spritemejs.src='http://spriteme.org/spriteme.js';document.getElementsByTagName('head')[0].appendChild(spritemejs);})();

Thursday, 1 October 2009

Javascript: Prevent editing in file input fields

add the following properties:

oncontextmenu='return false' onkeydown='this.blur()'

Wednesday, 11 March 2009

Javascript: A list of Javascript Framework

Thought I'll compile a list of common javascript framework/libraries that i've come across:
List will be built up gradually.

jQuery - http://jquery.com/
prototype - http://www.prototypejs.org/
mootools - http://mootools.net/
moofx - http://moofx.mad4milk.net/
ExtJS - http://extjs.com/
script.aculo.us - http://script.aculo.us/

Tuesday, 17 February 2009

Javascript: Bubble Sorting

Found an interesting article and compact js file to handle dynamic sorting in tables.

Very cool and works flawlessly.

http://www.the-art-of-web.com/javascript/oopsort/

Friday, 21 November 2008

Javascript: Find query in page

A simple search for string within a webpage, similar to CTRL+F.

HTML



<form name="form1" onsubmit="search(document.form1, frametosearch); return false">
<input name="findthis" size="15" title="Press 'ALT s' after clicking submit to repeatedly search page" type="text">
<input class="searchbtn" value="Find" accesskey="s" type="submit">
</form>


JavaScript



/******************************************
* Find In Page Script -- Submitted/revised by Alan Koontz
* Visit Dynamic Drive (http://www.dynamicdrive.com/) for full source code
* This notice must stay intact for use
******************************************/

// revised by Alan Koontz -- May 2003

var TRange = null;
var dupeRange = null;
var TestRange = null;
var win = null;


// SELECTED BROWSER SNIFFER COMPONENTS DOCUMENTED AT
// http://www.mozilla.org/docs/web-developer/sniffer/browser_type.html

var nom = navigator.appName.toLowerCase();
var agt = navigator.userAgent.toLowerCase();
var is_major = parseInt(navigator.appVersion);
var is_minor = parseFloat(navigator.appVersion);
var is_ie = (agt.indexOf("msie") != -1);
var is_ie4up = (is_ie && (is_major >= 4));
var is_not_moz = (agt.indexOf('netscape')!=-1)
var is_nav = (nom.indexOf('netscape')!=-1);
var is_nav4 = (is_nav && (is_major == 4));
var is_mac = (agt.indexOf("mac")!=-1);
var is_gecko = (agt.indexOf('gecko') != -1);
var is_opera = (agt.indexOf("opera") != -1);


// GECKO REVISION

var is_rev=0
if (is_gecko) {
temp = agt.split("rv:")
is_rev = parseFloat(temp[1])
}


// USE THE FOLLOWING VARIABLE TO CONFIGURE FRAMES TO SEARCH
// (SELF OR CHILD FRAME)

// If you want to search another frame, change from "self" to
// the name of the target frame:
// e.g., var frametosearch = 'main'

//var frametosearch = 'main';
var frametosearch = self;


function search(whichform, whichframe) {

// TEST FOR IE5 FOR MAC (NO DOCUMENTATION)

if (is_ie4up && is_mac) return;

// TEST FOR NAV 6 (NO DOCUMENTATION)

if (is_gecko && (is_rev <1)) str =" whichform.findthis.value;" win =" whichframe;" frameval="false;" frameval="true;" win =" parent.frames[whichframe];" strfound="win.find(str);" strfound="win.find(str,">= 1)) {

if(frameval!=false) win.focus(); // force search in specified child frame
strFound=win.find(str, false, false, true, false, frameval, false);

// The following statement enables reversion of focus
// back to the search box after each search event
// allowing the user to press the ENTER key instead
// of clicking the search button to continue search.
// Note: tends to be buggy in Mozilla as of 1.3.1
// (see www.mozilla.org) so is excluded from users
// of that browser.

if (is_not_moz) whichform.findthis.focus();

// There are 7 arguments available:
// searchString: type string and it's the item to be searched
// caseSensitive: boolean -- is search case sensitive?
// backwards: boolean --should we also search backwards?
// wrapAround: boolean -- should we wrap the search?
// wholeWord: boolean: should we search only for whole words
// searchInFrames: boolean -- should we search in frames?
// showDialog: boolean -- should we show the Find Dialog?


}

if (is_ie4up) {

// EXPLORER-SPECIFIC CODE revised 5/21/03

if (TRange!=null) {

TestRange=win.document.body.createTextRange();



if (dupeRange.inRange(TestRange)) {

TRange.collapse(false);
strFound=TRange.findText(str);
if (strFound) {
//the following line added by Mike and Susan Keenan, 7 June 2003
win.document.body.scrollTop = win.document.body.scrollTop + TRange.offsetTop;
TRange.select();
}


}

else {

TRange=win.document.body.createTextRange();
TRange.collapse(false);
strFound=TRange.findText(str);
if (strFound) {
//the following line added by Mike and Susan Keenan, 7 June 2003
win.document.body.scrollTop = TRange.offsetTop;
TRange.select();
}



}
}

if (TRange==null || strFound==0) {
TRange=win.document.body.createTextRange();
dupeRange = TRange.duplicate();
strFound=TRange.findText(str);
if (strFound) {
//the following line added by Mike and Susan Keenan, 7 June 2003
win.document.body.scrollTop = TRange.offsetTop;
TRange.select();
}


}

}

if (!strFound) alert ("String '"+str+"' not found!") // string not found


}

Javascript: getElementsByClassName


/*
Written by Jonathan Snook, http://www.snook.ca/jonathan
Add-ons by Robert Nyman, http://www.robertnyman.com
*/
function getElementsByClassName(oElm, strTagName, oClassNames){
var arrElements = (strTagName == "*" && oElm.all)? oElm.all : oElm.getElementsByTagName(strTagName);
var arrReturnElements = new Array();
var arrRegExpClassNames = new Array();
if(typeof oClassNames == "object"){
for(var i=0; i<oClassNames.length; i++){
arrRegExpClassNames.push(new RegExp("(^|\\s)" + oClassNames[i].replace(/\-/g, "\\-") + "(\\s|$)"));
}
}
else{
arrRegExpClassNames.push(new RegExp("(^|\\s)" + oClassNames.replace(/\-/g, "\\-") + "(\\s|$)"));
}
var oElement;
var bMatchesAll;
for(var j=0; j<arrElements.length; j++){
oElement = arrElements[j];
bMatchesAll = true;
for(var k=0; k<arrRegExpClassNames.length; k++){
if(!arrRegExpClassNames[k].test(oElement.className)){
bMatchesAll = false;
break;
}
}
if(bMatchesAll){
arrReturnElements.push(oElement);
}
}
return (arrReturnElements)
}

Tuesday, 8 July 2008

Javascript: Maximize and Minimize

<SCRIPT LANGUAGE="JavaScript">

function Minimize()
{
window.innerWidth = 100;
window.innerHeight = 100;
window.screenX = screen.width;
window.screenY = screen.height;
alwaysLowered = true;
}

function Maximize()
{
window.innerWidth = screen.width;
window.innerHeight = screen.height;
window.screenX = 0;
window.screenY = 0;
alwaysLowered = false;
}
</SCRIPT>

<A HREF="javascript:onClick=Minimize()">Minimize</A>
<A HREF="javascript:onClick=Maximize()">Maximize</A> 

<html>
<head>
<title>Maximize Your Potential</title>
<script>
function maximize() {
  window.moveTo(0, 0);
  window.resizeTo(screen.width, screen.height);
}
maximize();
</script>
</head>
<body>
<h1 align="center">Maximize Your Potential</h1>
This page is self-maximizing.
</body>
</html>

function openWindowMax(location) {
sizeX = screen.width
sizeY = screen.height-50
var posx = (screen.availWidth-sizeX)/2;
var posy = (screen.availHeight-sizeY)/2;
var windowString = 'toolbar=no,location=no,menubar=no,status=no,resizable=no,directories=no,scrollbars=yes,copyhistory=no,width='+sizeX+',height='+sizeY+',left='+posx+',top='+posy+',screenX='+posx+',screenY='+posy;
newWindow = window.open(location, "", windowString);
newWindow.moveTo(0,0);
}

Monday, 23 June 2008

Javascript: Validate file extension when uploading files

/*check file extension*/
function CheckFileExtension(obj){
val=obj.value.substring(obj.value.length-4,obj.value.length);
  if (val!='.jpg'&&val!='.gif'&&val!='.bmp'&&val!='.png'&&val!='.jpeg'&&val!='.JPG'&&val!='.GIF'&&val!='.BMP'&&val!='.PNG'&&val!='.JPEG'){
   return false;
  }
}

Thursday, 29 May 2008

Javascript: Copy text to clipboard function

<SPAN ID="copytext" STYLE="height:150;width:162;background-color:pink">
This text will be copied onto the clipboard when you click the button below. Try it!
</SPAN>
<TEXTAREA ID="holdtext" STYLE="display:none;"></TEXTAREA>
<BUTTON onClick="ClipBoard();">Copy to Clipboard</BUTTON>

<SCRIPT LANGUAGE="JavaScript">

function ClipBoard()
{
holdtext.innerText = copytext.innerText;
Copied = holdtext.createTextRange();
Copied.execCommand("Copy");
}

</SCRIPT>

Extract description from site:

The script, as it is currently written, copies whatever text is within the SPAN tags. If there is code, like a
command created to display using & commands, those will copy right along. If you've got formatting in the text and you only want the user to copy the text, then you need to add a command that will remove that formatting. Luckily, there's an execCommand that will do that for you. It's important that you place it in the script before the copy process.

<SCRIPT LANGUAGE="JavaScript">

function ClipBoard()
{
holdtext.innerText = copytext.innerText;
Copied = holdtext.createTextRange();
Copied.execCommand("RemoveFormat");
Copied.execCommand("Copy");
}

</SCRIPT>

NOTE: due to mozillas tight security setting this script only works in IE.

Other variation

var x = document.getElementById("EncodedString").value;
window.clipboardData.setData('text', x);

Monday, 12 November 2007

HTML: Auto Adjust IFRAMEs

Auto Adjust IFRAME
------------------
<iframe name="ifr" id="ifr" src="whatever.html" onload="this.style.height 
= ifr.document.body.scrollHeight + 5"></iframe> 

OR

<iframe id="ifr" src="ifr.html">< /iframe>< br />
<input type="button" onclick="document.getElementById('ifr').style.height 
= ifr.document.body.scrollHeight + 5" value="Ajust" />

Wednesday, 15 August 2007

Javascript: Replacing OnLoad attribute in Body tag

//This section runs the SetPage function when the form loads - replaces OnLoad function in body tag
addLoadEvent(SetPage);
function addLoadEvent(func) {   
   var oldonload = window.onload;   
   if (typeof window.onload != 'function') {   
     window.onload = func;   
   } else {   
     window.onload = function() {   
       oldonload();   
       func();   
     }   
  }   
}

//Another example will run when page load but code doesn't utilize onLoad attribute in body tag
var frm = document.frmCreateModifyPosition;
window.onload = function(){
if (frm.txtAction[1].checked){
ShowPositionID()
}
}