Using jqueryUI’s blur and focus to hide on mouseout

As you probably already know, jquery UI triggers an focus and blur event for each element of the menu so it’s a bit tricky to hide the hole menu for example when the mouse hovers out. Still there’s a workaround:

                        $('.menu_dropdown').click(function() {
		    	    var self = this;
		    	    var test_timer = null;
	    		    $(this).next('ul').menu({ 
		    		    position: { my: "left top", at: "right-5 top+5" },
		    		    create: function( event, ui ) { $(this).position({my: "left top", at: "left bottom", of: $(self)}); },
		    		    select: function( event, ui) { $(this).menu('destroy'); $(this).css('display',''); $.removeData(this,'uiMenu'); },
		    		    blur: function(event, ui) {  test_timer = setInterval(function() { $(self).next('ul').menu('destroy'); $(self).next('ul').css('display',''); $.removeData($(self).next('ul'),'uiMenu'); clearInterval(test_timer); }, 500); },
		    		    focus: function(event, ui) { clearInterval(test_timer); }
		    		});
	    	   });

or you can use the hiding method presented here.

New jquery UI destroy menu not quite working

Well jquery 1.9 is here and so is the version 1.10 of the popular jquery UI. It has some nice additions like menus, tooltips, menu bars and so on. However the menu seems a little bit tricky to use when using an element to trigger it.

let’s have this example:

      some actions
      

ok now the style:

   .themenu { display: none }

and finally the javascript:

                    $('.menu-expander').click(function() {
		    	    var self = this;
	    		    $(this).next('ul').menu({ 
		    		    position: { my: "left top", at: "right-5 top+5" },
		    		    create: function( event, ui ) { $(this).position({my: "left top", at: "left bottom", of: $(self)}); },
		    		    select: function( event, ui) { $(this).menu('destroy'); $(this).css('display',''); $.removeData(this,'uiMenu'); },
		    		    blur: function() {}
		    		});
	    	   });

Calling the destroy will leave the menu object intact in the element’s data array under the name “uiMenu”. So destroying it takes the 3 steps shown in select method above.
You could also just hide it on select using this:

     $('.menu-expander').click(function() {
		    	    var self = this;
                            var mn = $(this).next('ul');
                            if(mn.data('uiMenu') != null) mn.show();
                            else 
	    		        $(this).next('ul').menu({ 
		    		    position: { my: "left top", at: "right-5 top+5" },
		    		    create: function( event, ui ) { $(this).position({my: "left top", at: "left bottom", of: $(self)}); },
		    		    select: function( event, ui) { $(this).hide(); },
		    		    blur: function() {}
		    	        });
	    	   });

[rb] Removing textframe linkage with applescript

You may sometimes need to be able to remove linkage between text frames in a particular document in Indesign. this script might come to the rescue:

tell application "Adobe InDesign CS2"
	set theObjs to selection
	
	if theObjs is equal to {} then
		set theObjs to every text frame of document 1
	end if
	tell document 1 to set thebaseframe to make new text frame
	
	
	repeat with tos in theObjs
		if (class of tos as string) = "text frame" then
			if end text frame of tos is not tos then
				set next text frame of tos to next text frame of thebaseframe
				set previous text frame of tos to previous text frame of thebaseframe
				set autoflow thread orphaned of tos to true
			end if
		end if
	end repeat
	tell document 1 to delete thebaseframe
end tell

Extending illustrator capabilities with applescript

While Illustrator offers a range of selection options that most of the time are enough for a particular scope, you might sometimes need to deal with a lot of stuff that come from other programs. This tiny script scrap might  come to the rescue in many occasions:

tell application "Adobe Illustrator"
	set sel to selection
	set target to item 1 of sel
	set cls to class of target
	
	set objs to every page item of document 1
	
	repeat with o in objs
		if (class of o is equal to cls) then
			set selected of o to true
		end if
	end repeat
	
end tell

Getting content from a signed pdf document

While most of the time the person that adds a signature for the document, disabling the editing of that document has good reasons for doing so, you sometimes might need to get that content to make some changes. For that you’ll need Acrobat Professional and OSX (tested on 10.4 … might work on 10.5 too):

First step: Open you pdf document with Preview and select the “Select tool” and select the part of the document that you need to edit and copy it.

Second step: Create a new document, hit paste and save it.
Note: at this point the document is editable but the fonts might come as garbage. However you can use the next steps to overcome that.

The next steps are only for flattening/outlining fonts.

Third step: Open the newly created document with Acrobat Professional and add a background to the document from Document -> Background – > Add and set the Opacity to 0(this is needed most of the time if you want to flatten the document).

Fourth step: Flatten the document from Advanced -> Print Production -> Flattener preview (check Convert all text to outlines if you want the fonts to be outlined) and save the document.

This should be it … now you should have an unlocked and working file.

[rb] Load all forms/links within tabs in the same place with jquery

One of the things that probably most of the people stumbled upon while working with jquery tabs is reloading the content of a form submit/link within the same window/tab window. That’s pretty simple to achieve with the following code:

//this one will work for forms
$("#tabs form").live( 'submit' , function() {
		var self = this;
		$.ajax({
		  type: (!$(this).attr('method') ? 'post' : $(this).attr('method')),
		  url: $(this).attr('action'),
		  data: $(this).serialize(),
		  success: function(data) { $('.ui-tabs-panel:visible').html(data); }	 
		});
		return false;
	});
