Permalink
Browse files

Initial commit (with v0.8.1)

  • Loading branch information...
0 parents commit 5b49de28d89035eb8cf2c27f1af7ae1876a4d8ad Paul Engel committed Jul 21, 2010
@@ -0,0 +1,23 @@
+= SeatHolder CHANGELOG
+
+== Version 0.8.1 (May 28, 2010)
+
+* Improved copying hinted element attributes a lot
+
+== Version 0.8 (April 2, 2010)
+
+* Not using ID for matching hint and hinted elements anymore (yay!) Using jQuery.data() instead (woot!)
+
+== Version 0.7 (March 7, 2010)
+
+* Being able to show seatholders within textareas
+* Also cloning the 'cols' and 'rows' attributes
+
+== Version 0.6 (January 12, 2010)
+
+* Added SeatHolder.version
+* Adjusted jQuery inclusion (including ./jquery/core.js from now on)
+
+== Version 0.5 (May 15, 2009)
+
+* Including jquery.js automatically when missing (done like TopUp)
@@ -0,0 +1,20 @@
+Copyright (c) 2010 Paul Engel
+
+Permission is hereby granted, free of charge, to any person obtaining
+a copy of this software and associated documentation files (the
+"Software"), to deal in the Software without restriction, including
+without limitation the rights to use, copy, modify, merge, publish,
+distribute, sublicense, and/or sell copies of the Software, and to
+permit persons to whom the Software is furnished to do so, subject to
+the following conditions:
+
+The above copyright notice and this permission notice shall be
+included in all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,99 @@
+
+h1. SeatHolder
+
+The modest Javascript placeholder
+
+h2. Introduction
+
+SeatHolder is a small Javascript library which lets you display placeholder text (so called @seatholders@) and place default values to text inputs and textareas with great ease. It uses jQuery ("http://jquery.com":http://jquery.com) to keep your HTML as clean as possible.
+
+h2. Installation
+
+h3. When including jQuery yourself
+
+Just include SeatHolder after you have included jQuery:
+
+<pre>
+ <script src="path/to/jquery.js" type="text/javascript"></script>
+ <script src="path/to/seat_holder.js" type="text/javascript"></script>
+</pre>
+
+*Note*: include @seat_holder-min.js@ for the minified SeatHolder library
+
+h3. When letting SeatHolder include jQuery automatically
+
+Make sure you put the @jquery@ directory in the same directory as the SeatHolder library:
+
+<pre>
+ |
+ |-- seat_holder.js
+ |
+ |-- jquery
+ |
+ |-- core.js
+</pre>
+
+Just include SeatHolder:
+
+<pre>
+ <script src="path/to/seat_holder.js" type="text/javascript"></script>
+</pre>
+
+*Note*: include @seat_holder-min.js@ for the minified SeatHolder library
+
+h2. Usage
+
+h3. Placeholders
+
+Just add the @seatholder@ attribute to your inputs:
+
+<pre>
+ <form>
+ ...
+ <input type="text" name="user[first_name]" seatholder="Your first name">
+ <textarea name="question[body]" seatholder="Please specify your question"></textarea>
+ ...
+ </form>
+</pre>
+
+h3. Default values
+
+As stated above, you can also specify default values for text inputs and textareas. Just start the @seatholder@ attribute with @'&'@:
+
+<pre>
+ <form>
+ ...
+ <input type="text" name="object[title]" seatholder="&SeatHolder Demo">
+ <textarea name="object[body]" seatholder="&I would like to receive more information"></textarea>
+ ...
+ </form>
+</pre>
+
+For a complete example, please open "http://github.com/archan937/seat_holder/blob/master/test/index.html":http://github.com/archan937/seat_holder/blob/master/test/index.html which is extracted from "http://gettopup.com/demo":http://gettopup.com/demo.
+
+h2. Contact me
+
+For support, remarks and requests please mail me at "paul.engel@holder.nl":mailto:paul.engel@holder.nl.
+
+h2. Credit
+
+This Javascript library depends on:
+
+jQuery<br>
+"http://jquery.com":http://jquery.com
+
+h2. ToDo's
+
+None
+
+h2. License
+
+Copyright (c) 2010 Paul Engel, released under the MIT license
+
+"http://holder.nl":http://holder.nl - "http://codehero.es":http://codehero.es - "http://gettopup.com":http://gettopup.com - "http://twitter.com/archan937":http://twitter.com/archan937 - "paul.engel@holder.nl":mailto:paul.engel@holder.nl
+
+Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,39 @@
+namespace :seat_holder do
+ desc "Release a new SeatHolder version"
+ task :release, :version do |task, args|
+ if (args[:version] || "").strip.empty?
+ puts "usage: rake seat_holder:release[version]"
+ exit
+ end
+
+ timestamp = Time.now
+ javascript = File.open("src/seat_holder.js").readlines.collect{ |line|
+ line.gsub(/\{(version|year|date)\}/) do |matched|
+ case matched
+ when "{version}"
+ args[:version]
+ when "{year}"
+ timestamp.year.to_s
+ when "{date}"
+ timestamp.strftime("%Y-%m-%d %H:%M:%S +0100 (%a, %d %B %Y)")
+ end
+ end
+ }
+
+ # Define variables
+ releases_dir = "releases"
+ release_dir = "#{releases_dir}/#{args[:version]}"
+
+ # Create directories
+ FileUtils.rm_r(release_dir) if File.exists?(release_dir)
+ FileUtils.mkdir_p("#{release_dir}/jquery")
+
+ # Create files
+ File.open("#{release_dir}/seat_holder.js", "w").puts(javascript)
+ FileUtils.cp("src/jquery/core.js", "#{release_dir}/jquery")
+ File.open("VERSION", "w").puts(args[:version])
+
+ # Compress release using YUI compressor
+ IO.popen "java -jar lib/yuicompressor-2.4.2.jar -v #{release_dir}/seat_holder.js -o #{release_dir}/seat_holder-min.js"
+ end
+end
@@ -0,0 +1 @@
+0.8.1
Binary file not shown.

Large diffs are not rendered by default.

Oops, something went wrong.

Some generated files are not rendered by default. Learn more.

Oops, something went wrong.
@@ -0,0 +1,168 @@
+if (typeof(SeatHolder) == "undefined") {
+
+var scriptElement = (function deriveScriptElement() {
+ var id = "tu_dummy_script";
+ document.write('<script id="' + id + '"></script>');
+
+ var dummyScript = document.getElementById(id);
+ var element = dummyScript.previousSibling;
+
+ dummyScript.parentNode.removeChild(dummyScript);
+ return element;
+}());
+var scriptHost = (function deriveScriptHost() {
+ var src = scriptElement.getAttribute("src");
+ return src.match(/^\w+\:\/\//) ? src.match(/^\w+\:\/\/[^\/]*\//)[0] : "";
+}());
+
+// *
+// * SeatHolder 0.5 (Uncompressed)
+// * The modest Javascript placeholder (used in http://gettopup.com)
+// *
+// * This library requires jQuery (http://jquery.com)
+// *
+// * (c) 2009 Paul Engel (Internetbureau Holder B.V.)
+// * Except otherwise noted, SeatHolder is licensed under
+// * http://creativecommons.org/licenses/by-sa/3.0
+// *
+// * $Date: 2009-05-15 21:48:24 +0100 (Fri, 15 May 2009) $
+// *
+
+SeatHolder = (function() {
+ var hintClass = "sh_hint", hideClass = "sh_hide";
+
+ var injectCode = function() {
+ var style = "<style>" +
+ "." + hintClass + " { color: " + SeatHolder.hintColor +" !important } " +
+ "." + hideClass + " { display: none !important }" +
+ "</style>";
+
+ jQuery(style).prependTo("head");
+ };
+ var bind = function() {
+ var hintedElements = [];
+
+ jQuery.each(jQuery(SeatHolder.selector), function(i, element) {
+ element = jQuery(element);
+ var seatholder = element.attr("seatholder");
+
+ if (seatholder == null) {
+ return;
+ }
+
+ if (seatholder.match(/^&/)) {
+ onBlur(null, element);
+ } else {
+ hintedElements.push(element);
+ }
+
+ element.focus(onFocus)
+ .blur(onBlur);
+ });
+
+ jQuery.each(hintedElements, function(i, element) {
+ element = jQuery(element);
+ element.attr("id", element.attr("id") || "hinted_element_" + i);
+
+ var hintElement = jQuery("#" + element.attr("hint_element"));
+
+ if (hintElement.length == 0) {
+ hintElement = jQuery("<input/>")
+ .attr("id", "hint_element_" + i)
+ .attr("type", element.attr("type"))
+ .attr("readonly", true)
+ .attr("hinted_element", element.attr("id"))
+ .focus(onHintFocus);
+
+ jQuery.each(["class", "size"], function(index, attribute) {
+ switch(attribute) {
+ case "class":
+ hintElement.attr(attribute, element.attr(attribute).replace(hideClass, "")); break;
+ default:
+ hintElement.attr(attribute, element.attr(attribute));
+ }
+ });
+
+ hintElement.addClass(hintClass);
+ element.attr("hint_element", hintElement.attr("id"))
+ .before(hintElement);
+ }
+
+ hintElement.val(element.attr("seatholder"));
+ onBlur(null, element);
+ });
+ };
+
+ var onHintFocus = function(event) {
+ var hintElement = jQuery(event.target).addClass(hideClass);
+
+ jQuery(document.getElementById(hintElement.attr("hinted_element")))
+ .attr("disabled", false)
+ .removeClass(hideClass)
+ .focus();
+ };
+ var onFocus = function(event) {
+ var element = jQuery(event.target);
+ var seatholder = element.attr("seatholder");
+
+ if (element.val() == seatholder.replace(/^&/, "")) {
+ element.val("");
+ }
+
+ var input = element.get(0);
+
+ if (input.createTextRange) {
+ var oRange = input.createTextRange();
+ oRange.moveStart("character", 0);
+ oRange.moveEnd("character", element.val().length);
+ oRange.select();
+ } else if (input.setSelectionRange) {
+ input.setSelectionRange(0, element.val().length);
+ }
+ };
+ var onBlur = function(event, element) {
+ if (element == null) {
+ element = jQuery(event.target);
+ }
+ var seatholder = element.attr("seatholder");
+ if ((element.val().length > 0 && element.val() != seatholder.replace(/^&/, ""))) {
+ jQuery("#" + element.attr("hint_element")).addClass(hideClass);
+ return;
+ }
+
+ if (seatholder.match(/^&/)) {
+ element.val(seatholder.replace(/^&/, ""));
+ } else {
+ element.attr("disabled", true)
+ .addClass(hideClass);
+ jQuery("#" + element.attr("hint_element")).removeClass(hideClass);
+ }
+ };
+
+ return {
+ selector: "[seatholder]",
+ hintColor: "#AAA",
+ init: function() {
+ jQuery(document).ready(function() {
+ injectCode();
+ bind();
+ });
+ },
+ rebind: function() {
+ bind();
+ }
+ };
+}());
+
+(function () {
+ if (typeof(jQuery) == "undefined") {
+ var src = scriptElement.getAttribute("src").replace(/seat_holder(\-min)?\.js.*$/, "jquery.js");
+ document.write('<script src="' + src + '" type="text/javascript" ' +
+ 'onload="SeatHolder.init()" onreadystatechange="SeatHolder.init()">' +
+ '</script>');
+ } else {
+ SeatHolder.init();
+ }
+}());
+
+}

Large diffs are not rendered by default.

Oops, something went wrong.

Some generated files are not rendered by default. Learn more.

Oops, something went wrong.
Oops, something went wrong.

0 comments on commit 5b49de2

Please sign in to comment.