329 Lotus blogs updated hourly. Who will post next? Home | Downloads | Events | Jobs | Twitter | Bookmarks | Pods | Blogs | Search | myPL | About 
 
Latest 7 Posts
XPages ND9 (Dojo 1.8) does not work with other AMD loaders (and the work around)
Tue, May 14th 2013 173
Server-side HTML vs. JS Widgets vs. Single-Page Web Apps – the XPages version
Mon, May 13th 2013 247
DCLUG – May 23rd – IBM Sametime Deployment – A look at where are we and where should we go
Mon, May 13th 2013 121
EXTJS in XPages #9 – Infinite scrolling rebooted and reborn – v4.2 BufferedRenderer
Mon, May 13th 2013 177
Shorthand Conditional JavaScript variable checking using ||
Sun, May 5th 2013 206
jQuery in XPages #19 – Shadow (Add eye catching drop shadows to your page elements)
Thu, May 2nd 2013 221
JavaScript variable hoisting
Wed, May 1st 2013 226
Top 10
jQuery in XPages #17 – nanoScroller (game changing – mini scrollbar)
Sun, Dec 2nd 2012 816
Thank you Carl Tyler, Ed Brill and the lotus community.
Thu, Dec 13th 2012 814
Dave Leedy: Drink to 99 at IBMConnect
Sun, Dec 16th 2012 703
EXTJS in XPages – the grid series
Sun, Feb 24th 2013 633
Community Blogging and why you shouldn’t give a &^%$ what anyone thinks
Thu, Nov 15th 2012 579
A couple of Tips on how to optimize your XPages REST Service
Thu, Feb 7th 2013 489
Nice simple OneUI XPage layout section with dijit.TitlePane
Thu, Aug 23rd 2012 484
Make your XPages more maintainable – JavaScript Callback functions
Sun, Apr 28th 2013 479
XPages SSJS: Beware – context.getURL() does not do what it says on the tin!
Thu, Mar 7th 2013 445
EXTJS in XPages #3 – Creating a basic grid from a Custom Control
Sun, Mar 3rd 2013 434


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
134 hits



Recent Blog Posts
173


XPages ND9 (Dojo 1.8) does not work with other AMD loaders (and the work around)
Tue, May 14th 2013 6:10p   Mark Roden
Today I took a new jQuery plugin that I was playing with from an R8.5.3 environment where it worked, to an R9 environment and it failed – I figured it had something to do with something I had been reading about over the last month and in fixing my problem this lead to a more serious realization that I KNOW other people are also going to come across. Background A brief scan of the last month’s discussions on Xpages and jQuery Mobile 1.3 reveals a number of posts started by Dave Leedy [read] Keywords: domino ibm notes R8 xpages bug database dojo mobile properties
247


Server-side HTML vs. JS Widgets vs. Single-Page Web Apps – the XPages version
Mon, May 13th 2013 8:13p   Mark Roden
Yesterday I came across this excellent article by Pamela Fox - http://blog.pamelafox.org/2013/05/frontend-architectures-server-side-html.html. In it she goes through how her company uses all three stated architectures, discusses why, and how they are used by the end users. It struck me as fascinating because I feel like we are going through this exact same struggle in the XPages community – what is the best architecture to create applications for our users? I also feel fortunate to have [read] Keywords: domino ibm lotus notes script library xpages ajax application applications community development enterprise interface javascript profile server twitter widget widgets
121


DCLUG – May 23rd – IBM Sametime Deployment – A look at where are we and where should we go
Mon, May 13th 2013 11:48a   Mark Roden
This month we have Maurice Cogdell speaking to us about his recent experiences with Sametime and where it is going in the market. If you are to attend this meeting YOU MUST use the meetup site (listed below) to state you are attending – name badges will be created prior to the meeting as your access. Date 23rd May 2013 Address The meeting will be held at IBM Technical Exploration Center 401 Greensboro Drive, McLean, VA Agenda ————————R [read] Keywords: ibm lotus sametime show and tell community google networking
177


