diff --git a/.gitignore b/.gitignore index f24bdb1bfc..3b7223108b 100644 --- a/.gitignore +++ b/.gitignore @@ -9,8 +9,6 @@ .AppleDouble database.sqlite courseware/static/js/mathjax/* -db.newaskbot -db.oldaskbot flushdb.sh build .coverage diff --git a/.hgignore b/.hgignore deleted file mode 100644 index 67ea339cd8..0000000000 --- a/.hgignore +++ /dev/null @@ -1,12 +0,0 @@ -syntax: glob -*.pyc -*~ -*.scssc -*.swp -*.orig -*.DS_Store -database.sqlite -courseware/static/js/mathjax/* -db.newaskbot -db.oldaskbot -flushdb.sh diff --git a/cms/templates/asset_index.html b/cms/templates/asset_index.html index 83e2188691..900ef3b697 100644 --- a/cms/templates/asset_index.html +++ b/cms/templates/asset_index.html @@ -28,7 +28,7 @@ {{uploadDate}}
Consider a hypothetical magnetic field pointing out of your computer screen. Now imagine an electron traveling from right to leftin the plane of your screen. A diagram of this situation is show below.
+
a. The magnitude of the force experienced by the electron is proportional the product of which of the following? (Select all that apply.)
+b. The direction of the force experienced by the electron is _______.
++ Part 1: Function Types +
++For each of the following functions, specify the type of its output. You can assume each function is called with an appropriate argument, as specified by its docstring.
++If the output can be either an int or a float, select num, which isn't a real Python type, but which we'll use to indicate that either basic numeric type is legal.
++In fact, in Python, booleans True and False can be operated on as if they were the integers 1 and 0; but it is ugly and confusing to take advantage of this fact, and we will resolutely pretend that it isn't true.
+
+
+In this and future problems, you'll see function definitions that look like this:
+What are those three lines between
+In Python, docstrings appear immediately after the
+As you begin coding your own functions, we strongly encourage you to document all your functions by using properly-formatted docstrings!
+def a(x):
+ '''
+ x: int or float.
+ '''
+ return x + 1
+
+ def a(x): and return x + 1? These lines are called the docstring of the function. A docstring is a special type of comment that is used to document what your function is doing. Typically, docstrings will explain what the function expects the type(s) of the argument(s) to be, and what the function is returning. def line of a function, before the body. Docstrings start and end with triple quotes - this can be triple single quotes or triple double quotes, it doesn't matter as long as they match. To sum up this general form:
+def myFunction(argument):
+ """
+ Docstring goes here. Explain what type argument(s) should have, and what your function
+ is going to return.
+ """
+ < Code for your function (the body of the function) goes here >
+
+
+def a(x): + ''' + x: int or float. + ''' + return x + 1 ++
+ Indicate the type of the output that the function a will yield.
+def b(x): + ''' + x: int or float. + ''' + return x + 1.0 ++
+ Indicate the type of the output that the function b will yield.
+def c(x, y): + ''' + x: int or float. + y: int or float. + ''' + return x + y ++
+ Indicate the type of the output that the function c will yield.
+def d(x, y): + ''' + x: Can be of any type. + y: Can be of any type. + ''' + return x > y ++
+ Indicate the type of the output that the function d will yield.
+def e(x, y, z): + ''' + x: Can be of any type. + y: Can be of any type. + z: Can be of any type. + ''' + return x >= y and x <= z ++
+ Indicate the type of the output that the function e will yield.
+def f(x, y): + ''' + x: int or float. + y: int or float + ''' + x + y - 2 ++
+ Indicate the type of the output that the function f will yield.
+ Part 2: Transcript +
++Below is a transcript of a session with the Python shell. Assume the functions from Part 1 (above) have been defined. Provide the type and value of the expressions being evaluated. If evaluating an expression would cause an error, select NoneType and write 'error' in the box. If the value of an expression is a function, select function as the type and write 'function' in the box.
+
+ a(6)
+
+ a(-5.3)
+
+ a(a(a(6)))
+
+ c(a(1), b(1))
+
+ d('apple', 11.1)
+
+ e(a(3), b(4), c(3, 4))
+
+ f
+
Suppose you were to pass a hydroge ion (H+) through an electric field and measure the deflection of the ion. How would its deflection compare to the deflection of an electron passed through the same electric field?
+Gaseous hydrogen can be reacted with gaseous oxygen in the presence of a flame to produce water vapor according to the following reaction:
+ [mathjax] \text{ a } \text{H}_{2 } + \text{ b }\text{O}_{2 } = \text{ c }\text{H}_{2 }\text{O }[/mathjax] +Balance the equation i.e., specify the values of a, b, and c. Use the lowest whole number coefficients.
+ +a =
+b =
+
c =
+
Metallothermic production of zirconium (Zr) would involve the reaction of sodium (Na) with zirconium tetrachloride (ZrCl4).
+ +(a) Write a balanced chemical equation.
+ + + +(b) Write the balanced chemical equation using lowest whole numbers.
+ + + +(c) Calculate the amount of zirconium produced (in kg) if a reactor were charged with 111 kg [mathjaxinline]\text{ZrCl}_4[/mathjaxinline] and 11.1 kg [mathjaxinline]\text{Na}[/mathjaxinline].
+
SOLUTION:
+(b)[mathjax] \text{ZrCl}_{4 } + \mathbf{4 }\text{Na} = \mathbf{4 }\text{NaCl } + \mathbf{1 } \text{Zr} [/mathjax]
+(c)
+[mathjaxinline]111\text{kg ZrCl}_4 = 111000/[91.22 + (4 \times 35.45)] = 476 \text{ moles ZrCl}_4[/mathjaxinline]
+[mathjaxinline]11.1\text{ kg Na} = 11100/22.99 = 483\text{ moles C}[/mathjaxinline]
+stoichiometry of reaction further dictates that on a molar basis there needs to be 4 x amount of [mathjaxinline]\text{Na}[/mathjaxinline] as there is [mathjaxinline]\text{ZrCl}_4[/mathjaxinline], but calculations show there to be a shortfall of [mathjaxinline]\text{Na}[/mathjaxinline]
+[mathjaxinline]\therefore[/mathjaxinline] reaction yield is contrained by [mathjaxinline]\text{Na}[/mathjaxinline] present
+stoichiometry of reaction further dictates that if [mathjaxinline]\text{Na}[/mathjaxinline] controls the yield, then the amount of [mathjaxinline]\text{Zr}[/mathjaxinline] produced = 1/4 x molar quantity of [mathjaxinline]\text{Na}[/mathjaxinline] = 1/4 x 483 moles = 121
+ [mathjaxinline]121 \text{ moles Zr} \times 91.22\text{ g / mol } \mathbf{= 11.0 \text{ kg Zr} }[/mathjaxinline]+
+ ++
+ +Hints can be provided to students, based on the last response given, as well as the history of responses given. Here is an example of a hint produced by a Formula Response problem.
+ ++What is the equation of the line which passess through ($x1,$y1) and +($x2,$y2)?
+ +The correct answer is $answer. A common error is to invert the equation for the slope. Enter +$wrongans to see a hint.
+ ++Two skiers are on frictionless black diamond ski slopes. +Hello
Use conservation of energy.
Suppose you were to pass a hydroge ion (H+) through an electric field and measure the deflection of the ion. How would its deflection compare to the deflection of an electron passed through the same electric field?
+Gaseous hydrogen can be reacted with gaseous oxygen in the presence of a flame to produce water vapor according to the following reaction:
+ [mathjax] \text{ a } \text{H}_{2 } + \text{ b }\text{O}_{2 } = \text{ c }\text{H}_{2 }\text{O }[/mathjax] +Balance the equation i.e., specify the values of a, b, and c. Use the lowest whole number coefficients.
+ +a =
+b =
+
c =
+
+Why do bicycles benefit from having larger wheels when going up a bump as shown in the picture?
+Assume that for both bicycles:
+1.) The tires have equal air pressure.
+2.) The bicycles never leave the contact with the bump.
+3.) The bicycles have the same mass. The bicycle tires (regardless of size) have the same mass.
+
The bicycles with larger wheels have more time to go over the bump. This decreases the magnitude of the force needed to lift the bicycle.
+The bicycles with larger wheels always have a smaller vertical displacement regardless of speed.
+The bicycles with larger wheels experience a force backward with less magnitude for the same amount of time.
+The bicycles with larger wheels experience a force backward with less magnitude for a greater amount of time.
+The bicycles with larger wheels have more kinetic energy turned into gravitational potential energy.
+The bicycles with larger wheels have more rotational kinetic energy, so the horizontal velocity of the biker changes less.
++A symbolic math response problem presents one or more symbolic math +input fields for input. Correctness of input is evaluated based on +the symbolic properties of the expression entered. The student enters +text, but sees a proper symbolic rendition of the entered formula, in +real time, next to the input box. +
+ +This is a correct answer which may be entered below:
+cos(theta)*[[1,0],[0,1]] + i*sin(theta)*[[0,1],[1,0]]
+ + +' + - gettext('Show/change current login methods') + - '
'); - setup_event_handlers( - enabler, - function(){ - if (askbot['settings']['signin_always_show_local_login'] === false){ - password_input_fields.hide(); - } - openid_login_token_input_fields.hide(); - enabler.hide(); - existing_login_methods_div.show(); - } - ); - existing_login_methods_div.after(enabler); - } - }; - - var reset_password_input_fields = function(){ - if (userIsAuthenticated){ - $('#id_new_password').val(''); - $('#id_new_password_retyped').val(''); - } - else { - $('#id_username').val(''); - $('#id_password').val(''); - } - }; - - var reset_form = function(){ - openid_login_token_input_fields.hide(); - if (askbot['settings']['signin_always_show_local_login'] === false){ - password_input_fields.hide(); - } - reset_password_input_fields(); - if (userIsAuthenticated === false){ - email_input_fields.hide(); - account_recovery_heading.hide(); - account_recovery_link.show(); - account_recovery_hint.show(); - $('#account-recovery-form>p.hint').css('margin-top','10px'); - account_recovery_text_span.html(account_recovery_question_text).show(); - } - else { - if (existing_login_methods !== null){ - existing_login_methods_div.hide(); - insert_login_list_enabler(); - } - } - }; - - var reset_form_and_errors = function(){ - reset_form(); - $('.error').remove(); - } - - var set_provider_name = function(element){ - var provider_name = element.attr('name'); - provider_name_input.val(provider_name); - }; - - var show_openid_input_fields = function(provider_name){ - reset_form_and_errors(); - var token_name = extra_token_name[provider_name] - if (userIsAuthenticated){ - $('#openid-heading').html( - interpolate(gettext('Please enter your %s, then proceed'), [token_name]) - ); - var button_text = gettext('Connect your %(provider_name)s account to %(site)s'); - var data = { - provider_name: provider_name, - site: siteName - } - button_text = interpolate(button_text, data, true); - openid_submit_button.val(button_text); - } - else { - $('#openid-heading>span').html(token_name); - } - openid_login_token_input_fields.show(); - openid_login_token_input.focus(); - }; - - var start_simple_login = function() { - //$('#openid_form .providers td').removeClass('highlight'); - //$li.addClass('highlight'); - set_provider_name($(this)); - signin_form.submit(); - return true; - }; - - var start_login_with_extra_openid_token = function() { - show_openid_input_fields($(this).attr('name')); - set_provider_name($(this)); - - setup_enter_key_handler( - openid_login_token_input, - function(){ - openid_submit_button.click(); - return false; - } - ); - - setup_event_handlers( - openid_submit_button, - function(){ - signin_form.unbind( - 'submit' - ).submit( - submit_with_extra_openid_token - ); - } - ); - return false; - }; - - var start_facebook_login = function(){ - set_provider_name($(this)); - if (typeof FB != 'undefined'){ - FB.getLoginStatus(function(response){ - if (response.authResponse){ - signin_form.submit(); - } - else { - if (FB.getAuthResponse()){ - signin_form.submit(); - } - FB.login(); - } - }); - } - return false; - }; - - var start_password_login_or_change = function(){ - //called upon clicking on one of the password login buttons - reset_form_and_errors(); - set_provider_name($(this)); - var provider_name = $(this).attr('name'); - return setup_password_login_or_change(provider_name); - }; - - var init_always_visible_password_login = function(){ - reset_form(); - //will break wordpress and ldap - provider_name_input.val('local'); - setup_password_login_or_change('local'); - }; - - var setup_password_login_or_change = function(provider_name){ - var token_name = extra_token_name[provider_name] - var password_action_input = $('input[name=password_action]'); - if (userIsAuthenticated === true){ - var password_button = $('input[name=change_password]'); - var submit_action = submit_change_password; - if (provider_name === 'local'){ - var provider_cleaned_name = siteName; - } - else { - var provider_cleaned_name = provider_name; - } - if (existing_login_methods && existing_login_methods[provider_name]){ - var password_heading_text = interpolate(gettext('Change your %s password'), [provider_cleaned_name]) - var password_button_text = gettext('Change password') - } - else { - var password_heading_text = interpolate(gettext('Create a password for %s'), [provider_cleaned_name]) - var password_button_text = gettext('Create password') - } - $('#password-heading').html( - password_heading_text - ) - password_button.val(password_button_text); - password_action_input.val('change_password'); - var focus_input = $('#id_new_password'); - var submittable_input = $('#id_new_password_retyped'); - } - else{ - $('#password-heading>span').html(token_name); - var password_button = $('input[name=login_with_password]'); - var submit_action = submit_login_with_password; - var create_pw_link = $('a.create-password-account') - if (create_pw_link.length > 0){ - create_pw_link.html(gettext('Create a password-protected account')); - var url = create_pw_link.attr('href'); - if (url.indexOf('?') !== -1){ - url = url.replace(/\?.*$/,'?login_provider=' + provider_name); - } - else{ - url += '?login_provider=' + provider_name; - } - create_pw_link.attr('href', url); - } - password_action_input.val('login'); - var focus_input = $('#id_username'); - var submittable_input = $('#id_password'); - } - password_input_fields.show(); - focus_input.focus(); - - var submit_password_login = function(){ - signin_form.unbind('submit').submit(submit_action); - }; - - setup_enter_key_handler( - submittable_input, - function() { - password_button.click(); - return false; - } - ); - setup_event_handlers(password_button, submit_password_login); - return false; - }; - - var start_account_recovery = function(){ - reset_form_and_errors(); - account_recovery_hint.hide(); - account_recovery_heading.css('margin-bottom', '0px'); - account_recovery_heading.html(account_recovery_prompt_text).show(); - email_input_fields.show(); - $('#id_email').focus(); - }; - - var clear_password_fields = function(){ - $('#id_password').val(''); - $('#id_new_password').val(''); - $('#id_new_password_retyped').val(''); - }; - - var setup_default_handlers = function(){ - setup_event_handlers( - signin_page.find('input.openid-direct'), - start_simple_login - ); - - setup_event_handlers( - signin_page.find('input.openid-username'), - start_login_with_extra_openid_token - ); - - setup_event_handlers( - signin_page.find('input.openid-generic'), - start_login_with_extra_openid_token - ); - - setup_event_handlers( - signin_page.find('input.facebook'), - start_facebook_login - ); - - setup_event_handlers( - signin_page.find('input.oauth'), - start_simple_login - ); - - setup_event_handlers( - signin_page.find('input.password'), - start_password_login_or_change - ); - setup_event_handlers( - signin_page.find('input.wordpress_site'), - start_password_login_or_change - ); - - setup_event_handlers(account_recovery_link, start_account_recovery); - - if (userIsAuthenticated){ - read_existing_login_methods(); - setup_login_method_deleters(); - } - }; - - setup_default_handlers(); - if (askbot['settings']['signin_always_show_local_login'] === true){ - init_always_visible_password_login(); - } - clear_password_fields(); - return this; -}; diff --git a/lms/askbot/skins/common/media/jquery-openid/openid.css b/lms/askbot/skins/common/media/jquery-openid/openid.css deleted file mode 100644 index 0028722442..0000000000 --- a/lms/askbot/skins/common/media/jquery-openid/openid.css +++ /dev/null @@ -1,39 +0,0 @@ -div#login-icons {margin:10px 0 0 0;padding:10px;border:#eee 1px solid;} -ul.login-icons {width: 450px; margin:0;padding:0;text-align:left; list-style-type:none; display:block;} -ul.login-icons li {display:inline;} -ul.large input {height: 40px; width: 90px;border:1px solid #ccc;margin:0 5px 5px 0;} -.openid-signin h2 {margin-top:15px;} -.openid-signin h2#account-recovery-heading {margin-bottom:2px;} -#account-recovery-form p.hint a {color:#1b79bd; text-decoration: none;} -#account-recovery-form p.hint a:hover {text-decoration: underline;} -.openid-signin fieldset { border-style:none;margin:0;padding:0;} -.openid-signin p {margin:0;padding:0}; -.openid-signin p.hint {color: #555;} -.openid-signin #password-fs label {width:100px;margin-top:5px;text-align:left;} -.openid-signin #password-fs .hint {margin-bottom:5px} -#password-fs a {padding-left:5px;} -/*#signin-form #account-recovery-form input {cursor:pointer;} -#signin-form #account-recovery-form input.text {cursor:default;}*/ - -table.login { text-align: right;} - -.openid-signin .submit-b { - cursor: pointer; /*letter-spacing:1px;*/ - margin: 0 0 2px 0; - vertical-align: middle; -} - -.openid-signin .highlight { -moz-border-radius:4px; -webkit-border-radius:4px; background-color: #FD6} - -ul.providers { - display: block; -} - -.openid-signin th { - color: #555; - font-weight: normal; -} - -.openid-signin .ab-provider-name { - font-weight: bold; -} diff --git a/lms/askbot/skins/common/media/js/autocompleter.js b/lms/askbot/skins/common/media/js/autocompleter.js deleted file mode 100644 index a7c5431592..0000000000 --- a/lms/askbot/skins/common/media/js/autocompleter.js +++ /dev/null @@ -1,766 +0,0 @@ -/** - * AutoCompleter Object, refactored closure style from - * jQuery autocomplete plugin - * @param {Object=} options Settings - * @constructor - */ -var AutoCompleter = function(options) { - - /** - * Default options for autocomplete plugin - */ - var defaults = { - autocompleteMultiple: true, - multipleSeparator: ' ',//a single character - inputClass: 'acInput', - loadingClass: 'acLoading', - resultsClass: 'acResults', - selectClass: 'acSelect', - queryParamName: 'q', - limitParamName: 'limit', - extraParams: {}, - lineSeparator: '\n', - cellSeparator: '|', - minChars: 2, - maxItemsToShow: 10, - delay: 400, - useCache: true, - maxCacheLength: 10, - matchSubset: true, - matchCase: false, - matchInside: true, - mustMatch: false, - preloadData: false, - selectFirst: false, - stopCharRegex: /\s+/, - selectOnly: false, - formatItem: null, // TBD - onItemSelect: false, - autoFill: false, - filterResults: true, - sortResults: true, - sortFunction: false, - onNoMatch: false - }; - - /** - * Options dictionary - * @type Object - * @private - */ - this.options = $.extend({}, defaults, options); - - /** - * Cached data - * @type Object - * @private - */ - this.cacheData_ = {}; - - /** - * Number of cached data items - * @type number - * @private - */ - this.cacheLength_ = 0; - - /** - * Class name to mark selected item - * @type string - * @private - */ - this.selectClass_ = 'jquery-autocomplete-selected-item'; - - /** - * Handler to activation timeout - * @type ?number - * @private - */ - this.keyTimeout_ = null; - - /** - * Last key pressed in the input field (store for behavior) - * @type ?number - * @private - */ - this.lastKeyPressed_ = null; - - /** - * Last value processed by the autocompleter - * @type ?string - * @private - */ - this.lastProcessedValue_ = null; - - /** - * Last value selected by the user - * @type ?string - * @private - */ - this.lastSelectedValue_ = null; - - /** - * Is this autocompleter active? - * @type boolean - * @private - */ - this.active_ = false; - - /** - * Is it OK to finish on blur? - * @type boolean - * @private - */ - this.finishOnBlur_ = true; - - this.options.minChars = parseInt(this.options.minChars, 10); - if (isNaN(this.options.minChars) || this.options.minChars < 1) { - this.options.minChars = 2; - } - - this.options.maxItemsToShow = parseInt(this.options.maxItemsToShow, 10); - if (isNaN(this.options.maxItemsToShow) || this.options.maxItemsToShow < 1) { - this.options.maxItemsToShow = 10; - } - - this.options.maxCacheLength = parseInt(this.options.maxCacheLength, 10); - if (isNaN(this.options.maxCacheLength) || this.options.maxCacheLength < 1) { - this.options.maxCacheLength = 10; - } - - if (this.options['preloadData'] === true){ - this.fetchRemoteData('', function(){}); - } -}; -inherits(AutoCompleter, WrappedElement); - -AutoCompleter.prototype.decorate = function(element){ - - /** - * Init DOM elements repository - */ - this._element = element; - - /** - * Switch off the native autocomplete - */ - this._element.attr('autocomplete', 'off'); - - /** - * Create DOM element to hold results - */ - this._results = $('').hide(); - if (this.options.resultsClass) { - this._results.addClass(this.options.resultsClass); - } - this._results.css({ - position: 'absolute' - }); - $('body').append(this._results); - - this.setEventHandlers(); -}; - -AutoCompleter.prototype.setEventHandlers = function(){ - /** - * Shortcut to self - */ - var self = this; - - /** - * Attach keyboard monitoring to $elem - */ - self._element.keydown(function(e) { - self.lastKeyPressed_ = e.keyCode; - switch(self.lastKeyPressed_) { - - case 38: // up - e.preventDefault(); - if (self.active_) { - self.focusPrev(); - } else { - self.activate(); - } - return false; - break; - - case 40: // down - e.preventDefault(); - if (self.active_) { - self.focusNext(); - } else { - self.activate(); - } - return false; - break; - - case 9: // tab - case 13: // return - if (self.active_) { - e.preventDefault(); - self.selectCurrent(); - return false; - } - break; - - case 27: // escape - if (self.active_) { - e.preventDefault(); - self.finish(); - return false; - } - break; - - default: - self.activate(); - - } - }); - self._element.blur(function() { - if (self.finishOnBlur_) { - setTimeout(function() { self.finish(); }, 200); - } - }); -}; - -AutoCompleter.prototype.position = function() { - var offset = this._element.offset(); - this._results.css({ - top: offset.top + this._element.outerHeight(), - left: offset.left - }); -}; - -AutoCompleter.prototype.cacheRead = function(filter) { - var filterLength, searchLength, search, maxPos, pos; - if (this.options.useCache) { - filter = String(filter); - filterLength = filter.length; - if (this.options.matchSubset) { - searchLength = 1; - } else { - searchLength = filterLength; - } - while (searchLength <= filterLength) { - if (this.options.matchInside) { - maxPos = filterLength - searchLength; - } else { - maxPos = 0; - } - pos = 0; - while (pos <= maxPos) { - search = filter.substr(0, searchLength); - if (this.cacheData_[search] !== undefined) { - return this.cacheData_[search]; - } - pos++; - } - searchLength++; - } - } - return false; -}; - -AutoCompleter.prototype.cacheWrite = function(filter, data) { - if (this.options.useCache) { - if (this.cacheLength_ >= this.options.maxCacheLength) { - this.cacheFlush(); - } - filter = String(filter); - if (this.cacheData_[filter] !== undefined) { - this.cacheLength_++; - } - return this.cacheData_[filter] = data; - } - return false; -}; - -AutoCompleter.prototype.cacheFlush = function() { - this.cacheData_ = {}; - this.cacheLength_ = 0; -}; - -AutoCompleter.prototype.callHook = function(hook, data) { - var f = this.options[hook]; - if (f && $.isFunction(f)) { - return f(data, this); - } - return false; -}; - -AutoCompleter.prototype.activate = function() { - var self = this; - var activateNow = function() { - self.activateNow(); - }; - var delay = parseInt(this.options.delay, 10); - if (isNaN(delay) || delay <= 0) { - delay = 250; - } - if (this.keyTimeout_) { - clearTimeout(this.keyTimeout_); - } - this.keyTimeout_ = setTimeout(activateNow, delay); -}; - -AutoCompleter.prototype.activateNow = function() { - var value = this.getValue(); - if (value !== this.lastProcessedValue_ && value !== this.lastSelectedValue_) { - if (value.length >= this.options.minChars) { - this.active_ = true; - this.lastProcessedValue_ = value; - this.fetchData(value); - } - } -}; - -AutoCompleter.prototype.fetchData = function(value) { - if (this.options.data) { - this.filterAndShowResults(this.options.data, value); - } else { - var self = this; - this.fetchRemoteData(value, function(remoteData) { - self.filterAndShowResults(remoteData, value); - }); - } -}; - -AutoCompleter.prototype.fetchRemoteData = function(filter, callback) { - var data = this.cacheRead(filter); - if (data) { - callback(data); - } else { - var self = this; - if (this._element){ - this._element.addClass(this.options.loadingClass); - } - var ajaxCallback = function(data) { - var parsed = false; - if (data !== false) { - parsed = self.parseRemoteData(data); - self.options.data = parsed;//cache data forever - E.F. - self.cacheWrite(filter, parsed); - } - if (self._element){ - self._element.removeClass(self.options.loadingClass); - } - callback(parsed); - }; - $.ajax({ - url: this.makeUrl(filter), - success: ajaxCallback, - error: function() { - ajaxCallback(false); - } - }); - } -}; - -AutoCompleter.prototype.setOption = function(name, value){ - this.options[name] = value; -}; - -AutoCompleter.prototype.setExtraParam = function(name, value) { - var index = $.trim(String(name)); - if (index) { - if (!this.options.extraParams) { - this.options.extraParams = {}; - } - if (this.options.extraParams[index] !== value) { - this.options.extraParams[index] = value; - this.cacheFlush(); - } - } -}; - -AutoCompleter.prototype.makeUrl = function(param) { - var self = this; - var url = this.options.url; - var params = $.extend({}, this.options.extraParams); - // If options.queryParamName === false, append query to url - // instead of using a GET parameter - if (this.options.queryParamName === false) { - url += encodeURIComponent(param); - } else { - params[this.options.queryParamName] = param; - } - - if (this.options.limitParamName && this.options.maxItemsToShow) { - params[this.options.limitParamName] = this.options.maxItemsToShow; - } - - var urlAppend = []; - $.each(params, function(index, value) { - urlAppend.push(self.makeUrlParam(index, value)); - }); - if (urlAppend.length) { - url += url.indexOf('?') == -1 ? '?' : '&'; - url += urlAppend.join('&'); - } - return url; -}; - -AutoCompleter.prototype.makeUrlParam = function(name, value) { - return String(name) + '=' + encodeURIComponent(value); -}; - -/** - * Sanitize CR and LF, then split into lines - */ -AutoCompleter.prototype.splitText = function(text) { - return String(text).replace(/(\r\n|\r|\n)/g, '\n').split(this.options.lineSeparator); -}; - -AutoCompleter.prototype.parseRemoteData = function(remoteData) { - var value, lines, i, j, data; - var results = []; - var lines = this.splitText(remoteData); - for (i = 0; i < lines.length; i++) { - var line = lines[i].split(this.options.cellSeparator); - data = []; - for (j = 0; j < line.length; j++) { - data.push(unescape(line[j])); - } - value = data.shift(); - results.push({ value: unescape(value), data: data }); - } - return results; -}; - -AutoCompleter.prototype.filterAndShowResults = function(results, filter) { - this.showResults(this.filterResults(results, filter), filter); -}; - -AutoCompleter.prototype.filterResults = function(results, filter) { - - var filtered = []; - var value, data, i, result, type, include; - var regex, pattern, testValue; - - for (i = 0; i < results.length; i++) { - result = results[i]; - type = typeof result; - if (type === 'string') { - value = result; - data = {}; - } else if ($.isArray(result)) { - value = result[0]; - data = result.slice(1); - } else if (type === 'object') { - value = result.value; - data = result.data; - } - value = String(value); - if (value > '') { - if (typeof data !== 'object') { - data = {}; - } - if (this.options.filterResults) { - pattern = String(filter); - testValue = String(value); - if (!this.options.matchCase) { - pattern = pattern.toLowerCase(); - testValue = testValue.toLowerCase(); - } - include = testValue.indexOf(pattern); - if (this.options.matchInside) { - include = include > -1; - } else { - include = include === 0; - } - } else { - include = true; - } - if (include) { - filtered.push({ value: value, data: data }); - } - } - } - - if (this.options.sortResults) { - filtered = this.sortResults(filtered, filter); - } - - if (this.options.maxItemsToShow > 0 && this.options.maxItemsToShow < filtered.length) { - filtered.length = this.options.maxItemsToShow; - } - - return filtered; - -}; - -AutoCompleter.prototype.sortResults = function(results, filter) { - var self = this; - var sortFunction = this.options.sortFunction; - if (!$.isFunction(sortFunction)) { - sortFunction = function(a, b, f) { - return self.sortValueAlpha(a, b, f); - }; - } - results.sort(function(a, b) { - return sortFunction(a, b, filter); - }); - return results; -}; - -AutoCompleter.prototype.sortValueAlpha = function(a, b, filter) { - a = String(a.value); - b = String(b.value); - if (!this.options.matchCase) { - a = a.toLowerCase(); - b = b.toLowerCase(); - } - if (a > b) { - return 1; - } - if (a < b) { - return -1; - } - return 0; -}; - -AutoCompleter.prototype.showResults = function(results, filter) { - var self = this; - var $ul = $('| t |