Subscribe to feed

Archive for the ‘Techniques’ Category

It’s relatively simple to include Javascript in your Sharepoint pages. With some judicious editing you can add your code inline or via separate code files.

Embedding Javascript

To include Javascript in your page:

  1. use a Content Editor Webpart (CEWP)
  2. edit via the Source Editor button (not Rich Text Editor), and
  3. add your code within standard <script></script> tags

Within the script block just add your normal code, comments, etc. The only issue you’ll have is being able to indent the text and make it look pretty. Tab doesn’t help; you’ll need to use spaces (the horror!).

Don’t use the Rich Text Editor
Important! Always use the Source Editor function to manipulate your code, or any other content within the same CEWP. If you use the Rich Text Editor at any point it will delete all your script.

Linking to Javascript source files

Sometimes your javascript code may be a little too long to embed. Or, like me, you’ve been burnt once too often by clicking the Rich Text Editor button by mistake. At such times you might prefer to link to separate javascript files rather than embedding all directly.

To link to a separate file:

  1. save the Javascript content as a separate .JS file and upload to somewhere on your site. I tend use a /scripts subfolder within the default documents library.
  2. add/edit your CEWP to reference the script file:
<script type="text/javascript" src="full path to script file"></script>

For example, here’s a CEWP that includes a separate Javascript file and then references a function (presumably) defined within it.

Share

Just discovered this website had been hacked. First clue was when the site got banned by a corporate web filter as “adult material”. Unless someone had posted a particularly vitriolic comment that was unlikely.

I won’t provide any more oxygen to the hackers over what exactly happened, but here’s the steps taken to get back online.

(1) Run to Google

As always, find a friend who’s been through it before. In particular these two pages proved useful.

First steps taken after reading them (and they explain more about each step):

  • change passwords (for both wordpress and mySQL)
  • setup secret keys and salts
  • check .htaccess
  • delete all unused themes

(2) Install the exploit scanner

There is a plugin available that can help check for suspicious code:

http://ocaoimh.ie/exploit-scanner/

Follow the provided instructions to install.

When I ran the scanner it located dodgy code in a plethora of files. Comparing those files to a (sadly) old backup I discovered they were not part of the original wordpress installation. They also, suspiciously, all had an identical and recent install date/time.

Therefore next step was to delete them all. And that did most of the work. I got my site back. Almost….

(3) Fix the theme

After deleting all the extra files, the site was almost back. It now did not show the “you’ve been hacked page”. But instead it showed the contents of my theme’s CSS file. Obviously some corruption in there somewhere.

First step was to temporarily install a basic theme and switched to that. All worked well and my site was back up and running. Just ugly(er). To improve I then deleted the corrupted theme and re-installed from a backup. And everything was back to normal.

Conclusion

Thankfully my intrusion proved quite simple to remove. Whether I removed every element we’ll find out in the next days as we see how long the site stays up. However lessons learnt are quite simple:

  1. get a recent/regular backup (of content and data). Having another folder listing what files should be there proved invaluable in quickly deleting what was added.
  2. keep up to date with releases.
  3. if you’re site suddenly gets blocked by a web filter, don’t blame a rude commenter!
Share

If needing to present data that pertains to specific geographic locations, the logical approach is a map. Having just worked with Google Maps, and discovered how easy it is to implement, this article summarises all the key information needed to quickly make a map of your own.

Share

Everybody needs a lego moleskine. Comparison shopping at the UK Book Depository proved troublesome because they decided to cut the product title short, removing the information that actually differentiated the products being chosen:

Hard to tell which one to choose when everything you want to know about the choices is unavailable. Should I get the “Lego Y..” or, mmmmm, the other “Lego Y..”?

Compare to Amazon, who manage to fit the full name in without issue:

If you’re going to allow a certain number of characters for a value, assume all of those characters may be important at some point. And make sure somewhere on your interface you let them all get their moment in the sun.

Share

Frustratingly, my iPad calendar appeared to unilaterally decide that the first day of the week was Sunday. And there was no obvious setting to change it, like there is for Calendar on the Mac.

Turns out this “feature” is decided by Apple based on your region. They believe Australian weeks start on Sunday so that’s the way it is. To change the day, change your region.

For Australians wanting their calendar to start on a Monday:

  1. Launch settings
  2. Select General > International
  3. change region format to Namibia

This bizarre choice seems to have the best option for calendar setting, as well as changes it makes to keyboards (what currency symbol you see), date and time formats, even which google you default to when you search. Namibia appears to leave all the other settings “just like Australia”, and still default to google.com.au for searching in Safari.

Thanks to the clever chaps on the Whirlpool forums, particularly dokh22, for uncovering this. Now how long before Apple gives us a calendar setting to do it properly?

Share

Adding frame-by-frame animations to your iOS application is simple once you find out that a UIImageView can be initialised with an array of images, not just one image.

