354 Lotus blogs updated hourly. Who will post next? Home | Downloads | Events | Pods | Blogs | Search | myPL | About 
 
Latest 7 Posts
An open letter to Mr. NotesIn9
Wed, Apr 2nd 2014 408
And the gloves are off……
Mon, Mar 31st 2014 308
When the community comes together we get the right answer
Sun, Mar 30th 2014 286
Why learning JavaScript is more critical to XPage developers than Java
Wed, Mar 26th 2014 696
PATCHing a Document using Domino Data Service
Mon, Mar 24th 2014 194
How to ad icons to individual items in a Select2 multi-value field
Tue, Mar 18th 2014 211
My ongoing struggle with stupidity and what is not valid JSON
Sun, Mar 16th 2014 178
Top 10
Why learning JavaScript is more critical to XPage developers than Java
Wed, Mar 26th 2014 696
An open letter to Mr. NotesIn9
Wed, Apr 2nd 2014 408
Arguably the most dangerous thing you could ever do in XPages – let other people use your eval() in their SSJS
Tue, Jun 18th 2013 397
Why using XPages Partial Refresh is sometimes easy for developers and bad for users
Tue, Mar 4th 2014 311
Going porn-mode on your browser
Fri, Jan 24th 2014 309
And the gloves are off……
Mon, Mar 31st 2014 308
Prototypal inheritance of SSJS across the whole server in XPages
Sun, Mar 2nd 2014 301
When the community comes together we get the right answer
Sun, Mar 30th 2014 286
EXTJS in XPages #14 – Grid editing and saving data via REST CRUD
Thu, Aug 1st 2013 278
Lowering your ODS – an oldie but goodie
Fri, Feb 7th 2014 267


jQuery in XPages #6 – watermark.js
MarkyRoden    

In this article I will demonstrate how to implement watermark.js by Patrick Wied. Using the power of HTML5 image manipulation we are able to add a watermark graphic to another image and determine position and opacity - even with a JPG!! Of course that means no IE but hey we’re looking forward not backward people!

Introduction

This week I am only going to use one article because this hopefully won’t be too long. I am also going to try and break the article down into a simpler format than before, highlighting the XPages techniques as well as the jQuery techniques. Thanks to David Leedy for the feedback on article format and content.

Demonstration

The effect is demonstrated here

Download

The demonstration database can be downloaded from the link above or from here

Opacity in images

JPEG has been the standard web format for many years and was fantastic when we were able to reduce the size of images to (good enough) over a slow connection. Nowadays though the need to have image capability is opacity. PNG files are now the go to image format for the web and like GIF they support an A(lpha) channel which allows for an opacity to be applied to the image directly.

watermark.js

Looping through all pixels in an image – using JavaScript!

watermark.js uses a new feature in HTML5 whereby each pixel of a graphic can be manipulated from JavaScript, including the addition of an alpha (opactiy) value. The original article by Patrick explains how some very simple loop code can be written to go through each pixel in an image and apply an opacity.

First we have to create a canvas element, add it to the document’s body, set the canvas size to the image size (we have a 500×200 img) and add the image to the canvas.

// get the image
var img = document.getElementById("your-image");
// create and customize the canvas
var canvas = document.createElement("canvas");
canvas.width = 500;
canvas.height = 200;
document.body.appendChild(canvas);
// get the context
var ctx = canvas.getContext("2d");
// draw the image into the canvas
ctx.drawImage(img, 0, 0);

“Ok this is the more interesting part of the solution. We have to access the image data, loop thru all pixels of the image and set the alpha values to the value of our choice. A pixel in the imagedata is represented by four values: red, green, blue, alpha (rgba) therefore we have to change every fourth value.”

// get the image data object
var image = ctx.getImageData(0, 0, 500, 200);
// get the image data values
var imageData = image.data,
length = imageData.length;
// set every fourth value to 50
for(var i=3; i < length; i+=4){
    imageData[i] = 50;
}
// after the manipulation, reset the data
image.data = imageData;
// and put the imagedata back to the canvas
ctx.putImageData(image, 0, 0);

And here’s what we are going to build – an image with another opaque image surfaced on top of is as a watermark.

Our watermarked image

Our watermarked image

The watermark custom control