//this one will work for links
$("#tabs > div a").live( 'click' , function() {
		var self = this;
		$.ajax({
		  type: 'get',
		  url: $(this).attr('href'),
		  success: function(response) { $('.ui-tabs-panel:visible').html(response); }	 
		});
		return false;
});

While there might be some other implementations with a smoother code, this will do what is supposed to …

Remove unnecessary shape points in Illustrator

Did you ever got annoyed by those extra points in illustrator? This is something that might help …

var Geometry2DHelper = {
	getSlope: function(pt1, pt2){
		var i1 = pt1.anchor[1] - pt2.anchor[1];
		var i2 = pt1.anchor[0] - pt2.anchor[0];
		var slope = (i2 == 0) ? null : i1/i2;
		return (slope == 0) ? 0 : slope;
	},
	getConstructionPoints: function(path) {
		var pts = path.pathPoints;
		var ctspts = "";
		var x = 0;
		if(pts.length < 3) return [];
		for(i = pts.length - 1; i>=0;i--) {
			var pt1 = (i == pts.length - 1) ? pts[0] : pts[i + 1];
			var pt2 = (i == 0) ? pts[pts.length - 1] : pts[i - 1];
			var slope = (this.getSlope(pts[i], pt1)!=null) ? this.getSlope(pts[i], pt1).toFixed(2) : null;
			var slope2 = (this.getSlope(pts[i], pt2)!=null) ? this.getSlope(pts[i], pt2).toFixed(2) : null;
			if(slope != slope2) ctspts += "|" + i + "|";
		}
		return ctspts;
	},
	remove: function(path, whitelist) {
		alert(whitelist);
		var pts = path.pathPoints;
		if(whitelist=="") {
			for(i = pts.length - 1; i>= 0; i--) {
				if(i != pts.length - 1 && i!= 0) {pts[i].remove(); continue;}
			}
			return;
		}		
		for(i = pts.length - 1; i>= 0; i--) {
			if(whitelist.indexOf("|" + i + "|") < 0) {pts[i].remove(); }
		}
	},
	isVertical: function(pt1, pt2) {
        if(pt1.anchor[0].toFixed(1) == pt2.anchor[0].toFixed(1)) return true;
        return false;
    },
    isHorizontal: function(pt1, pt2) {
        if(pt1.anchor[1].toFixed(1) == pt2.anchor[1].toFixed(1)) return true;
        return false;
    }
}
for(j = app.activeDocument.pathItems.length - 1; j >= 0; j--) {
    var x = Geometry2DHelper.getConstructionPoints(app.activeDocument.pathItems[j]);
    //alert(x);
    Geometry2DHelper.remove(app.activeDocument.pageItems[j], x);  
}

Replace selected image with another in Indesign

Ever needed to change a bunch of picture from one document with another in Indesign? This script does just that …

function indexOf(array, elem) {
	for(j= 0; j < array.length; j++) {
				if(array[j] ==elem) return true;
		}
		return false;
}

var rFile;

if(app.documents.length > 0){
var myDoc = app.activeDocument;
var docLinks = myDoc.links;
var myDialog = app.dialogs.add({name:"Parameters:", canCancel:true});
with(myDialog){
with(dialogColumns.add( {})){
with(borderPanels.add()){
with(dialogColumns.add()){
staticTexts.add({staticLabel:"Replace image:"});
}
with(dialogColumns.add()){

var mDrop  = dropdowns.add({ stringList:GetLinks(docLinks), selectedIndex: 0});
}

}
}
}
if(myDialog.show() == true ) {
rFile = File.openDialog ("Replacement file:");
} else {
myDialog.destroy();
exit();
}
} else {
alert("There is no opened document.");
}


function GetLinks(lks) {
	var lA = new Array();
	var lAi = 0 ;
	for(i=0; i < lks.length; i++){
		if(indexOf(lA, lks[i].name) == false)  { lA[lAi] = lks[i].name; lAi++; }
	}
	return lA;
}
var imgName = myDoc.links.item(mDrop.stringList[mDrop.selectedIndex]).name;

var vLinks = myDoc.links;
var o = 0;
for(i=vLinks.length-1; i >= 0; i--){
	if(vLinks[i].name == imgName){
		vLinks[i].relink(rFile);		
	}
}
for(i=vLinks.length-1; i >= 0; --i){
		if(vLinks[i].status ==  LinkStatus.LINK_OUT_OF_DATE) vLinks[i].update();	
}

Resize all items in selection to the desired size

Let’s say you have a dozen circles that you want to resize from 2mm to 3mm … this script will help you do just that:

doc = app.activeDocument;
var sSize = prompt("Resize to how many millimeters?", "3", "Square size?");
var _s = (parseInt(sSize) == 'NaN') ? 0 : sSize;
var _w = new UnitValue(_s, "mm").as("pt");
var _h = new UnitValue(_s, "mm").as("pt");

if(doc.selection.length == 0) {
	for(i = 0; i < doc.pathItems.length; i++) {
		var x = Number((_w*100)/doc.pathItems[i].width);
		var y = Number((_h*100)/doc.pathItems[i].height);
		doc.pathItems[i].resize(x,y,true,true,true,true, 100, Transformation.CENTER);
	}
} else {
	for(i = 0; i < doc.selection.length; i++) {
		var x = Number((_w*100)/doc.selection[i].width);
		var y = Number((_h*100)/doc.selection[i].height);
		doc.selection[i].resize(x,y,true,true,true,true, 100, Transformation.CENTER);
	}
}