This post was inspired by a colleague who had not uncovered that fact, and so had spent time arduously linking separate views with timers. This post shows how to use a single view and 3 lines of animation code to do all the work.

What to do?

What we’ll do as a test is animate the blinking eyes on a tennis-playing ninja splash screen. To trigger the animation will add a “blink” button on the same screen.

Don’t ask how we ended up with that as the example (thanks to the friend). But you can download the entire project, or just the images if wanting to join in.

Share

Finally managed to download and install the IOS5 update for the iPad. Most of the new features are unobtrusive, although still trying to find some of them.

However what wins is the wireless synchronisation feature. Now I can update my library (songs, books, tv) on my computer and click Sync. And the iPad gets updated while not connected. While not even switched on. While in my briefcase in another room.

Sweet.

[Although I'll admit it's probably sweet because Apple kept us tethered for far too long!]

Share

I’m in the midst of collating a series of issues/quirks with UPK 3.6.1, hoping that Oracle are listening. While organising here’s a bonus item.

When I’m editing frame properties, don’t present a tooltip that has the unerring habit of appearing directly over the top of where I’m trying to type!! B!@#y annoying.

Share

Earlier I wrote about how you can use XML+XSL to get around the limitation in Sharepoint 2007 of sharing calendars across multiple sites. This technique stores your events as XML and allows you to publish entries wherever and however you wish.

This article expands that earlier introduction with some tips and tricks we collating when implementing this for one client:

  • working outside Sharepoint
  • presenting a URL
  • sorting items
  • grouping items
  • showing a message if a filter set is empty

Note: You can download sample XML and XSL here. These files show all the techniques described in this article.

the original XML filtered view grouped view
Share

With ePUBs it is straightforward to add a table of contents to your book, allowing your readers to quickly navigate within your content. Interestingly how you do it is not a part of the ePUB specification itself, but highlights ePUB’s development from earlier digital book initiatives.

This article assumes you are creating/editing your ePUB source content directly. If generating an ePUB via a development tool (eg Pages, InDesign) then it can automatically generate the TOC for you. However even if doing so this article will help describe what is being built for you.

To help, I’ve included a smorgasbord of sample ePUBs to demonstrate how tables of contents are included. There’s a basic book (single level/standard TOC) as well as books with 2, 3, 4, or 5 level TOCs.
Download the one you want or take the whole pack. Note that because WordPress considers EPUBs a security risk, they’ve all be zipped.

Do I need to do this?

A table of contents is optional (your ePUB is valid and usable without one). What’s more how it actually presents for your readers is dependent on the reader. As such you should decide for each book, and your target market, whether worth the development effort.

How do I do this?

Adding a table of contents to your ePUB has two key steps:

  1. Creating a valid .NCX file
  2. Including the .NCX file in your book

Let’s work through these steps in turn.

Creating a valid .NCX file

The .NCX file defines your table of contents. There’s no rule about what filename to give it, but the default option for most eBooks appears to be TOC.NCX. So we’ll assume we’ve called it that too.

The definition for your TOC.NCX file is not part of the ePUB specification but is instead maintained by the DAISY Consortium and co-opted by IPDF who manage ePUBs for us. Browse the detailed specification and see if you can find out what NCX stands for.

In essence an .NCX file is an XML file. It lists the elements for your table of contents within a simple and standard framework:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE ncx
  PUBLIC "-//NISO//DTD ncx 2005-1//EN"
  "http://www.daisy.org/z3986/2005/ncx-2005-1.dtd">
<head>
	-- insert required metadata
</head>
<docTitle><text>DOCTITLE</text></docTitle>
<docAuthor><text>DOCAUTHOR</text></docAuthor>
<navMap>
	-- insert required navigation structure
</navMap>
</ncx>

Copy that and use as the basis for your TOC.NCX, while we fill in the missing bits: metadata, title, author, navigation structure.

(1) insert required metadata

Every .NCX file needs to define four metadata elements:

  • dtb:uid – this is the unique ID for your publication.  It needs to match the ID given in content.opf.
  • dtb:depth – this is the number of levels in your TOC. Normally this would be 1 but you can add more levels – see hierarchical contents below
  • dtb:totalPageCount – this is not used: set to zero
  • dtb:maxPageNumber – this is not used: set to zero

For example, here’s the .NCX header for a standard table of contents with only 1 layer of entries.

<head>
	<meta name="dtb:uid" content="a897sad23fd23ds" />
	<meta name="dtb:depth" content="1" />
	<meta name="dtb:totalPageCount" content="0" />
	<meta name="dtb:maxPageNumber" content="0" />
</head>

 

(2) record title and author

The document title and author should match those recorded in the main metadata within content.opf (DC:Title, DC:Creator respectively). Some readers may reference these values when displaying the contents, although those in my limited test suite all seem to ignore these values and focus on those in content.opf.