We are going to build an XPages watermark custom control whereby the developer can determine all the parameters of the effect through the custom properties of the control and therefore not have to change any of the underlying code.

There are 5 parameters which go with the jQuery plugin for watermark.js

  1. “className”: the class of the elements which should get a mark. (Optionally) Default: “watermark”
  2. “position”: “top-left”|”top-right”|”bottom-right”|”bottom-left”. (Optionally) Default: “bottom-right”
  3. “watermark”: an img element which represents your watermark. (Optionally)
  4. “path”: the path to your watermark image. (Optionally)
  5. “opacity”: opacity percentage, no “%” only the number [0-100] (Optionally) Default: 50

So we create the custom control in our database and under the “Property Definition” section we add our “properties”. Each property is a string except the position which is a combobox with pre-defined parameters.

Property Definition of a Custom Control

formWatermark Property Definitions

formWatermark Property Definitions

Entering custom properties to your custom control

And when we add the custom control to our XPage we are able to fill in the parameters for the control

Adding parameter values to our custom control in the XPage

Adding parameter values to our custom control in the XPage

Accessing the custom properties through the XPage

Accessing the custom properties through the XPage is achieved using compositeData.whateverParameterName. As you can see from the above example though not all the fields need to be filled in – so we need to compute their inclusion on the plugin instantiation.

This is the code used to create the effect. It must be added through and output script in the XPage because we need access to the Server Side variable computation which is not available through a Client Side library.

<xp:scriptBlock id="scriptBlock1">
		<xp:this.value><![CDATA[
		$(document).watermark({
			path: '#{compositeData.path}',
			className: '#{compositeData.className}',
			opacity: '#{compositeData.opacity}',
			position: '#{compositeData.position}',
			watermark: '#{compositeData.watermark}'
		});
		]]></xp:this.value>
	</xp:scriptBlock>

Watermark these images
Unless otherwise stated in the parameters the watermark.js effect is applied to all images with the class=”watermark”. Here are my images from the database.

	<xp:table style="width:100%" id="table1">
		<xp:tr>
			<xp:td style="width:50%">
				<xp:image url="/Nin9TV.jpg" id="image1" styleClass="watermark">
				</xp:image>
			</xp:td>
			<xp:td>
				<xp:image url="/xpages.jpg" id="image2" styleClass="watermark">
				</xp:image>
			</xp:td>
		</xp:tr>
	</xp:table>

Demonstration

The demonstration site shows a number of possibilities and allows the developer to change the variables and see the effect.

Demonstration of using watermark.js in an XPage

Demonstration of using watermark.js in an XPage




---------------------
http://xomino.com/2012/04/17/jquery-in-xpages-6-watermark-js/
Apr 17, 2012
33 hits



Recent Blog Posts
408


An open letter to Mr. NotesIn9
Wed, Apr 2nd 2014 6:33a   Mark Roden
Dear Mr Leedy, I regret to inform you that your blatant use of child labor has offended my child labor union. They do not feel like you have represented me in the correct light. I trust that you will find this short response in the same light as your original offense. yours faithfully, Your very good friend Marky Roden CC: everyone who has seen this video http://notesin9.com/index.php/2014/03/31/notesin9-141-java-vs-javascript-throwdown/ [read] Keywords: java javascript
308


And the gloves are off……
Mon, Mar 31st 2014 5:57p   Mark Roden
Picture this: I have been away for 5 days and during that time “someone” has been posting cryptic comments on twitter about how the next notesin9 is going to be different….and scaring me. So I am waiting at the airport this afternoon, about to board my plane home and I get this link from this “friend” who tells me to watch the new video it and enjoy. I download it and watch it on the plane. People start to look at me funny as I start to snort and giggle at my phone. [read] Keywords: ibm xpages application integration javascript twitter
286


When the community comes together we get the right answer
Sun, Mar 30th 2014 12:41p   Mark Roden
Last week I posted why JavaScript is more critical a skill to learn than Java. There was an outpouring of comments, discussion and responses unlike any I have seen in a while. To give a little more background as to why I decided to post: I was not to be antagonistic or instigate a storm in a tea cup. It was because for the third time in 2014 I had been told by a notes developer something along the lines of “I can’t learn XPages because I have read that you need to learn Java and I do [read] Keywords: notes xpages blogging community java javascript
696