EXTJS in XPages #9 – Infinite scrolling rebooted and reborn – v4.2 BufferedRenderer
Mon, May 13th 2013 5:29a   Mark Roden
In this article I will introduce the new EXTJS v4.2 Infinite scroller – the BuffererRenderer. The whole concept of infinite scrolling has been rewritten in the new version of the grid and it had made a huge difference to responsiveness and stability of the infinite grid. EXTJS in XPages series Here are links to all of the previous articles in this series EXTJS in XPages #8 – Selecting data from the grid and opening a document EXTJS in XPages #7 – Doing an @Unique(@DbColumn) equivalent [read] Keywords: xpages ajax application database javascript properties server xml
206


Shorthand Conditional JavaScript variable checking using ||
Sun, May 5th 2013 6:23p   Mark Roden
In this article I will highlight a shorthand method of JavaScript conditional variable checking. The || operator is commonly recognized as “OR” but it’s usage is broader than some people would think. You might have occasion to have a variable declaration purposefully override a desired value. In this example the start will be zero unless the start variable has been declared with and assigned value: Long Hand var start /*..bunch o' code..*/ if (!start){ start = 0 } [read] Keywords: javascript
221


jQuery in XPages #19 – Shadow (Add eye catching drop shadows to your page elements)
Thu, May 2nd 2013 9:38p   Mark Roden
In this article I will describe how to implement and use the jQuery shadow plugin to create great looking shadowed panels within your XPages application. Demonstration The XPages integration of shadow is demonstrated here Download The demonstration database can be downloaded from the link above or from here Shadow Introduction “Adapted from Nicholas Gallagher’s CSS drop shadows without images demo “ Adding “depth” to the visual aspect of your website is one of tho [read] Keywords: xpages application css database dojo firefox integration interface widget
226


JavaScript variable hoisting
Wed, May 1st 2013 8:16p   Mark Roden
In this article I will give a quick overview of JavaScript hoisting and explain why sometimes your variables are not doing what you expect them to. In the following example we have a very simple variable declaration and function: var msg = "hello world" function sayHi(){ alert(msg) } sayHi() If you run this through firebug you get the expected message in the browser However if you change the code slightly you do not get the initially expected response. When you run the following code [read] Keywords: javascript
479


Make your XPages more maintainable – JavaScript Callback functions
Sun, Apr 28th 2013 6:39p   Mark Roden
In this article I will attempt to explain the purpose and benefits of using callback functions in JavaScript. Introduction Basic JavaScript functions look like this normally like this function addMe(a, b){ return a+ b } JavaScript variables normally look like this var a = 2 var b = 3 Finally we would call the function to add the variables var theTotal = addMe(a, b) //5 Seems simple enough Setting a variable to a function But we can also combine them into something like this va [read] Keywords: xpages ajax application development dojo javascript




254


Webcast: jQuery The World’s Most Popular JavaScript Library Comes to XPages – now on YouTube
Fri, Apr 26th 2013 7:39a   Mark Roden
It was an absolute pleasure to do my jQuery in XPages presentation for the 3rd time (publicly) earlier this week and it was as part of the TLCC and Teamstudio webcast series highlighting some of the people and presentations from the community. There were 430 people registered for the webcast and at its peak there were over 300 people watching. As with each presentation, podcast and screencast I have had the privilege of being a part of, I am humbled by knowing that I am able to help other develo [read] Keywords: xpages community javascript podcast
173


My first PSC star award – Advise
Sat, Apr 20th 2013 8:21a   Mark Roden
The company I am very proud to work for, PSC Group, has an excellent internal consultant personal growth program called the “5 points of excellence“. This program allows consultants to grow and learn in 15 different areas from sales, to estimation, to development and others. PSC runs classes to promote individual areas of personal growth such as a consultant bootcamp, rainmaking seminars, personal image classes and many others. I have never worked for a company with such a focused [read] Keywords: development




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