/* * Helper functions specific to Movie Habit */ if (!window.console) { function dn() { /* do nothing */ } window.console = { 'log': dn, 'debug': dn, 'info': dn, 'warn': dn, 'error': dn, 'assert': dn, 'dir': dn, 'dirxml': dn, 'trace': dn, 'group': dn, 'groupCollapsed': dn, 'groupEnd': dn, 'time': dn, 'timeEnd': dn, 'profile': dn, 'profileEnd': dn, 'count': dn }; } Function.prototype.hitch = function(context) { var fn = this; return function () { return fn.apply(context, arguments); }; }; function MovieHabit_Class(){ this.init(); } MovieHabit_Class.prototype.rValidRatings = ["0", "0.5", ".5", "1", "1.0", "1.5", "2", "2.0", "2.5", "3", "3.0", "3.5", "4", "4.0"]; MovieHabit_Class.prototype.init = function() { this.oValidRatings = {}; for (var i = 0; i < this.rValidRatings.length; i++) { var rating = this.rValidRatings[i]; this.oValidRatings[rating] = true; } }; MovieHabit_Class.prototype.getEssayFileName = function(title) { var title = String(title).substring(0, 45); title = title.toLowerCase(); return this.cleanFileName( title.replace(/ /g, "_") + "_" + this.get4Date() ); }; MovieHabit_Class.prototype.cleanFileName = function(filename) { return String(filename).replace(/[^0-9a-zA-Z\_\-]/g, ""); }; MovieHabit_Class.prototype.get4Date = function() { var rParts = []; // fir_ah09 - a var d = new Date(); var month = (d.getMonth()+1); rParts.push( String.fromCharCode((96 + month)) ); // fir_ah09 - h var dt = d.getDate(); if (dt < 27) { rParts.push( String.fromCharCode((96 + dt)) ); } else { rParts.push( String(dt).substr(1, 1) ); } // fir_ah09 - 09 rParts.push( String(d.getFullYear()).substr(2, 2) ); return rParts.join(""); }; MovieHabit_Class.prototype.getOldFileName = function(title) { var rParts = []; var titleNoArticle = this.getTitleNoArticle(title); titleNoArticle = titleNoArticle.replace(/[^\w]/g, ""); titleNoArticle = titleNoArticle.toLowerCase(); rParts.push( titleNoArticle.substr(0, 3) ); rParts.push("_"); rParts.push(this.get4Date()); return rParts.join(""); }; MovieHabit_Class.prototype.getSqlDate = function(jsDate) { var d = jsDate || new Date(); datePart = [ d.getFullYear(), ((d.getMonth() < 9 ? '0' : '') + (d.getMonth()+1)), ((d.getDate() < 10 ? '0' : '') + d.getDate()) ].join("-"); timePart = [ d.getHours(), d.getMinutes(), d.getSeconds() ].join(":"); return datePart + " " + timePart; }; MovieHabit_Class.prototype.getImdbLink = function(title) { return "http://imdb.com/find?s=tt&q=" + title.replace(/ /g,"+"); }; MovieHabit_Class.prototype.getAmazonLink = function(title) { return "http://www.amazon.com/exec/obidos/external-search?tag=moviehabit-20&keyword=" + encodeURIComponent(title) + "&mode=dvd"; }; MovieHabit_Class.prototype.getOutnowLink = function(title) { return "http://www.google.com/search?q=" + encodeURIComponent(title) + "+bilder+site%3Aoutnow.ch"; }; MovieHabit_Class.prototype.getTitleNoArticle = function(title) { var str = String(title); str = str.replace(/(^a\s|^an\s|^the\s)(.*$)/i, "$2, $1"); return this.trim(str); }; MovieHabit_Class.prototype.isValidRating = function(numStars) { return (numStars in this.oValidRatings); }; MovieHabit_Class.prototype.trim = function(strWithSpace) { var str = String(strWithSpace); return str.replace(/^\s+|\s+$/g, ""); }; // Convert "It's a Wonderful Life 2: The reckoning" into // its_a_wonderful_life_2 (suffix is like _78.jpg or _150.png) MovieHabit_Class.prototype.getPhotoTitle = function(title, suffix) { title = title.toLowerCase(); title = title.replace(/ /g, "_"); title = title.replace(/'|\-|,|\?|!|\./g, ""); title = title.replace(/_{2,}/, "_"); var posOfColon = title.indexOf(":"); if (posOfColon > -1) {title = title.substr(0, posOfColon); } if (suffix) { title = title + suffix; } return title; }; MovieHabit_Class.prototype.getInitials = function(nameOrNames) { rOut = []; if (nameOrNames.constructor == String) { var rNames = nameOrNames.split(","); } if (nameOrNames.constructor == Array) { var rNames = nameOrNames; } if (!rNames) { return false; } for (var i in rNames) { rOut.push(this._getInitials(rNames[i])); } return this.commatize(rOut); }; MovieHabit_Class.prototype._getInitials = function(singleName) { sOut = ""; rNames = singleName.match(/[^\s]+/g); for (var i in rNames) { sOut += rNames[i].substr(0, 1); } return sOut; }; MovieHabit_Class.prototype.commatize = function(rArray, glue1, glue2) { var glue1 = glue1 || ", "; var glue2 = glue2 || " and "; var last = rArray.pop(); var first = rArray.join(glue1); if (first == "") { return last; } return first + glue2 + last; }; var MovieHabit = new MovieHabit_Class(); jQuery.valt = function () { alert ("testing 3902"); }; (function($) { $.fn.labelInput = function(label) { var label = label || ""; function init () { var j = $(this); if ("" == j.val() || label == j.val()) { j.addClass("empty"); j.val(label); } j.bind("focus", this, inputFocus); j.bind("blur", this, inputBlur); j.bind("beforeSubmit", this, beforeSubmit); // custom event j.attr({title: label}); j.attr({"labeledInput": label}); j.valt = function(){alert (2392)}; } function beforeSubmit() { revertValue.apply(this); } function revertValue() { var el = $(this); if (el.val() == label) { el.val(""); } } function inputFocus (e) { // assert e.data == this var el = $(this); if (el.hasClass("empty")) { el.removeClass("empty"); revertValue.apply(this); } } function inputBlur (e) { var el = $(this); if (el.val() == "") { el.addClass("empty"); el.val(label); } } this.filter('textarea, :text').each(init); return this; }; $.fn.VAL = function () { var j = $(this); if ( j.hasClass("empty") ) { return ""; } return j.val(); }; })(jQuery);