Why learning JavaScript is more critical to XPage developers than Java
Wed, Mar 26th 2014 5:14p   Mark Roden
I have tried to write this article multiple times over the last 2 years, when I read it back to myself it always sounds like I am bitching. Honestly, I usually am and that is why it has not been published. This is a final attempt at a constructive argument against the insistence on many blogs that everyone should learn Java. Many people think I hate Java; I really don’t. I can program Java (I am no expert admittedly) and have done so on multiple occasions. My concerns are always raised whe [read] Keywords: domino ibm lotus notes notes client R4 xpages ajax application applications community css database development dojo google interface java javascript network server websphere xml
194


PATCHing a Document using Domino Data Service
Mon, Mar 24th 2014 7:11p   Mark Roden
Talk about frustrating – in a week full of slow progress and CORS cross domain hell I found this little annoyance after hours of staring and curing – once again the power of trial and error triumphs over my stupidity again. The problem I have a Domino Data Service running on the server and I want to update a document This is the imaginary URL https://xomino.com/issues.nsf/api/data/documents/unid/FDCA9C28A793D3F785257C4D0068BBCA returning the imaginary data just fine { "@href": [read] Keywords: domino ibm ajax application java server
211


How to ad icons to individual items in a Select2 multi-value field
Tue, Mar 18th 2014 8:08p   Mark Roden
Select2 is one of the best user interface enhancers I have come across – if you do not know what it is then you need to go play with it. It transforms SELECT boxes into dynamic, stunning, interactive UI elements and allows for all sorts of customizations and developer fun. What I want to be able to do is select items from different categories within the select2 box and then add an icon displaying to the user which category they came from. In this article I will show how. Example I want to [read] Keywords: css interface xml




178


My ongoing struggle with stupidity and what is not valid JSON
Sun, Mar 16th 2014 6:06p   Mark Roden
So this was a frustrating lesson to learn – and please feel free to be entertained by my apparent stupidity. I was trying to create my own JSON with an xAgent – seems easy enough. I created a simple output which looked like this { 'items': [ { 'name': 'AK', 'dc': 23 } ] } and when I fed it through my AJAX code it failed. $.ajax({ dataType: 'json', url: "http://copper.xomino.com/xomino/ExtjsBigData.nsf/xState.xsp?query="+query //url: 'http://coppe [read] Keywords: ajax google javascript
190


jQuery in XPages #20 – NProgress – YouTube-like slim progress bar
Wed, Mar 12th 2014 7:02p   Mark Roden
In this article I will describe how to implement and use the jQuery NProgress nano scrollbar plugin Demonstration The XPages integration of NProgress is demonstrated here Download The demonstration database can be downloaded from the link above or from here NProgress Introduction Since Youtube.com added their nano scroll bar at the top of the page there have been a flurry of different jQuery plugins which mimic the nano progress bar at the top of the screen. The silly thing is that the progre [read] Keywords: xpages ajax application applications css database dojo integration javascript openntf server xml
222


Manually Setting Domino Database Properties through DDE
Sun, Mar 9th 2014 6:27p   Mark Roden
This gets filed under the “I am writing this because I know I am going to forget it, and will need it again” We had a problem in a database whereby we were checking to see if document locking was enabled and if not then it gets programmatically enabled. This reference document from IBM tells you how it can be done in LotusScript. This was done to the database which was deployed around the world. Is there a way to programmatically change Database Properties for a database? 'Set th [read] Keywords: domino dxl ibm lotusscript xpages database eclipse properties
311


Why using XPages Partial Refresh is sometimes easy for developers and bad for users
Tue, Mar 4th 2014 6:14p   Mark Roden
In this article I will discuss the potential issues of using using a Partial Refresh in XPages and how developer addiction and dependency on it is bad for users. Introduction This is the hardest blog post I have written – and I have written and destroyed it about 5 times before this one. Too many times I have come across what I consider to be poor design choices. I am always motivated to write when I am annoyed and rant and whine about how the over use of Partial Refresh is easy for XPag [read] Keywords: domino ibm notes xpages ajax application development dojo google interface java javascript properties server




Created and Maintained by Yancy Lent - About - Blog Submission - Suggestions - Change Log - Blog Widget - Advertising - Mobile Edition