Embedding JS Script Tags in WordPress Posts

When you include javascript in a WordPress post, WP automatically applies formatting to the script tag’s contents, causing script errors. This has led to a large number of workarounds, including: plugins, using custom fields, including every script as a separate JS file, and stripping empty lines from the script (to prevent WP from injecting paragraph tags).

I wanted a solution that would let me quickly inject JS directly into my post content, and wouldn’t require any special prep or have dependencies on third party plugins. After unsuccessfully hunting the web for an answer, I came up with a simple approach that uses a pre tag to prevent WordPress from formatting my code:

<pre class="script"><script>
  // code here.
</script></pre>

Then just add the following to your site styles to prevent the pre tag from displaying:

pre.script {
  visibility: hidden;
  display: none;
}

It’s crazy simple and the script executes properly. I’m kind of shocked that I didn’t run into this approach at all in my search. It makes me worry a bit that there’s some glaring flaw with it, but so far it seems to be working great.

Hopefully this saves someone else some time and frustration.

Note: there’s a chance you may need to disable “Settings > Writing > WordPress should correct invalidly nested XHTML automatically” to prevent WP from encoding characters in your code. I have it disabled normally, but in limited testing I didn’t see any problems with it enabled.

New dev update for Bardbarian!

null

Over at TreeFortress we’ve put together a massive dev update for our upcoming game Bardbarian. To read all about it, check out the TreeFortress blog!

If you’re not familiar, Bardbarian is an iOS/Android game, built with Adobe AIR and the Starling Framework, and is slated for a Spring/Summer release in 2013. TreeFortress is a seperate division of gskinner, focused solely on creating our own apps and games. Follow them directly if you’re interested!

Spelling Plus Library Open Sourced

We would like to let everyone know that Spelling Plus Library (aka SPL), our Flash/Flex spell-checking library has been released open source.

We first released SPL as a commercial component over 6 years ago, with a major overhaul to support the Text Layout Framework almost 4 years later. It was always our goal to provide a high quality, performant, and feature rich product, backed by great support. As the requirements of the industry have shifted, and the demand for Flash components has dropped, we felt it was a great time to release it to the community at large.

The entire SPL repository is now available under an MIT license, meaning it is free to use for everyone, including on commercial projects. This includes:

  • The SPL source code. Word list loader and parser, text highlighter, and spelling suggestion and replacement utilities
  • The Flex-based AIR application that helps create, modify, and export word lists
  • All examples, spikes we used for testing, and some internal demos
  • The build process to export Flash and Flex SWCs
  • Generated word lists using custom compression for US and UK English, along with tested word lists for Spanish, French, and German.

 
You can check out the GitHub repository to get everything. Feel free to submit pull requests. Please note that we are no longer supporting SPL, so any questions or issues reported may not get immediate responses.

Thanks to our supporters over the years, we are super proud of what SPL has accomplished, and hope that it will continue to see life moving forward.

New versions of CreateJS released!

Wow. What a difference of couple of years makes. Most of you have noticed a shift in the industry over the last two years towards HTML5 — instead of running away from this change, we’ve embraced it. Our response was CreateJS: a collection of Javascript libraries that allow us to create the same high quality experience and quick turnaround that we are known for.

Not only has the framework been a major part of our development, but some great tools have been created to improve user workflow, such as ToolKit for CreateJS and Zoë.

We are happy to announce new versions of the CreateJS Libraries, available now on the CreateJS CDN and GitHub.

This update includes a new common event model, vastly improved documentation, and a ton of new features and fixes for each library. For specific information on the changes, please review the VERSIONS.txt file in the relative GitHub repositories.

We have also introduced a minified CreateJS library to the CDN, containing all the latest libraries in one handy file.

With this release, we are happy to announce the launch of the CreateJS blog, which will provide a centralized location for announcements and articles about the libraries. Read more about the update to the CreateJS libraries here.