In the sample ePUBs included with this article I deliberate added “(NCX)” to the end of the title and author in each .NCX file. Just to see if/where it appeared. Never did. But your mileage may vary.

(3) insert required navigation structure

The navMap is where the entries in your table of contents are defined using special XML elements called navPoints.

<navPoint playOrder="x">
     <navLabel>Text to show in the table</navLabel>
     <content src="url" />
</navPoint>

The playOrder is numeric, indicating the sequence that the content elements should be traversed in when navigating.  Note that this does not need to match the order you list them (and they appear) in the TOC. Nor does it need to match the sequence in the <spine> section of content.opf.

My testing (and the OPF specification) indicate that the playOrder is not used to determine the sequence content is browsed. When users move through the content sequentially, this sequence is defined by the <spine> element in content.opf. However, even though playOrder is not used, it is recommended that meaningful values are recorded “just-in-case”. It also ensures your ePUB validation, if using epubcheck, will be successful.

The text will present as entered in your TOC; be mindful that not all readers will have a lot of room so don’t make the entries too long.

The URL needs to be the reference to the file/location that is the target of this TOC entry. This will be the filename if you have created separate chapter files. Else you could reference separate sections within a single document via anchor tags.

For example, here are sample entries from the start of one EBook.


<navPoint playOrder="1">
  <navLabel><text>cover</text></navLabel>
  <content src="00-cover.xhtml" />
</navPoint>
<navPoint playOrder="2">
  <navLabel><text>preface</text></navLabel>
  <content src="10-frontis.xhtml#preface" />
</navPoint>
<navPoint playOrder="3">
  <navLabel><text>credits</text></navLabel>
  <content src="10-frontis.xhtml#credits" />
</navPoint>
<navPoint playOrder="4">
  <navLabel><text>Chapter 1 - Background</text></navLabel>
  <content src="chapter1.xhtml" />
</navPoint>

Note: If using anchor tabs, the other end of the link needs to be to an ID, not name tag. Read this for the explanation.

Including the .NCX file in your book

Only two small changes are made to your existing eBook to include your .NCX content, both made to content.opf:

  • add your TOC.NCX file to the ebook manifest. Application type needs to be
    application/x-dtbncx+xml
  • add a reference to the new TOC.NCX to your ebook spine. This is added as an attribute in your <spine> tag:
<manifest>
  <item href="toc.ncx" id="ncx" media-type="application/x-dtbncx+xml"/>
  ...
</manifest>

<spine toc="ncx">
  <itemref idref="chapter1" />
  ...
</spine>

That’s it. Save CONTENT.OPF, build and test.

Next steps

Once you’ve mastered the basic table of contents, you’re ready to investigate some more advanced options:

hierarchical contents

You can create multiple levels in your table of contents simply by nesting your navPoint elements.

...
<navPoint id="navpoint" playOrder="1">
          <navLabel>Chapter 1
          <navPoint playOrder="2">
Section 1</navPoint>
          <navPoint playOrder="3">
Section 2</navPoint>
...

Don’t forget to work through the playOrder values to retain a logical sequence to your content. Even though not sure who/where these values are used :-)

How hierachical contents are displayed or navigated depends very much on the reader. It also appears to vary how many levels of content are supported. The standard itself sets no limits (or tells you what to call them: chapter, part, section, ..). However mileage may vary with different readers so don’t go overboard. The following table shows results with the two readers I spend most of my time with: Adobe Digital Editions (ADE) and iBooks (on the iPad). The two columns for ADE show the default view (when first opening your book) and the expanded view.

single level (basic book)
two levels
three levels
four levels
five levels

Notice:

  • for iBooks, it gives up after 2 levels of contents. Unable to find anything official that states that’s a limit, but if aiming for that platform I’d stop at 2.
  • for Adobe Digital Editions, the menu gets a little confused at the deeper levels – notice at 5 levels of contents the first level does not appear. Not sure if anything can be done to fix that, but also reason to avoid going that deep.

The above images are taken from the sample ebooks included with this article. Feel free to use to test how well supported in your chosen reader.

multiple tables (pageLists and navLists)

The standard table of contents is defined within a navMap. This is the complete, logical structure of your book. However the .NCX specification also allows you add two additional types of references to your TOC:

  • pageList – use if needing to offer navigation by page (rather than topic/section). Your ePUB can only include one pageList, and it cannot be hierarchical – one layer only.
  • navList – use if wanting to offer other any other arbitrary collection of topics, for example a list of illustrations or a collection of chocolate recipes taken from your complete recipe book. You can have as many navLists as you want, although they too can only be single level. An additional element, navLabel, can be added to give a title to your collection.

The steps involved in defining and including these tables is complex enough to warrant their own article, coming soon.

Conclusion

A table of contents is a valuable addition to most books, particularly non-fiction or reference titles. Adding one is reasonably simple, and thus worth the effort. However keep to the basics if wanting to be functional in the widest range of readers.

Share