[Jifty-commit] jifty branch, autocomplete-refactor, updated. 0e5741cd38371a507279b13f8ad6f08dd2b5f1d9
Jifty commits
jifty-commit at lists.jifty.org
Mon Mar 22 15:09:57 EDT 2010
The branch, autocomplete-refactor has been updated
via 0e5741cd38371a507279b13f8ad6f08dd2b5f1d9 (commit)
via 02c6bd06618ff88940379aed61d7812d507e89f8 (commit)
via 54a40c9c0fe6c56df1a5a55a11b5007362ab5de2 (commit)
from c893db57491b7bced53102262dd87ad2ee4cc3da (commit)
Summary of changes:
lib/Jifty/Web.pm | 4 +-
share/web/static/css/jquery.autocomplete.css | 48 ++
share/web/static/css/main.css | 2 +
share/web/static/css/thickbox.css | 163 ++++++
share/web/static/js/iautocompleter.js | 540 -----------------
share/web/static/js/jifty.js | 69 ---
share/web/static/js/jifty_interface.js | 61 --
share/web/static/js/jquery.ajaxQueue.js | 116 ++++
share/web/static/js/jquery.autocomplete.js | 808 ++++++++++++++++++++++++++
share/web/static/js/jquery.bgiframe.min.js | 10 +
10 files changed, 1150 insertions(+), 671 deletions(-)
create mode 100644 share/web/static/css/jquery.autocomplete.css
create mode 100644 share/web/static/css/thickbox.css
delete mode 100644 share/web/static/js/iautocompleter.js
create mode 100644 share/web/static/js/jquery.ajaxQueue.js
create mode 100644 share/web/static/js/jquery.autocomplete.js
create mode 100644 share/web/static/js/jquery.bgiframe.min.js
- Log -----------------------------------------------------------------
commit 54a40c9c0fe6c56df1a5a55a11b5007362ab5de2
Author: Shawn M Moore <sartak at bestpractical.com>
Date: Mon Mar 22 14:43:37 2010 -0400
Add jQuery's usual Autocomplete plugin
diff --git a/share/web/static/css/jquery.autocomplete.css b/share/web/static/css/jquery.autocomplete.css
new file mode 100644
index 0000000..91b6228
--- /dev/null
+++ b/share/web/static/css/jquery.autocomplete.css
@@ -0,0 +1,48 @@
+.ac_results {
+ padding: 0px;
+ border: 1px solid black;
+ background-color: white;
+ overflow: hidden;
+ z-index: 99999;
+}
+
+.ac_results ul {
+ width: 100%;
+ list-style-position: outside;
+ list-style: none;
+ padding: 0;
+ margin: 0;
+}
+
+.ac_results li {
+ margin: 0px;
+ padding: 2px 5px;
+ cursor: default;
+ display: block;
+ /*
+ if width will be 100% horizontal scrollbar will apear
+ when scroll mode will be used
+ */
+ /*width: 100%;*/
+ font: menu;
+ font-size: 12px;
+ /*
+ it is very important, if line-height not setted or setted
+ in relative units scroll will be broken in firefox
+ */
+ line-height: 16px;
+ overflow: hidden;
+}
+
+.ac_loading {
+ background: white url('indicator.gif') right center no-repeat;
+}
+
+.ac_odd {
+ background-color: #eee;
+}
+
+.ac_over {
+ background-color: #0A246A;
+ color: white;
+}
diff --git a/share/web/static/css/main.css b/share/web/static/css/main.css
index 098fcc5..ecd2728 100644
--- a/share/web/static/css/main.css
+++ b/share/web/static/css/main.css
@@ -15,8 +15,10 @@
@import "yui/menu/menu-core.css";
@import "yui/menu/menu.css";
@import "notices.css";
+ at import "jquery.autocomplete.css";
@import "jquery.jgrowl.css";
@import "jquery.timepickr.css";
+ at import "thickbox.css";
@import "facebox.css";
@import "datetime.css";
@import "app-late.css";
diff --git a/share/web/static/css/thickbox.css b/share/web/static/css/thickbox.css
new file mode 100644
index 0000000..d24b9be
--- /dev/null
+++ b/share/web/static/css/thickbox.css
@@ -0,0 +1,163 @@
+/* ----------------------------------------------------------------------------------------------------------------*/
+/* ---------->>> global settings needed for thickbox <<<-----------------------------------------------------------*/
+/* ----------------------------------------------------------------------------------------------------------------*/
+*{padding: 0; margin: 0;}
+
+/* ----------------------------------------------------------------------------------------------------------------*/
+/* ---------->>> thickbox specific link and font settings <<<------------------------------------------------------*/
+/* ----------------------------------------------------------------------------------------------------------------*/
+#TB_window {
+ font: 12px Arial, Helvetica, sans-serif;
+ color: #333333;
+}
+
+#TB_secondLine {
+ font: 10px Arial, Helvetica, sans-serif;
+ color:#666666;
+}
+
+#TB_window a:link {color: #666666;}
+#TB_window a:visited {color: #666666;}
+#TB_window a:hover {color: #000;}
+#TB_window a:active {color: #666666;}
+#TB_window a:focus{color: #666666;}
+
+/* ----------------------------------------------------------------------------------------------------------------*/
+/* ---------->>> thickbox settings <<<-----------------------------------------------------------------------------*/
+/* ----------------------------------------------------------------------------------------------------------------*/
+#TB_overlay {
+ position: fixed;
+ z-index:100;
+ top: 0px;
+ left: 0px;
+ height:100%;
+ width:100%;
+}
+
+.TB_overlayMacFFBGHack {background: url(macFFBgHack.png) repeat;}
+.TB_overlayBG {
+ background-color:#000;
+ filter:alpha(opacity=75);
+ -moz-opacity: 0.75;
+ opacity: 0.75;
+}
+
+* html #TB_overlay { /* ie6 hack */
+ position: absolute;
+ height: expression(document.body.scrollHeight > document.body.offsetHeight ? document.body.scrollHeight : document.body.offsetHeight + 'px');
+}
+
+#TB_window {
+ position: fixed;
+ background: #ffffff;
+ z-index: 102;
+ color:#000000;
+ display:none;
+ border: 4px solid #525252;
+ text-align:left;
+ top:50%;
+ left:50%;
+}
+
+* html #TB_window { /* ie6 hack */
+position: absolute;
+margin-top: expression(0 - parseInt(this.offsetHeight / 2) + (TBWindowMargin = document.documentElement && document.documentElement.scrollTop || document.body.scrollTop) + 'px');
+}
+
+#TB_window img#TB_Image {
+ display:block;
+ margin: 15px 0 0 15px;
+ border-right: 1px solid #ccc;
+ border-bottom: 1px solid #ccc;
+ border-top: 1px solid #666;
+ border-left: 1px solid #666;
+}
+
+#TB_caption{
+ height:25px;
+ padding:7px 30px 10px 25px;
+ float:left;
+}
+
+#TB_closeWindow{
+ height:25px;
+ padding:11px 25px 10px 0;
+ float:right;
+}
+
+#TB_closeAjaxWindow{
+ padding:7px 10px 5px 0;
+ margin-bottom:1px;
+ text-align:right;
+ float:right;
+}
+
+#TB_ajaxWindowTitle{
+ float:left;
+ padding:7px 0 5px 10px;
+ margin-bottom:1px;
+}
+
+#TB_title{
+ background-color:#e8e8e8;
+ height:27px;
+}
+
+#TB_ajaxContent{
+ clear:both;
+ padding:2px 15px 15px 15px;
+ overflow:auto;
+ text-align:left;
+ line-height:1.4em;
+}
+
+#TB_ajaxContent.TB_modal{
+ padding:15px;
+}
+
+#TB_ajaxContent p{
+ padding:5px 0px 5px 0px;
+}
+
+#TB_load{
+ position: fixed;
+ display:none;
+ height:13px;
+ width:208px;
+ z-index:103;
+ top: 50%;
+ left: 50%;
+ margin: -6px 0 0 -104px; /* -height/2 0 0 -width/2 */
+}
+
+* html #TB_load { /* ie6 hack */
+position: absolute;
+margin-top: expression(0 - parseInt(this.offsetHeight / 2) + (TBWindowMargin = document.documentElement && document.documentElement.scrollTop || document.body.scrollTop) + 'px');
+}
+
+#TB_HideSelect{
+ z-index:99;
+ position:fixed;
+ top: 0;
+ left: 0;
+ background-color:#fff;
+ border:none;
+ filter:alpha(opacity=0);
+ -moz-opacity: 0;
+ opacity: 0;
+ height:100%;
+ width:100%;
+}
+
+* html #TB_HideSelect { /* ie6 hack */
+ position: absolute;
+ height: expression(document.body.scrollHeight > document.body.offsetHeight ? document.body.scrollHeight : document.body.offsetHeight + 'px');
+}
+
+#TB_iframeContent{
+ clear:both;
+ border:none;
+ margin-bottom:-1px;
+ margin-top:1px;
+ _margin-bottom:1px;
+}
diff --git a/share/web/static/js/jquery.ajaxQueue.js b/share/web/static/js/jquery.ajaxQueue.js
new file mode 100644
index 0000000..bdd2e4f
--- /dev/null
+++ b/share/web/static/js/jquery.ajaxQueue.js
@@ -0,0 +1,116 @@
+/**
+ * Ajax Queue Plugin
+ *
+ * Homepage: http://jquery.com/plugins/project/ajaxqueue
+ * Documentation: http://docs.jquery.com/AjaxQueue
+ */
+
+/**
+
+<script>
+$(function(){
+ jQuery.ajaxQueue({
+ url: "test.php",
+ success: function(html){ jQuery("ul").append(html); }
+ });
+ jQuery.ajaxQueue({
+ url: "test.php",
+ success: function(html){ jQuery("ul").append(html); }
+ });
+ jQuery.ajaxSync({
+ url: "test.php",
+ success: function(html){ jQuery("ul").append("<b>"+html+"</b>"); }
+ });
+ jQuery.ajaxSync({
+ url: "test.php",
+ success: function(html){ jQuery("ul").append("<b>"+html+"</b>"); }
+ });
+});
+</script>
+<ul style="position: absolute; top: 5px; right: 5px;"></ul>
+
+ */
+/*
+ * Queued Ajax requests.
+ * A new Ajax request won't be started until the previous queued
+ * request has finished.
+ */
+
+/*
+ * Synced Ajax requests.
+ * The Ajax request will happen as soon as you call this method, but
+ * the callbacks (success/error/complete) won't fire until all previous
+ * synced requests have been completed.
+ */
+
+
+(function($) {
+
+ var ajax = $.ajax;
+
+ var pendingRequests = {};
+
+ var synced = [];
+ var syncedData = [];
+
+ $.ajax = function(settings) {
+ // create settings for compatibility with ajaxSetup
+ settings = jQuery.extend(settings, jQuery.extend({}, jQuery.ajaxSettings, settings));
+
+ var port = settings.port;
+
+ switch(settings.mode) {
+ case "abort":
+ if ( pendingRequests[port] ) {
+ pendingRequests[port].abort();
+ }
+ return pendingRequests[port] = ajax.apply(this, arguments);
+ case "queue":
+ var _old = settings.complete;
+ settings.complete = function(){
+ if ( _old )
+ _old.apply( this, arguments );
+ jQuery([ajax]).dequeue("ajax" + port );;
+ };
+
+ jQuery([ ajax ]).queue("ajax" + port, function(){
+ ajax( settings );
+ });
+ return;
+ case "sync":
+ var pos = synced.length;
+
+ synced[ pos ] = {
+ error: settings.error,
+ success: settings.success,
+ complete: settings.complete,
+ done: false
+ };
+
+ syncedData[ pos ] = {
+ error: [],
+ success: [],
+ complete: []
+ };
+
+ settings.error = function(){ syncedData[ pos ].error = arguments; };
+ settings.success = function(){ syncedData[ pos ].success = arguments; };
+ settings.complete = function(){
+ syncedData[ pos ].complete = arguments;
+ synced[ pos ].done = true;
+
+ if ( pos == 0 || !synced[ pos-1 ] )
+ for ( var i = pos; i < synced.length && synced[i].done; i++ ) {
+ if ( synced[i].error ) synced[i].error.apply( jQuery, syncedData[i].error );
+ if ( synced[i].success ) synced[i].success.apply( jQuery, syncedData[i].success );
+ if ( synced[i].complete ) synced[i].complete.apply( jQuery, syncedData[i].complete );
+
+ synced[i] = null;
+ syncedData[i] = null;
+ }
+ };
+ }
+ return ajax.apply(this, arguments);
+ };
+
+})(jQuery);
\ No newline at end of file
diff --git a/share/web/static/js/jquery.autocomplete.js b/share/web/static/js/jquery.autocomplete.js
new file mode 100644
index 0000000..9d12a29
--- /dev/null
+++ b/share/web/static/js/jquery.autocomplete.js
@@ -0,0 +1,808 @@
+/*
+ * jQuery Autocomplete plugin 1.1
+ *
+ * Copyright (c) 2009 Jörn Zaefferer
+ *
+ * Dual licensed under the MIT and GPL licenses:
+ * http://www.opensource.org/licenses/mit-license.php
+ * http://www.gnu.org/licenses/gpl.html
+ *
+ * Revision: $Id: jquery.autocomplete.js 15 2009-08-22 10:30:27Z joern.zaefferer $
+ */
+
+;(function($) {
+
+$.fn.extend({
+ autocomplete: function(urlOrData, options) {
+ var isUrl = typeof urlOrData == "string";
+ options = $.extend({}, $.Autocompleter.defaults, {
+ url: isUrl ? urlOrData : null,
+ data: isUrl ? null : urlOrData,
+ delay: isUrl ? $.Autocompleter.defaults.delay : 10,
+ max: options && !options.scroll ? 10 : 150
+ }, options);
+
+ // if highlight is set to false, replace it with a do-nothing function
+ options.highlight = options.highlight || function(value) { return value; };
+
+ // if the formatMatch option is not specified, then use formatItem for backwards compatibility
+ options.formatMatch = options.formatMatch || options.formatItem;
+
+ return this.each(function() {
+ new $.Autocompleter(this, options);
+ });
+ },
+ result: function(handler) {
+ return this.bind("result", handler);
+ },
+ search: function(handler) {
+ return this.trigger("search", [handler]);
+ },
+ flushCache: function() {
+ return this.trigger("flushCache");
+ },
+ setOptions: function(options){
+ return this.trigger("setOptions", [options]);
+ },
+ unautocomplete: function() {
+ return this.trigger("unautocomplete");
+ }
+});
+
+$.Autocompleter = function(input, options) {
+
+ var KEY = {
+ UP: 38,
+ DOWN: 40,
+ DEL: 46,
+ TAB: 9,
+ RETURN: 13,
+ ESC: 27,
+ COMMA: 188,
+ PAGEUP: 33,
+ PAGEDOWN: 34,
+ BACKSPACE: 8
+ };
+
+ // Create $ object for input element
+ var $input = $(input).attr("autocomplete", "off").addClass(options.inputClass);
+
+ var timeout;
+ var previousValue = "";
+ var cache = $.Autocompleter.Cache(options);
+ var hasFocus = 0;
+ var lastKeyPressCode;
+ var config = {
+ mouseDownOnSelect: false
+ };
+ var select = $.Autocompleter.Select(options, input, selectCurrent, config);
+
+ var blockSubmit;
+
+ // prevent form submit in opera when selecting with return key
+ $.browser.opera && $(input.form).bind("submit.autocomplete", function() {
+ if (blockSubmit) {
+ blockSubmit = false;
+ return false;
+ }
+ });
+
+ // only opera doesn't trigger keydown multiple times while pressed, others don't work with keypress at all
+ $input.bind(($.browser.opera ? "keypress" : "keydown") + ".autocomplete", function(event) {
+ // a keypress means the input has focus
+ // avoids issue where input had focus before the autocomplete was applied
+ hasFocus = 1;
+ // track last key pressed
+ lastKeyPressCode = event.keyCode;
+ switch(event.keyCode) {
+
+ case KEY.UP:
+ event.preventDefault();
+ if ( select.visible() ) {
+ select.prev();
+ } else {
+ onChange(0, true);
+ }
+ break;
+
+ case KEY.DOWN:
+ event.preventDefault();
+ if ( select.visible() ) {
+ select.next();
+ } else {
+ onChange(0, true);
+ }
+ break;
+
+ case KEY.PAGEUP:
+ event.preventDefault();
+ if ( select.visible() ) {
+ select.pageUp();
+ } else {
+ onChange(0, true);
+ }
+ break;
+
+ case KEY.PAGEDOWN:
+ event.preventDefault();
+ if ( select.visible() ) {
+ select.pageDown();
+ } else {
+ onChange(0, true);
+ }
+ break;
+
+ // matches also semicolon
+ case options.multiple && $.trim(options.multipleSeparator) == "," && KEY.COMMA:
+ case KEY.TAB:
+ case KEY.RETURN:
+ if( selectCurrent() ) {
+ // stop default to prevent a form submit, Opera needs special handling
+ event.preventDefault();
+ blockSubmit = true;
+ return false;
+ }
+ break;
+
+ case KEY.ESC:
+ select.hide();
+ break;
+
+ default:
+ clearTimeout(timeout);
+ timeout = setTimeout(onChange, options.delay);
+ break;
+ }
+ }).focus(function(){
+ // track whether the field has focus, we shouldn't process any
+ // results if the field no longer has focus
+ hasFocus++;
+ }).blur(function() {
+ hasFocus = 0;
+ if (!config.mouseDownOnSelect) {
+ hideResults();
+ }
+ }).click(function() {
+ // show select when clicking in a focused field
+ if ( hasFocus++ > 1 && !select.visible() ) {
+ onChange(0, true);
+ }
+ }).bind("search", function() {
+ // TODO why not just specifying both arguments?
+ var fn = (arguments.length > 1) ? arguments[1] : null;
+ function findValueCallback(q, data) {
+ var result;
+ if( data && data.length ) {
+ for (var i=0; i < data.length; i++) {
+ if( data[i].result.toLowerCase() == q.toLowerCase() ) {
+ result = data[i];
+ break;
+ }
+ }
+ }
+ if( typeof fn == "function" ) fn(result);
+ else $input.trigger("result", result && [result.data, result.value]);
+ }
+ $.each(trimWords($input.val()), function(i, value) {
+ request(value, findValueCallback, findValueCallback);
+ });
+ }).bind("flushCache", function() {
+ cache.flush();
+ }).bind("setOptions", function() {
+ $.extend(options, arguments[1]);
+ // if we've updated the data, repopulate
+ if ( "data" in arguments[1] )
+ cache.populate();
+ }).bind("unautocomplete", function() {
+ select.unbind();
+ $input.unbind();
+ $(input.form).unbind(".autocomplete");
+ });
+
+
+ function selectCurrent() {
+ var selected = select.selected();
+ if( !selected )
+ return false;
+
+ var v = selected.result;
+ previousValue = v;
+
+ if ( options.multiple ) {
+ var words = trimWords($input.val());
+ if ( words.length > 1 ) {
+ var seperator = options.multipleSeparator.length;
+ var cursorAt = $(input).selection().start;
+ var wordAt, progress = 0;
+ $.each(words, function(i, word) {
+ progress += word.length;
+ if (cursorAt <= progress) {
+ wordAt = i;
+ return false;
+ }
+ progress += seperator;
+ });
+ words[wordAt] = v;
+ // TODO this should set the cursor to the right position, but it gets overriden somewhere
+ //$.Autocompleter.Selection(input, progress + seperator, progress + seperator);
+ v = words.join( options.multipleSeparator );
+ }
+ v += options.multipleSeparator;
+ }
+
+ $input.val(v);
+ hideResultsNow();
+ $input.trigger("result", [selected.data, selected.value]);
+ return true;
+ }
+
+ function onChange(crap, skipPrevCheck) {
+ if( lastKeyPressCode == KEY.DEL ) {
+ select.hide();
+ return;
+ }
+
+ var currentValue = $input.val();
+
+ if ( !skipPrevCheck && currentValue == previousValue )
+ return;
+
+ previousValue = currentValue;
+
+ currentValue = lastWord(currentValue);
+ if ( currentValue.length >= options.minChars) {
+ $input.addClass(options.loadingClass);
+ if (!options.matchCase)
+ currentValue = currentValue.toLowerCase();
+ request(currentValue, receiveData, hideResultsNow);
+ } else {
+ stopLoading();
+ select.hide();
+ }
+ };
+
+ function trimWords(value) {
+ if (!value)
+ return [""];
+ if (!options.multiple)
+ return [$.trim(value)];
+ return $.map(value.split(options.multipleSeparator), function(word) {
+ return $.trim(value).length ? $.trim(word) : null;
+ });
+ }
+
+ function lastWord(value) {
+ if ( !options.multiple )
+ return value;
+ var words = trimWords(value);
+ if (words.length == 1)
+ return words[0];
+ var cursorAt = $(input).selection().start;
+ if (cursorAt == value.length) {
+ words = trimWords(value)
+ } else {
+ words = trimWords(value.replace(value.substring(cursorAt), ""));
+ }
+ return words[words.length - 1];
+ }
+
+ // fills in the input box w/the first match (assumed to be the best match)
+ // q: the term entered
+ // sValue: the first matching result
+ function autoFill(q, sValue){
+ // autofill in the complete box w/the first match as long as the user hasn't entered in more data
+ // if the last user key pressed was backspace, don't autofill
+ if( options.autoFill && (lastWord($input.val()).toLowerCase() == q.toLowerCase()) && lastKeyPressCode != KEY.BACKSPACE ) {
+ // fill in the value (keep the case the user has typed)
+ $input.val($input.val() + sValue.substring(lastWord(previousValue).length));
+ // select the portion of the value not typed by the user (so the next character will erase)
+ $(input).selection(previousValue.length, previousValue.length + sValue.length);
+ }
+ };
+
+ function hideResults() {
+ clearTimeout(timeout);
+ timeout = setTimeout(hideResultsNow, 200);
+ };
+
+ function hideResultsNow() {
+ var wasVisible = select.visible();
+ select.hide();
+ clearTimeout(timeout);
+ stopLoading();
+ if (options.mustMatch) {
+ // call search and run callback
+ $input.search(
+ function (result){
+ // if no value found, clear the input box
+ if( !result ) {
+ if (options.multiple) {
+ var words = trimWords($input.val()).slice(0, -1);
+ $input.val( words.join(options.multipleSeparator) + (words.length ? options.multipleSeparator : "") );
+ }
+ else {
+ $input.val( "" );
+ $input.trigger("result", null);
+ }
+ }
+ }
+ );
+ }
+ };
+
+ function receiveData(q, data) {
+ if ( data && data.length && hasFocus ) {
+ stopLoading();
+ select.display(data, q);
+ autoFill(q, data[0].value);
+ select.show();
+ } else {
+ hideResultsNow();
+ }
+ };
+
+ function request(term, success, failure) {
+ if (!options.matchCase)
+ term = term.toLowerCase();
+ var data = cache.load(term);
+ // recieve the cached data
+ if (data && data.length) {
+ success(term, data);
+ // if an AJAX url has been supplied, try loading the data now
+ } else if( (typeof options.url == "string") && (options.url.length > 0) ){
+
+ var extraParams = {
+ timestamp: +new Date()
+ };
+ $.each(options.extraParams, function(key, param) {
+ extraParams[key] = typeof param == "function" ? param() : param;
+ });
+
+ $.ajax({
+ // try to leverage ajaxQueue plugin to abort previous requests
+ mode: "abort",
+ // limit abortion to this input
+ port: "autocomplete" + input.name,
+ dataType: options.dataType,
+ url: options.url,
+ data: $.extend({
+ q: lastWord(term),
+ limit: options.max
+ }, extraParams),
+ success: function(data) {
+ var parsed = options.parse && options.parse(data) || parse(data);
+ cache.add(term, parsed);
+ success(term, parsed);
+ }
+ });
+ } else {
+ // if we have a failure, we need to empty the list -- this prevents the the [TAB] key from selecting the last successful match
+ select.emptyList();
+ failure(term);
+ }
+ };
+
+ function parse(data) {
+ var parsed = [];
+ var rows = data.split("\n");
+ for (var i=0; i < rows.length; i++) {
+ var row = $.trim(rows[i]);
+ if (row) {
+ row = row.split("|");
+ parsed[parsed.length] = {
+ data: row,
+ value: row[0],
+ result: options.formatResult && options.formatResult(row, row[0]) || row[0]
+ };
+ }
+ }
+ return parsed;
+ };
+
+ function stopLoading() {
+ $input.removeClass(options.loadingClass);
+ };
+
+};
+
+$.Autocompleter.defaults = {
+ inputClass: "ac_input",
+ resultsClass: "ac_results",
+ loadingClass: "ac_loading",
+ minChars: 1,
+ delay: 400,
+ matchCase: false,
+ matchSubset: true,
+ matchContains: false,
+ cacheLength: 10,
+ max: 100,
+ mustMatch: false,
+ extraParams: {},
+ selectFirst: true,
+ formatItem: function(row) { return row[0]; },
+ formatMatch: null,
+ autoFill: false,
+ width: 0,
+ multiple: false,
+ multipleSeparator: ", ",
+ highlight: function(value, term) {
+ return value.replace(new RegExp("(?![^&;]+;)(?!<[^<>]*)(" + term.replace(/([\^\$\(\)\[\]\{\}\*\.\+\?\|\\])/gi, "\\$1") + ")(?![^<>]*>)(?![^&;]+;)", "gi"), "<strong>$1</strong>");
+ },
+ scroll: true,
+ scrollHeight: 180
+};
+
+$.Autocompleter.Cache = function(options) {
+
+ var data = {};
+ var length = 0;
+
+ function matchSubset(s, sub) {
+ if (!options.matchCase)
+ s = s.toLowerCase();
+ var i = s.indexOf(sub);
+ if (options.matchContains == "word"){
+ i = s.toLowerCase().search("\\b" + sub.toLowerCase());
+ }
+ if (i == -1) return false;
+ return i == 0 || options.matchContains;
+ };
+
+ function add(q, value) {
+ if (length > options.cacheLength){
+ flush();
+ }
+ if (!data[q]){
+ length++;
+ }
+ data[q] = value;
+ }
+
+ function populate(){
+ if( !options.data ) return false;
+ // track the matches
+ var stMatchSets = {},
+ nullData = 0;
+
+ // no url was specified, we need to adjust the cache length to make sure it fits the local data store
+ if( !options.url ) options.cacheLength = 1;
+
+ // track all options for minChars = 0
+ stMatchSets[""] = [];
+
+ // loop through the array and create a lookup structure
+ for ( var i = 0, ol = options.data.length; i < ol; i++ ) {
+ var rawValue = options.data[i];
+ // if rawValue is a string, make an array otherwise just reference the array
+ rawValue = (typeof rawValue == "string") ? [rawValue] : rawValue;
+
+ var value = options.formatMatch(rawValue, i+1, options.data.length);
+ if ( value === false )
+ continue;
+
+ var firstChar = value.charAt(0).toLowerCase();
+ // if no lookup array for this character exists, look it up now
+ if( !stMatchSets[firstChar] )
+ stMatchSets[firstChar] = [];
+
+ // if the match is a string
+ var row = {
+ value: value,
+ data: rawValue,
+ result: options.formatResult && options.formatResult(rawValue) || value
+ };
+
+ // push the current match into the set list
+ stMatchSets[firstChar].push(row);
+
+ // keep track of minChars zero items
+ if ( nullData++ < options.max ) {
+ stMatchSets[""].push(row);
+ }
+ };
+
+ // add the data items to the cache
+ $.each(stMatchSets, function(i, value) {
+ // increase the cache size
+ options.cacheLength++;
+ // add to the cache
+ add(i, value);
+ });
+ }
+
+ // populate any existing data
+ setTimeout(populate, 25);
+
+ function flush(){
+ data = {};
+ length = 0;
+ }
+
+ return {
+ flush: flush,
+ add: add,
+ populate: populate,
+ load: function(q) {
+ if (!options.cacheLength || !length)
+ return null;
+ /*
+ * if dealing w/local data and matchContains than we must make sure
+ * to loop through all the data collections looking for matches
+ */
+ if( !options.url && options.matchContains ){
+ // track all matches
+ var csub = [];
+ // loop through all the data grids for matches
+ for( var k in data ){
+ // don't search through the stMatchSets[""] (minChars: 0) cache
+ // this prevents duplicates
+ if( k.length > 0 ){
+ var c = data[k];
+ $.each(c, function(i, x) {
+ // if we've got a match, add it to the array
+ if (matchSubset(x.value, q)) {
+ csub.push(x);
+ }
+ });
+ }
+ }
+ return csub;
+ } else
+ // if the exact item exists, use it
+ if (data[q]){
+ return data[q];
+ } else
+ if (options.matchSubset) {
+ for (var i = q.length - 1; i >= options.minChars; i--) {
+ var c = data[q.substr(0, i)];
+ if (c) {
+ var csub = [];
+ $.each(c, function(i, x) {
+ if (matchSubset(x.value, q)) {
+ csub[csub.length] = x;
+ }
+ });
+ return csub;
+ }
+ }
+ }
+ return null;
+ }
+ };
+};
+
+$.Autocompleter.Select = function (options, input, select, config) {
+ var CLASSES = {
+ ACTIVE: "ac_over"
+ };
+
+ var listItems,
+ active = -1,
+ data,
+ term = "",
+ needsInit = true,
+ element,
+ list;
+
+ // Create results
+ function init() {
+ if (!needsInit)
+ return;
+ element = $("<div/>")
+ .hide()
+ .addClass(options.resultsClass)
+ .css("position", "absolute")
+ .appendTo(document.body);
+
+ list = $("<ul/>").appendTo(element).mouseover( function(event) {
+ if(target(event).nodeName && target(event).nodeName.toUpperCase() == 'LI') {
+ active = $("li", list).removeClass(CLASSES.ACTIVE).index(target(event));
+ $(target(event)).addClass(CLASSES.ACTIVE);
+ }
+ }).click(function(event) {
+ $(target(event)).addClass(CLASSES.ACTIVE);
+ select();
+ // TODO provide option to avoid setting focus again after selection? useful for cleanup-on-focus
+ input.focus();
+ return false;
+ }).mousedown(function() {
+ config.mouseDownOnSelect = true;
+ }).mouseup(function() {
+ config.mouseDownOnSelect = false;
+ });
+
+ if( options.width > 0 )
+ element.css("width", options.width);
+
+ needsInit = false;
+ }
+
+ function target(event) {
+ var element = event.target;
+ while(element && element.tagName != "LI")
+ element = element.parentNode;
+ // more fun with IE, sometimes event.target is empty, just ignore it then
+ if(!element)
+ return [];
+ return element;
+ }
+
+ function moveSelect(step) {
+ listItems.slice(active, active + 1).removeClass(CLASSES.ACTIVE);
+ movePosition(step);
+ var activeItem = listItems.slice(active, active + 1).addClass(CLASSES.ACTIVE);
+ if(options.scroll) {
+ var offset = 0;
+ listItems.slice(0, active).each(function() {
+ offset += this.offsetHeight;
+ });
+ if((offset + activeItem[0].offsetHeight - list.scrollTop()) > list[0].clientHeight) {
+ list.scrollTop(offset + activeItem[0].offsetHeight - list.innerHeight());
+ } else if(offset < list.scrollTop()) {
+ list.scrollTop(offset);
+ }
+ }
+ };
+
+ function movePosition(step) {
+ active += step;
+ if (active < 0) {
+ active = listItems.size() - 1;
+ } else if (active >= listItems.size()) {
+ active = 0;
+ }
+ }
+
+ function limitNumberOfItems(available) {
+ return options.max && options.max < available
+ ? options.max
+ : available;
+ }
+
+ function fillList() {
+ list.empty();
+ var max = limitNumberOfItems(data.length);
+ for (var i=0; i < max; i++) {
+ if (!data[i])
+ continue;
+ var formatted = options.formatItem(data[i].data, i+1, max, data[i].value, term);
+ if ( formatted === false )
+ continue;
+ var li = $("<li/>").html( options.highlight(formatted, term) ).addClass(i%2 == 0 ? "ac_even" : "ac_odd").appendTo(list)[0];
+ $.data(li, "ac_data", data[i]);
+ }
+ listItems = list.find("li");
+ if ( options.selectFirst ) {
+ listItems.slice(0, 1).addClass(CLASSES.ACTIVE);
+ active = 0;
+ }
+ // apply bgiframe if available
+ if ( $.fn.bgiframe )
+ list.bgiframe();
+ }
+
+ return {
+ display: function(d, q) {
+ init();
+ data = d;
+ term = q;
+ fillList();
+ },
+ next: function() {
+ moveSelect(1);
+ },
+ prev: function() {
+ moveSelect(-1);
+ },
+ pageUp: function() {
+ if (active != 0 && active - 8 < 0) {
+ moveSelect( -active );
+ } else {
+ moveSelect(-8);
+ }
+ },
+ pageDown: function() {
+ if (active != listItems.size() - 1 && active + 8 > listItems.size()) {
+ moveSelect( listItems.size() - 1 - active );
+ } else {
+ moveSelect(8);
+ }
+ },
+ hide: function() {
+ element && element.hide();
+ listItems && listItems.removeClass(CLASSES.ACTIVE);
+ active = -1;
+ },
+ visible : function() {
+ return element && element.is(":visible");
+ },
+ current: function() {
+ return this.visible() && (listItems.filter("." + CLASSES.ACTIVE)[0] || options.selectFirst && listItems[0]);
+ },
+ show: function() {
+ var offset = $(input).offset();
+ element.css({
+ width: typeof options.width == "string" || options.width > 0 ? options.width : $(input).width(),
+ top: offset.top + input.offsetHeight,
+ left: offset.left
+ }).show();
+ if(options.scroll) {
+ list.scrollTop(0);
+ list.css({
+ maxHeight: options.scrollHeight,
+ overflow: 'auto'
+ });
+
+ if($.browser.msie && typeof document.body.style.maxHeight === "undefined") {
+ var listHeight = 0;
+ listItems.each(function() {
+ listHeight += this.offsetHeight;
+ });
+ var scrollbarsVisible = listHeight > options.scrollHeight;
+ list.css('height', scrollbarsVisible ? options.scrollHeight : listHeight );
+ if (!scrollbarsVisible) {
+ // IE doesn't recalculate width when scrollbar disappears
+ listItems.width( list.width() - parseInt(listItems.css("padding-left")) - parseInt(listItems.css("padding-right")) );
+ }
+ }
+
+ }
+ },
+ selected: function() {
+ var selected = listItems && listItems.filter("." + CLASSES.ACTIVE).removeClass(CLASSES.ACTIVE);
+ return selected && selected.length && $.data(selected[0], "ac_data");
+ },
+ emptyList: function (){
+ list && list.empty();
+ },
+ unbind: function() {
+ element && element.remove();
+ }
+ };
+};
+
+$.fn.selection = function(start, end) {
+ if (start !== undefined) {
+ return this.each(function() {
+ if( this.createTextRange ){
+ var selRange = this.createTextRange();
+ if (end === undefined || start == end) {
+ selRange.move("character", start);
+ selRange.select();
+ } else {
+ selRange.collapse(true);
+ selRange.moveStart("character", start);
+ selRange.moveEnd("character", end);
+ selRange.select();
+ }
+ } else if( this.setSelectionRange ){
+ this.setSelectionRange(start, end);
+ } else if( this.selectionStart ){
+ this.selectionStart = start;
+ this.selectionEnd = end;
+ }
+ });
+ }
+ var field = this[0];
+ if ( field.createTextRange ) {
+ var range = document.selection.createRange(),
+ orig = field.value,
+ teststring = "<->",
+ textLength = range.text.length;
+ range.text = teststring;
+ var caretAt = field.value.indexOf(teststring);
+ field.value = orig;
+ this.selection(caretAt, caretAt + textLength);
+ return {
+ start: caretAt,
+ end: caretAt + textLength
+ }
+ } else if( field.selectionStart !== undefined ){
+ return {
+ start: field.selectionStart,
+ end: field.selectionEnd
+ }
+ }
+};
+
+})(jQuery);
\ No newline at end of file
diff --git a/share/web/static/js/jquery.bgiframe.min.js b/share/web/static/js/jquery.bgiframe.min.js
new file mode 100644
index 0000000..7faef4b
--- /dev/null
+++ b/share/web/static/js/jquery.bgiframe.min.js
@@ -0,0 +1,10 @@
+/* Copyright (c) 2006 Brandon Aaron (http://brandonaaron.net)
+ * Dual licensed under the MIT (http://www.opensource.org/licenses/mit-license.php)
+ * and GPL (http://www.opensource.org/licenses/gpl-license.php) licenses.
+ *
+ * $LastChangedDate: 2007-07-22 01:45:56 +0200 (Son, 22 Jul 2007) $
+ * $Rev: 2447 $
+ *
+ * Version 2.1.1
+ */
+(function($){$.fn.bgIframe=$.fn.bgiframe=function(s){if($.browser.msie&&/6.0/.test(navigator.userAgent)){s=$.extend({top:'auto',left:'auto',width:'auto',height:'auto',opacity:true,src:'javascript:false;'},s||{});var prop=function(n){return n&&n.constructor==Number?n+'px':n;},html='<iframe class="bgiframe"frameborder="0"tabindex="-1"src="'+s.src+'"'+'style="display:block;position:absolute;z-index:-1;'+(s.opacity!==false?'filter:Alpha(Opacity=\'0\');':'')+'top:'+(s.top=='auto'?'expression(((parseInt(this.parentNode.currentStyle.borderTopWidth)||0)*-1)+\'px\')':prop(s.top))+';'+'left:'+(s.left=='auto'?'expression(((parseInt(this.parentNode.currentStyle.borderLeftWidth)||0)*-1)+\'px\')':prop(s.left))+';'+'width:'+(s.width=='auto'?'expression(this.parentNode.offsetWidth+\'px\')':prop(s.width))+';'+'height:'+(s.height=='auto'?'expression(this.parentNode.offsetHeight+\'px\')':prop(s.height))+';'+'"/>';return this.each(function(){if($('> iframe.bgiframe',this).length==0)this.insertB
efore(document.createElement(html),this.firstChild);});}return this;};})(jQuery);
\ No newline at end of file
commit 02c6bd06618ff88940379aed61d7812d507e89f8
Author: Shawn M Moore <sartak at bestpractical.com>
Date: Mon Mar 22 14:58:33 2010 -0400
Remove previous jifty autocomplete implementation
diff --git a/share/web/static/js/iautocompleter.js b/share/web/static/js/iautocompleter.js
deleted file mode 100644
index 4210fca..0000000
--- a/share/web/static/js/iautocompleter.js
+++ /dev/null
@@ -1,540 +0,0 @@
-/**
- * Interface Elements for jQuery
- * Autocompleter
- *
- * http://interface.eyecon.ro
- *
- * Copyright (c) 2006 Stefan Petre
- * Dual licensed under the MIT (MIT-LICENSE.txt)
- * and GPL (GPL-LICENSE.txt) licenses.
- *
- */
-
-/**
- * Attach AJAX driven autocomplete/sugestion box to text input fields.
- *
- *
- *
- * @name Autocomplete
- * @description Attach AJAX driven autocomplete/sugestion box to text input fields.
- * @param Hash hash A hash of parameters
- * @option String source the URL to request
- * @option Integer delay (optional) the delayed time to start the AJAX request
- * @option Boolean autofill (optional) when true the first sugested value fills the input
- * @option String helperClass (optional) the CSS class applied to sugestion box
- * @option String selectClass (optional) the CSS class applied to selected/hovered item
- * @option Integer minchars (optional) the number of characters needed before starting AJAX request
- * @option Hash fx (optional) {type:[slide|blind|fade]; duration: integer} the fx type to apply to sugestion box and duration for that fx
- * @option Function onSelect (optional) A function to be executed whenever an item it is selected
- * @option Function onShow (optional) A function to be executed whenever the suggection box is displayed
- * @option Function onHide (optional) A function to be executed whenever the suggection box is hidden
- * @option Function onHighlight (optional) A function to be executed whenever an item it is highlighted
- *
- * @type jQuery
- * @cat Plugins/Interface
- * @author Stefan Petre
- */
-jQuery.iAuto = {
- helper : null,
- content : null,
- iframe: null,
- timer : null,
- lastValue: null,
- currentValue: null,
- subject: null,
- selectedItem : null,
- items: null,
-
- empty : function()
- {
- jQuery.iAuto.content.empty();
- if (jQuery.iAuto.iframe) {
- jQuery.iAuto.iframe.hide();
- }
- },
-
- clear : function()
- {
- jQuery.iAuto.items = null;
- jQuery.iAuto.selectedItem = null;
- jQuery.iAuto.lastValue = jQuery.iAuto.subject.value;
- if(jQuery.iAuto.helper.css('display') == 'block') {
- if (jQuery.iAuto.subject.autoCFG.fx) {
- switch(jQuery.iAuto.subject.autoCFG.fx.type) {
- case 'fade':
- jQuery.iAuto.helper.fadeOut(jQuery.iAuto.subject.autoCFG.fx.duration, jQuery.iAuto.empty);
- break;
- case 'slide':
- jQuery.iAuto.helper.SlideOutUp(jQuery.iAuto.subject.autoCFG.fx.duration, jQuery.iAuto.empty);
- break;
- case 'blind':
- jQuery.iAuto.helper.BlindUp(jQuery.iAuto.subject.autoCFG.fx.duration, jQuery.iAuto.empty);
- break;
- }
- } else {
- jQuery.iAuto.helper.hide();
-
- if (jQuery.iAuto.iframe)
- jQuery.iAuto.iframe.hide();
-
- }
- if (jQuery.iAuto.subject.autoCFG.onHide)
- jQuery.iAuto.subject.autoCFG.onHide.apply(jQuery.iAuto.subject, [jQuery.iAuto.helper, jQuery.iAuto.iframe]);
- } else {
- jQuery.iAuto.empty();
- }
- window.clearTimeout(jQuery.iAuto.timer);
- },
-
- update : function ()
- {
- var subject = jQuery.iAuto.subject;
- var subjectValue = jQuery.iAuto.getFieldValues(subject);
- //var selectionStart = jQuery.iAuto.getSelectionStart(subject);
- if (subject && subjectValue.item != jQuery.iAuto.lastValue && subjectValue.item.length >= subject.autoCFG.minchars) {
- jQuery.iAuto.lastValue = subjectValue.item;
- jQuery.iAuto.currentValue = subjectValue.item;
-
- data = {
- field: jQuery(subject).attr('name')||'field',
- value: subjectValue.item
- };
-
- jQuery.ajax(
- {
- type: 'POST',
- data: jQuery.param(data),
- success: function(xml)
- {
- subject.autoCFG.lastSuggestion = jQuery('item',xml);
- size = subject.autoCFG.lastSuggestion.size();
- if (size > 0) {
- var toWrite = '';
- subject.autoCFG.lastSuggestion.each(
- function(nr)
- {
- toWrite += '<li rel="' + jQuery('value', this).text() + '" dir="' + nr + '" style="cursor: default;">' + jQuery('text', this).text() + '</li>';
- }
- );
- if (subject.autoCFG.autofill) {
- var valueToAdd = jQuery('value', subject.autoCFG.lastSuggestion.get(0)).text();
- subject.value = subjectValue.pre + valueToAdd + subject.autoCFG.multipleSeparator + subjectValue.post;
- jQuery.iAuto.selection(
- subject,
- subjectValue.item.length != valueToAdd.length ? (subjectValue.pre.length + subjectValue.item.length) : valueToAdd.length,
- subjectValue.item.length != valueToAdd.length ? (subjectValue.pre.length + valueToAdd.length) : valueToAdd.length
- );
- }
-
- if (size > 0) {
- jQuery.iAuto.writeItems(subject, toWrite);
- } else {
- jQuery.iAuto.clear();
- }
- } else {
- jQuery.iAuto.clear();
- }
- },
- url : subject.autoCFG.source
- }
- );
- }
- },
-
- writeItems : function(subject, toWrite)
- {
- jQuery.iAuto.content.html(toWrite);
- jQuery.iAuto.items = jQuery('li', jQuery.iAuto.content.get(0));
- jQuery.iAuto.items
- .mouseover(jQuery.iAuto.hoverItem)
- .bind('mousedown', jQuery.iAuto.clickItem);
- var position = jQuery(subject).position();
- var size = jQuery.iUtil.getSize(subject);
- jQuery.iAuto.helper
- .css('top', position.top + size.hb + 'px')
- .css('left', position.left + 'px')
- .addClass(subject.autoCFG.helperClass);
- if (jQuery.iAuto.iframe) {
- jQuery.iAuto.iframe
- .css('display', 'block')
- .css('top', position.top + size.hb + 'px')
- .css('left', position.left + 'px')
- .css('width', jQuery.iAuto.helper.width() )
- .css('height', jQuery.iAuto.helper.height() );
- }
- jQuery.iAuto.selectedItem = 0;
- jQuery.iAuto.items.get(0).className = subject.autoCFG.selectClass;
- jQuery.iAuto.applyOn(subject,subject.autoCFG.lastSuggestion.get(0), 'onHighlight');
-
- if (jQuery.iAuto.helper.css('display') == 'none') {
- if (subject.autoCFG.inputWidth) {
- var borders = jQuery.iUtil.getPadding(subject, true);
- var paddings = jQuery.iUtil.getBorder(subject, true);
- jQuery.iAuto.helper.css('width', subject.offsetWidth - (jQuery.boxModel ? (borders.l + borders.r + paddings.l + paddings.r) : 0 ) + 'px');
- }
- if (subject.autoCFG.fx) {
- switch(subject.autoCFG.fx.type) {
- case 'fade':
- jQuery.iAuto.helper.fadeIn(subject.autoCFG.fx.duration);
- break;
- case 'slide':
- jQuery.iAuto.helper.SlideInUp(subject.autoCFG.fx.duration);
- break;
- case 'blind':
- jQuery.iAuto.helper.BlindDown(subject.autoCFG.fx.duration);
- break;
- }
- } else {
- jQuery.iAuto.helper.show();
- }
-
- if (jQuery.iAuto.subject.autoCFG.onShow)
- jQuery.iAuto.subject.autoCFG.onShow.apply(jQuery.iAuto.subject, [jQuery.iAuto.helper, jQuery.iAuto.iframe]);
- }
- },
-
- checkCache : function()
- {
- var subject = this;
- if (subject.autoCFG.lastSuggestion) {
-
- jQuery.iAuto.lastValue = subject.value;
- jQuery.iAuto.currentValue = subject.value;
-
- var toWrite = '';
- subject.autoCFG.lastSuggestion.each(
- function(nr)
- {
- value = jQuery('value', this).text().toLowerCase();
- inputValue = subject.value.toLowerCase();
- if (value.indexOf(inputValue) == 0) {
- toWrite += '<li rel="' + jQuery('value', this).text() + '" dir="' + nr + '" style="cursor: default;">' + jQuery('text', this).text() + '</li>';
- }
- }
- );
-
- if (toWrite != '') {
- jQuery.iAuto.writeItems(subject, toWrite);
-
- this.autoCFG.inCache = true;
- return;
- }
- }
- subject.autoCFG.lastSuggestion = null;
- this.autoCFG.inCache = false;
- },
-
- selection : function(field, start, end)
- {
- if (field.createTextRange) {
- var selRange = field.createTextRange();
- selRange.collapse(true);
- selRange.moveStart("character", start);
- selRange.moveEnd("character", - end + start);
- selRange.select();
- } else if (field.setSelectionRange) {
- field.setSelectionRange(start, end);
- } else {
- if (field.selectionStart) {
- field.selectionStart = start;
- field.selectionEnd = end;
- }
- }
- field.focus();
- },
-
- getSelectionStart : function(field)
- {
- if (field.selectionStart)
- return field.selectionStart;
- else if(field.createTextRange) {
- var selRange = document.selection.createRange();
- var selRange2 = selRange.duplicate();
- return 0 - selRange2.moveStart('character', -100000);
- //result.end = result.start + range.text.length;
- /*var selRange = document.selection.createRange();
- var isCollapsed = selRange.compareEndPoints("StartToEnd", selRange) == 0;
- if (!isCollapsed)
- selRange.collapse(true);
- var bookmark = selRange.getBookmark();
- return bookmark.charCodeAt(2) - 2;*/
- }
- },
-
- getFieldValues : function(field)
- {
- var fieldData = {
- value: field.value,
- pre: '',
- post: '',
- item: ''
- };
-
- if(field.autoCFG.multiple) {
- var finishedPre = false;
- var selectionStart = jQuery.iAuto.getSelectionStart(field)||0;
- var chunks = fieldData.value.split(field.autoCFG.multipleSeparator);
- for (var i=0; i<chunks.length; i++) {
- if(
- (fieldData.pre.length + chunks[i].length >= selectionStart
- ||
- selectionStart == 0)
- &&
- !finishedPre
- ) {
- if (fieldData.pre.length <= selectionStart)
- fieldData.item = chunks[i];
- else
- fieldData.post += chunks[i] + (chunks[i] != '' ? field.autoCFG.multipleSeparator : '');
- finishedPre = true;
- } else if (finishedPre){
- fieldData.post += chunks[i] + (chunks[i] != '' ? field.autoCFG.multipleSeparator : '');
- }
- if(!finishedPre) {
- fieldData.pre += chunks[i] + (chunks.length > 1 ? field.autoCFG.multipleSeparator : '');
- }
- }
- } else {
- fieldData.item = fieldData.value;
- }
- return fieldData;
- },
-
- autocomplete : function(e)
- {
- window.clearTimeout(jQuery.iAuto.timer);
- var subject = jQuery.iAuto.getFieldValues(this);
-
- var pressedKey = e.charCode || e.keyCode || -1;
- if (/13|27|35|36|38|40|9/.test(pressedKey) && jQuery.iAuto.items) {
- if (window.event) {
- window.event.cancelBubble = true;
- window.event.returnValue = false;
- } else {
- e.preventDefault();
- e.stopPropagation();
- }
- if (jQuery.iAuto.selectedItem != null)
- jQuery.iAuto.items.get(jQuery.iAuto.selectedItem||0).className = '';
- else
- jQuery.iAuto.selectedItem = -1;
- switch(pressedKey) {
- //enter
- case 9:
- case 13:
- if (jQuery.iAuto.selectedItem == -1)
- jQuery.iAuto.selectedItem = 0;
- var selectedItem = jQuery.iAuto.items.get(jQuery.iAuto.selectedItem||0);
- var valueToAdd = selectedItem.getAttribute('rel');
- this.value = subject.pre + valueToAdd + this.autoCFG.multipleSeparator + subject.post;
- jQuery.iAuto.lastValue = subject.item;
- jQuery.iAuto.selection(
- this,
- subject.pre.length + valueToAdd.length + this.autoCFG.multipleSeparator.length,
- subject.pre.length + valueToAdd.length + this.autoCFG.multipleSeparator.length
- );
- jQuery.iAuto.clear();
- if (this.autoCFG.onSelect) {
- iteration = parseInt(selectedItem.getAttribute('dir'))||0;
- jQuery.iAuto.applyOn(this,this.autoCFG.lastSuggestion.get(iteration), 'onSelect');
- }
- if (this.scrollIntoView)
- this.scrollIntoView(false);
- return pressedKey != 13;
- break;
- //escape
- case 27:
- this.value = subject.pre + jQuery.iAuto.lastValue + this.autoCFG.multipleSeparator + subject.post;
- this.autoCFG.lastSuggestion = null;
- jQuery.iAuto.clear();
- if (this.scrollIntoView)
- this.scrollIntoView(false);
- return false;
- break;
- //end
- case 35:
- jQuery.iAuto.selectedItem = jQuery.iAuto.items.size() - 1;
- break;
- //home
- case 36:
- jQuery.iAuto.selectedItem = 0;
- break;
- //up
- case 38:
- jQuery.iAuto.selectedItem --;
- if (jQuery.iAuto.selectedItem < 0)
- jQuery.iAuto.selectedItem = jQuery.iAuto.items.size() - 1;
- break;
- case 40:
- jQuery.iAuto.selectedItem ++;
- if (jQuery.iAuto.selectedItem == jQuery.iAuto.items.size())
- jQuery.iAuto.selectedItem = 0;
- break;
- }
- jQuery.iAuto.applyOn(this,this.autoCFG.lastSuggestion.get(jQuery.iAuto.selectedItem||0), 'onHighlight');
- jQuery.iAuto.items.get(jQuery.iAuto.selectedItem||0).className = this.autoCFG.selectClass;
- if (jQuery.iAuto.items.get(jQuery.iAuto.selectedItem||0).scrollIntoView)
- jQuery.iAuto.items.get(jQuery.iAuto.selectedItem||0).scrollIntoView(false);
- if(this.autoCFG.autofill) {
- var valToAdd = jQuery.iAuto.items.get(jQuery.iAuto.selectedItem||0).getAttribute('rel');
- this.value = subject.pre + valToAdd + this.autoCFG.multipleSeparator + subject.post;
- if(jQuery.iAuto.lastValue.length != valToAdd.length)
- jQuery.iAuto.selection(
- this,
- subject.pre.length + jQuery.iAuto.lastValue.length,
- subject.pre.length + valToAdd.length
- );
- }
- return false;
- }
- jQuery.iAuto.checkCache.apply(this);
-
- if (this.autoCFG.inCache == false) {
- if (subject.item != jQuery.iAuto.lastValue && subject.item.length >= this.autoCFG.minchars)
- jQuery.iAuto.timer = window.setTimeout(jQuery.iAuto.update, this.autoCFG.delay);
- if (jQuery.iAuto.items) {
- jQuery.iAuto.clear();
- }
- }
- return true;
- },
-
- applyOn: function(field, item, type)
- {
- if (field.autoCFG[type]) {
- var data = {};
- childs = item.getElementsByTagName('*');
- for(i=0; i<childs.length; i++){
- data[childs[i].tagName] = childs[i].firstChild.nodeValue;
- }
- field.autoCFG[type].apply(field,[data]);
- }
- },
-
- hoverItem : function(e)
- {
- if (jQuery.iAuto.items) {
- if (jQuery.iAuto.selectedItem != null)
- jQuery.iAuto.items.get(jQuery.iAuto.selectedItem||0).className = '';
- jQuery.iAuto.items.get(jQuery.iAuto.selectedItem||0).className = '';
- jQuery.iAuto.selectedItem = parseInt(this.getAttribute('dir'))||0;
- jQuery.iAuto.items.get(jQuery.iAuto.selectedItem||0).className = jQuery.iAuto.subject.autoCFG.selectClass;
- }
- },
-
- clickItem : function(event)
- {
- window.clearTimeout(jQuery.iAuto.timer);
-
- event = event || jQuery.event.fix( window.event );
- event.preventDefault();
- event.stopPropagation();
- var subject = jQuery.iAuto.getFieldValues(jQuery.iAuto.subject);
- var valueToAdd = this.getAttribute('rel');
- jQuery.iAuto.subject.value = subject.pre + valueToAdd + jQuery.iAuto.subject.autoCFG.multipleSeparator + subject.post;
- jQuery.iAuto.lastValue = this.getAttribute('rel');
- jQuery.iAuto.selection(
- jQuery.iAuto.subject,
- subject.pre.length + valueToAdd.length + jQuery.iAuto.subject.autoCFG.multipleSeparator.length,
- subject.pre.length + valueToAdd.length + jQuery.iAuto.subject.autoCFG.multipleSeparator.length
- );
- jQuery.iAuto.clear();
- if (jQuery.iAuto.subject.autoCFG.onSelect) {
- iteration = parseInt(this.getAttribute('dir'))||0;
- jQuery.iAuto.applyOn(jQuery.iAuto.subject,jQuery.iAuto.subject.autoCFG.lastSuggestion.get(iteration), 'onSelect');
- }
-
- return false;
- },
-
- protect : function(e)
- {
- pressedKey = e.charCode || e.keyCode || -1;
- if (/13|27|35|36|38|40/.test(pressedKey) && jQuery.iAuto.items) {
- if (window.event) {
- window.event.cancelBubble = true;
- window.event.returnValue = false;
- } else {
- e.preventDefault();
- e.stopPropagation();
- }
- return false;
- }
- },
-
- build : function(options)
- {
- if (!options.source || !jQuery.iUtil) {
- return;
- }
-
- if (!jQuery.iAuto.helper) {
- if (jQuery.browser.msie) {
- jQuery('body', document).append('<iframe style="display:none;position:absolute;filter:progid:DXImageTransform.Microsoft.Alpha(opacity=0);" id="autocompleteIframe" src="about:blank" frameborder="0" scrolling="no"></iframe>');
- jQuery.iAuto.iframe = jQuery('#autocompleteIframe');
- }
- jQuery('body', document).append('<div id="autocompleteHelper" style="position: absolute; top: 0; left: 0; z-index: 30001; display: none;"><ul style="margin: 0;padding: 0; list-style: none; z-index: 30002;"> </ul></div>');
- jQuery.iAuto.helper = jQuery('#autocompleteHelper');
- jQuery.iAuto.content = jQuery('ul', jQuery.iAuto.helper);
- }
-
- return this.each(
- function()
- {
- if (this.tagName != 'INPUT' && this.getAttribute('type') != 'text' )
- return;
- this.autoCFG = {};
- this.autoCFG.source = options.source;
- this.autoCFG.minchars = parseInt(options.minchars) || 1;
- this.autoCFG.helperClass = options.helperClass ? options.helperClass : '';
- this.autoCFG.selectClass = options.selectClass ? options.selectClass : '';
- this.autoCFG.onSelect = options.onSelect && options.onSelect.constructor == Function ? options.onSelect : null;
- this.autoCFG.onShow = options.onShow && options.onShow.constructor == Function ? options.onShow : null;
- this.autoCFG.onHide = options.onHide && options.onHide.constructor == Function ? options.onHide : null;
- this.autoCFG.onHighlight = options.onHighlight && options.onHighlight.constructor == Function ? options.onHighlight : null;
- this.autoCFG.inputWidth = options.inputWidth||false;
- this.autoCFG.multiple = options.multiple||false;
- this.autoCFG.multipleSeparator = this.autoCFG.multiple ? (options.multipleSeparator||', '):'';
- this.autoCFG.autofill = options.autofill ? true : false;
- this.autoCFG.delay = Math.abs(parseInt(options.delay)||1000);
- if (options.fx && options.fx.constructor == Object) {
- if (!options.fx.type || !/fade|slide|blind/.test(options.fx.type)) {
- options.fx.type = 'slide';
- }
- if (options.fx.type == 'slide' && !jQuery.fx.slide)
- return;
- if (options.fx.type == 'blind' && !jQuery.fx.BlindDirection)
- return;
-
- options.fx.duration = Math.abs(parseInt(options.fx.duration)||400);
- if (options.fx.duration > this.autoCFG.delay) {
- options.fx.duration = this.autoCFG.delay - 100;
- }
- this.autoCFG.fx = options.fx;
- }
- this.autoCFG.lastSuggestion = null;
- this.autoCFG.inCache = false;
-
- jQuery(this)
- .attr('autocomplete', 'off')
- .focus(
- function()
- {
- jQuery.iAuto.subject = this;
- jQuery.iAuto.lastValue = this.value;
- }
- )
- .keypress(jQuery.iAuto.protect)
- .keyup(jQuery.iAuto.autocomplete)
-
- .blur(
- function()
- {
- jQuery.iAuto.timer = window.setTimeout(jQuery.iAuto.clear, 200);
- }
- );
- }
- );
- }
-};
-jQuery.fn.Autocomplete = jQuery.iAuto.build;
diff --git a/share/web/static/js/jifty.js b/share/web/static/js/jifty.js
index 037ac9a..4f2599b 100644
--- a/share/web/static/js/jifty.js
+++ b/share/web/static/js/jifty.js
@@ -398,7 +398,6 @@ ActionField.prototype = {
this.render_preamble,
this.render_label,
this.render_widget,
- this.render_autocomplete_div,
this.render_inline_javascript,
this.render_hints,
this.render_errors,
@@ -1723,74 +1722,6 @@ function show_action_result() {
});
}
-Jifty.Autocompleter = function() {
- var that = this;
- var args = arguments;
- jQuery(function () { that.initialize.apply(that, args) } );
- return this;
-};
-
-jQuery.extend(Jifty.Autocompleter.prototype, {
- initialize: function(field, div) {
- this.field = Jifty.$(field);
- this.action = Jifty.Form.Element.getAction(this.field);
- this.url = '/__jifty/autocomplete.xml';
-
- var sel = '#'+this.field.id+'-autocomplete';
- var autocomplete_div = jQuery(sel.replace(/:/g, '\\\\\\:'));
- var self = this;
- jQuery(this.field).focus(function(event) {
- self.changed = true;
- self.hasFocus = true;
- Jifty.current_autocompleter_object = self;
- autocomplete_div.append(jQuery('#autocompleteHelper')).show();
- }).blur(function() { autocomplete_div.hide() });
-
- jQuery(this.field).Autocomplete({
- source: this.url,
- minchars: -1,
- delay: 100,
- helperClass: 'autocomplete',
- selectClass: 'selected'
- });
- },
-
- beforeShow: function() {
- /* Prevents the race for canonicalization and updating via autocomplete */
- if ( this.field.onblur ) {
- this.element._onblur = this.element.onblur;
- this.element.onblur = null;
- }
- },
-
- beforeHide: function() {
- /* Restore onblur and config option */
- if ( this.element._onblur ) {
- this.element.onblur = this.element._onblur;
- this.element._onblur = null;
- }
- },
-
- afterUpdate: function(field, selection) {
- Jifty.Form.Element.validate(field);
- },
-
- buildRequest: function() {
- var request = { path: this.url, actions: {} };
- var a = {};
- a['moniker'] = 'autocomplete';
- a['class'] = 'Jifty::Action::Autocomplete';
- a['fields'] = {};
- a['fields']['moniker'] = this.action.moniker;
- a['fields']['argument'] = Jifty.Form.Element.getField(this.field);
- request['actions']['autocomplete'] = a;
- request['actions'][this.action.moniker] = this.action.data_structure();
- request['actions'][this.action.moniker]['active'] = 0;
- return request;
- }
-});
-
-
Jifty.Placeholder = function() {
this.initialize.apply(this, arguments);
return this;
diff --git a/share/web/static/js/jifty_interface.js b/share/web/static/js/jifty_interface.js
index aea700a..a867880 100644
--- a/share/web/static/js/jifty_interface.js
+++ b/share/web/static/js/jifty_interface.js
@@ -4,67 +4,6 @@
* jquery_noconflict.js
*/
-jQuery.iAuto.update = function() {
- var subject = jQuery.iAuto.subject;
- var subjectValue = jQuery.iAuto.getFieldValues(subject);
- //var selectionStart = jQuery.iAuto.getSelectionStart(subject);
- if (subject && subjectValue.item != jQuery.iAuto.lastValue && subjectValue.item.length >= subject.autoCFG.minchars) {
- jQuery.iAuto.lastValue = subjectValue.item;
- jQuery.iAuto.currentValue = subjectValue.item;
-
- var request = Jifty.current_autocompleter_object.buildRequest();
- jQuery.ajax(
- {
- 'type': 'post',
- 'url': subject.autoCFG.source,
- 'contentType': 'text/x-json',
- 'data': JSON.stringify(request),
- 'dataType': 'xml',
- 'success': function(xml, textStatus) {
- subject.autoCFG.lastSuggestion = jQuery('li',xml);
- size = subject.autoCFG.lastSuggestion.size();
- if (size > 0) {
- var toWrite = '';
-
- subject.autoCFG.lastSuggestion.each(
- function(nr) {
- // XXX: we should be looking at span.hidden_value, but it doesn't exist...
- var v = jQuery(this).text();
- var value = v;
- if (jQuery('span:last', this).size()) {
- value = jQuery('span:last', this).text();
- // XXX for some reasons .html() / innerHTML is empty though we have .text() working, so reconstruct the bloody html
- v = '<span class="informal">'+jQuery('span:first', this).text()+'</span>'+'<span class="hidden_value">'+jQuery('span:last', this).text()+'</span>';
- }
-
- toWrite += '<li rel="' + value + '" dir="' + nr + '" style="cursor: default;">' + v + '</li>';
- }
- );
-
- if (subject.autoCFG.autofill) {
- var valueToAdd = jQuery('value', subject.autoCFG.lastSuggestion.get(0)).text();
- subject.value = subjectValue.pre + valueToAdd + subject.autoCFG.multipleSeparator + subjectValue.post;
- jQuery.iAuto.selection(
- subject,
- subjectValue.item.length != valueToAdd.length ? (subjectValue.pre.length + subjectValue.item.length) : valueToAdd.length,
- subjectValue.item.length != valueToAdd.length ? (subjectValue.pre.length + valueToAdd.length) : valueToAdd.length
- );
- }
-
- if (size > 0) {
- jQuery.iAuto.writeItems(subject, toWrite);
- } else {
- jQuery.iAuto.clear();
- }
- } else {
- jQuery.iAuto.clear();
- }
- }
- }
- );
- }
-};
-
jQuery.fn.shake = function() {
this.each(function(init) {
var e = jQuery(this);
commit 0e5741cd38371a507279b13f8ad6f08dd2b5f1d9
Author: Shawn M Moore <sartak at bestpractical.com>
Date: Mon Mar 22 15:08:52 2010 -0400
Update the list of what JS files are served
diff --git a/lib/Jifty/Web.pm b/lib/Jifty/Web.pm
index 89312bc..2f2ad7b 100644
--- a/lib/Jifty/Web.pm
+++ b/lib/Jifty/Web.pm
@@ -35,7 +35,6 @@ __PACKAGE__->javascript_libs([qw(
json.js
jquery-1.2.6.js
iutil.js
- iautocompleter.js
jifty_interface.js
jquery_noconflict.js
jquery.jgrowl.js
@@ -65,6 +64,9 @@ __PACKAGE__->javascript_libs([qw(
css_browser_selector.js
cssQuery-jquery.js
jquery.timepickr.js
+ jquery.ajaxQueue.js
+ jquery.bgiframe.min.js
+ jquery.autocomplete.js
)]);
use Class::Trigger;
-----------------------------------------------------------------------
More information about the Jifty-commit
mailing list