Thank you all for testing, feedback, contributions, and bug reports…keep them coming!

SpriterAS: Playback Spriter animations with Starling

One of the toughest aspects of doing Game Development with GPU rendering, is managing the texture size of your various animations. Traditional SpriteSheets consume texture memory extremely quickly, and in the age of Retina Devices, they’re starting to prove inadequate.

To help work around this problem, our guys at TreeFortress have put together a library called SpriterAS. SpriterAS is a plugin which allows you to playback Spriter Animations (.SCML files) in AIR using Starling/Stage3D.

What is Spriter?
Spriter is a tool for creating so-called ‘modular’ animations which require a very small texture footprint. This enables long, complex animations running at a smooth 60fps.

For full details, examples and code snippets, check out the blog post over at treefortress.com!

Also, in case you’re wondering, we are planning on creating a Javascript version for use with EaselJS in the future 🙂

Introducing: TreeFortress Games!

Today we’re happy to announce a new initiative at gskinner: TreeFortress Games!

TreeFortress is a new arm of the company, focused on building mobile games (or apps) and bringing them to market. Initially, we will be using AIR + Starling as our core development stack, possibly branching out to Unity3D or HTML in the future.

TreeFortress will have its own blog which will include posts on our development workflow and upcoming games. Expect lots of code snippets, workflow tools, and tons of cool Artwork.

If you’re interested, you can follow us on your preferred social network:

 
Our first game is called Bardbarian, and is due out for Spring, 2013. For more info check it out here: http://treefortress.com/introducing-bardbarian/

Hope to see you there!

Open Source Licenses, JS, and Minification

I’m definitely not a lawyer and I detest reading legalese, but I have a strong interest in the legal considerations of the technology I work with. One area I’ve done a lot of research into in the past is the implications of different open source licenses, which led to this older blog post comparing common licenses.

Recently, one of my devs asked how this applied to JS and minification. Here’s the quick response I tossed together:

Let’s assume we are looking at the MIT license or an equivalent. Remember that ANY third party code requires client approval, and any license other than MIT should be run past me as well.

The MIT license specifically requires that the license is included somewhere in the software, but it does not need to be public facing. Typically, the license is included as a comment at the top of the source files. However, minification strips out the comments and combines source code into a single file. This raises three possible scenarios:


  1. All of the code in the file is under MIT license. In this case, you can inject the copyright statements for each of the libraries followed by the main body of the MIT license above the minified code. We do this automatically for the CreateJS libraries as part of our build process.
  2. Client code & MIT licensed code. I would recommend that all open source code is treated as in #1, and client code is minified into its own file (potentially with a copyright header specified by the client). This is much cleaner than trying to mix them.
  3. Code with different licenses. This gets much more complex, and should be dealt with on a case by case basis.

I’d be interested to hear about how other companies are dealing with this topic, or related ones.

Orcastra: Live Web Audio using CreateJS

We recently spent some time playing with a new feature in Chrome called Web Audio Input, which provides access to a microphone or other audio input.

The result was “Orcastra” (ha!) which allows users to select one of five deep sea characters who lip sync along to the user’s audio input.

Orcastra

Creating Orcastra was quite straightforward. The characters were all created in the Flash CS6 IDE (MovieClips with timeline animations) and exported to HTML5 using Toolkit for CreateJS. We used PreloadJS to load all our assets, TweenJS for simple tweens, and EaselJS as the display layer.

We use feature detection to ensure the browser supports audio input, prompt users to allow access to their microphone, then listen for volume changes (with maximum mic gain) to confirm audio input before showing the character selection screen. Once the user picks a character, it’s just a simple matter of syncing the CreateJS animations with the current input volume level.

Orcastra should work with any Web Audio Input enabled browser. This currently includes the latest version of Chrome for OSX, and Chrome Canary for Windows, but you’ll need to enable the feature with chrome://flags and restart your browser before trying it.