Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

central-develop into 0.17.x #5595

Merged
Merged
Show file tree
Hide file tree
Changes from 136 commits
Commits
Show all changes
140 commits
Select commit Hold shift + click to select a range
95ae21e
Student should be redirected to login page if he/she gets looged out …
anuragkanungo Feb 4, 2015
0615773
Merge pull request #2939 from anuragkanungo/nalanda-rct3
aronasorman Feb 4, 2015
3daac46
Added Unit Variable to ExerciseLog Export
anuragkanungo Feb 7, 2015
30758b4
Updated code for unit variable in exercise log
anuragkanungo Feb 7, 2015
5d6a29d
Increased height of exercise name column in exam reports
anuragkanungo Feb 10, 2015
6d7e510
Added Exam Prep Playlists
anuragkanungo Feb 10, 2015
0cef1b9
Added student_testing/data/407.json
anuragkanungo Feb 10, 2015
6c70ea7
Added 15Nov2014 RCT condition check for unit variable
anuragkanungo Feb 10, 2015
8fea95e
Merge pull request #3016 from anuragkanungo/smps_4b_exam_results
aronasorman Feb 10, 2015
318a01a
Merge pull request #3011 from anuragkanungo/exam_topic_width
aronasorman Feb 10, 2015
bf146dc
Merge pull request #3012 from anuragkanungo/playlist
aronasorman Feb 10, 2015
c6402d3
Added Student Mastery/Class Mastery CoachReports
anuragkanungo Feb 11, 2015
c1abb70
RCT Unit Variable comment
anuragkanungo Feb 11, 2015
5105876
Removed Unit Selection Box and Added Class Level Mastery
anuragkanungo Feb 12, 2015
6e6c0f0
correct unit for those we are sure else unit 0
anuragkanungo Feb 12, 2015
26592ee
Added comment why to keep unit variable as 0 for some cases
anuragkanungo Feb 12, 2015
61fb56b
Merge pull request #2958 from anuragkanungo/nalanda-rct3
jamalex Feb 12, 2015
5286833
Code cleanup and renamed report view to exercise_mastery_view
anuragkanungo Feb 13, 2015
af8d016
On Facility Switch remove playlist values from url, to avoid get exer…
anuragkanungo Feb 13, 2015
350a7f5
Fixed minor bugs related to division by zero and exercise selection
anuragkanungo Feb 13, 2015
1c582c2
Moved jquery.js required for dyna-tree persistance to static-libraries
anuragkanungo Feb 13, 2015
66a0248
Refactoring and percentage in float
anuragkanungo Feb 13, 2015
c106ca1
removed extra comma, tests was failing
anuragkanungo Feb 13, 2015
8e5e8e5
Merge pull request #3033 from anuragkanungo/coach_reports
jamalex Feb 20, 2015
bc21a36
Fix 3040, Redirect to login page in case of Unauthorized
anuragkanungo Feb 23, 2015
3bffde5
Used SetGetParam for url
anuragkanungo Feb 24, 2015
5e0b016
Test for redirect unauthorized playlist view request to login page
anuragkanungo Feb 24, 2015
d4c91a2
Added test for unauthorized request to redirect to login page
anuragkanungo Feb 24, 2015
cfb423d
Moved import to top
anuragkanungo Feb 24, 2015
14c8701
Added implicit wait for css selector to be found in selenium test
anuragkanungo Feb 24, 2015
b56a514
Updated implicit wait after selector
anuragkanungo Feb 24, 2015
4ffdb35
Increase implict wait timeout time
anuragkanungo Feb 24, 2015
7c9085b
Merge pull request #3092 from anuragkanungo/nalanda-rct3
aronasorman Feb 25, 2015
b68aadf
Fixing up loadtesting.
rtibbles Feb 27, 2015
618314d
Final tweaks and fixes for loadtesting.
rtibbles Feb 27, 2015
2c5cce4
Fixes up load_testing for nalanda_rct3
rtibbles Feb 27, 2015
b3f28a0
Adds description comment to loadtesting view.
rtibbles Feb 28, 2015
c06bab5
Merge pull request #3149 from rtibbles/load_testing_nalanda
jamalex Feb 28, 2015
dd65adb
Fixes video playback during loadtest
rtibbles Feb 28, 2015
0299599
Merge pull request #3161 from rtibbles/load_testing_video
jamalex Feb 28, 2015
e890a2d
Fixes exercise answering for nalanda-rct3
rtibbles Feb 28, 2015
b289d0f
Merge pull request #3163 from rtibbles/load_testing_video
jamalex Feb 28, 2015
54c23cb
Ignore content/khan folder in git.
jamalex Mar 1, 2015
1509abc
Re-enable motivational features by default for Nalanda.
jamalex Mar 1, 2015
0597547
Fixes and simplification to loadtesting app.
jamalex Mar 1, 2015
a6d62e5
Merge pull request #3165 from jamalex/loadtesting_fix
jamalex Mar 1, 2015
6e8da48
On loadtesting, set a timeout to continue even if page fails.
jamalex Mar 2, 2015
6177f63
Merge pull request #3169 from jamalex/loadtesting_robustness
rtibbles Mar 2, 2015
ee90bd5
when running an external kalite process, make sure we change the
aronasorman Mar 4, 2015
a5a5b1b
Skip unauthorzied redirect to login test on travis
anuragkanungo Mar 9, 2015
3bbd98e
Merge pull request #3198 from anuragkanungo/nalanda-rct3
anuragkanungo Mar 9, 2015
abb207c
Merge pull request #3200 from learningequality/nalanda-rct3
jamalex Mar 9, 2015
e6f34b2
Merge pull request #3156 from learningequality/develop
jamalex Mar 9, 2015
1f19654
Merge branch 'central-master' of github.com:learningequality/ka-lite …
jamalex Mar 9, 2015
2ebd3ed
Remove exercise_mastery_view.
jamalex Mar 9, 2015
097a747
Don't download assessment items when on central server.
jamalex Mar 9, 2015
073046f
add --no-assessment-download command for setup
aronasorman Mar 10, 2015
105272d
Merge pull request #3254 from jamalex/device_metadata_fix
jamalex Mar 11, 2015
e1d6c23
Cherry pick changes from develop
MCGallaspy Mar 16, 2015
63824f6
Fix js linting issue
MCGallaspy Mar 16, 2015
f13286c
Really fix device metadata issue (cherry pick from develop)
MCGallaspy Mar 17, 2015
c29c18d
Merge remote-tracking branch 'mcgallaspy/central-develop' into centra…
MCGallaspy Mar 17, 2015
645c7f0
Merge pull request #3309 from MCGallaspy/central-develop
aronasorman Mar 17, 2015
1648ace
Merge branch 'develop' into central-develop
aronasorman Mar 20, 2015
3755b72
Merge branch '0.13.x' into central-develop
aronasorman Mar 30, 2015
d24b7ab
fix the double-colons
aronasorman Mar 30, 2015
05bf1cd
make sure we're not the central server when checking for assessment i…
aronasorman Mar 31, 2015
3aaeea8
wrap unpack assessment item handling in settings.CENTRAL_SERVER state…
aronasorman Mar 31, 2015
5f82a77
Merge pull request #3454 from learningequality/0.13.x
aronasorman Apr 3, 2015
99dbcdb
Merge branch '0.13.x' into central-develop
Apr 6, 2015
c12f0ce
Merge pull request #3482 from jamalex/restore_response_count_to_its_f…
jamalex Apr 6, 2015
a276b0c
Additional diagnostic error data for bad client device import.
jamalex Apr 7, 2015
8a4d4be
Set the django module if given by kwargs.
Apr 7, 2015
f0bd27c
use CENTRAL_SERVER_URL instead of SECURESYNC_PROTOCOL +
Apr 7, 2015
34a27be
error out on registration when we get an invalid user error message.
Apr 7, 2015
65330fb
parse self.url.
Apr 7, 2015
eb670d5
Stop using deprecated command, update requirements, fix import
MCGallaspy Mar 31, 2015
8ffa4d2
use absolute path in kalitectl.py, update screenshot command
MCGallaspy Apr 1, 2015
ea857a6
Remove errant pdb.set_trace
MCGallaspy Apr 1, 2015
3ae33e7
Add language option to screenshots management command
MCGallaspy Apr 2, 2015
3510566
Fix language option on screenshot mgmt command
MCGallaspy Apr 2, 2015
3d273f2
Set up docs for translation. Need translated pofiles.
MCGallaspy Apr 2, 2015
ab8bc62
Don't build screenshots when making messages
MCGallaspy Apr 2, 2015
263e52b
Update README
MCGallaspy Apr 6, 2015
b0a9d48
Add dep for python 2.6
MCGallaspy Apr 7, 2015
83006de
Merge pull request #3490 from MCGallaspy/pick-docs-intl
aronasorman Apr 7, 2015
a253c1b
Merge pull request #3498 from learningequality/0.13.x
jamalex Apr 9, 2015
c3cc5ef
Merge pull request #3515 from jamalex/0.13-fixes
jamalex Apr 12, 2015
626f915
Merge branch 'develop' into central-develop
May 27, 2015
9801731
add missing import.
May 27, 2015
452e19e
Merge remote-tracking branch 'refs/remotes/u/develop' into central-de…
May 28, 2015
4d408f3
Merge branch 'develop' into central-develop
May 29, 2015
4771c3c
Merge branch 'develop' into central-develop
Jun 1, 2015
171f2f7
Merge branch '0.14.x' of github.com:learningequality/ka-lite into cen…
jamalex Jul 7, 2015
1c49921
Merge branch '0.14.x' of github.com:learningequality/ka-lite into cen…
jamalex Jul 7, 2015
de616c3
Merge branch 'tweaks_based_on_central_server' into central-develop
jamalex Jul 9, 2015
c682fa4
Merge pull request #4084 from jamalex/setup_fixes
jamalex Jul 11, 2015
5942943
Merge branch 'tweaks_based_on_central_server' of github.com:jamalex/k…
jamalex Jul 12, 2015
259d8ae
Merge branch '0.14.x' of github.com:learningequality/ka-lite into cen…
jamalex Jul 24, 2015
cabc30f
Merge branch '0.14.x' of github.com:learningequality/ka-lite into cen…
jamalex Jul 24, 2015
2a5fa54
Merge pull request #4161 from learningequality/0.14.x
jamalex Jul 25, 2015
590752e
Softload KHAN_ASSESSMENT_ITEM_DATABASE_PATH in case DB not defined.
jamalex Jul 27, 2015
1f87909
Merge pull request #4171 from jamalex/central_server_fixes
jamalex Jul 28, 2015
8adb6f3
Merge pull request #4207 from jamalex/securesync_fixes
jamalex Aug 5, 2015
68c6ffe
Merge pull request #4230 from rtibbles/zone_space_coach_reports
jamalex Aug 13, 2015
30f8bd1
Merge pull request #4236 from rtibbles/zone_space_coach_reports
jamalex Aug 13, 2015
6f62e04
Merge pull request #4243 from learningequality/0.14.x
jamalex Aug 15, 2015
41923fc
Safer BaseView.remove: remove el before reflow, no infinite recursion.
jamalex Aug 18, 2015
d6abcae
Merge pull request #4252 from jamalex/safer_removal_recursion_14
jamalex Aug 18, 2015
0c49a77
Merge pull request #4255 from jamalex/fix_container_overflow
jamalex Aug 18, 2015
fbc2912
Merge pull request #4279 from learningequality/0.14.x
aronasorman Aug 24, 2015
c01942e
Merge remote-tracking branch 'upstream/0.15.x' into central-develop
MCGallaspy Sep 18, 2015
719921a
Remove duplicate TestCase subclass
MCGallaspy Sep 18, 2015
361834b
Merge pull request #4455 from MCGallaspy/central-develop
MCGallaspy Sep 18, 2015
1323db0
Add get_cookie to base module & global scope
MCGallaspy Sep 21, 2015
cd4cb41
Do not use os-specific separator
MCGallaspy Sep 22, 2015
e418511
Massage the Popen arguments into windows form
MCGallaspy Sep 22, 2015
4951c10
Merge pull request #4465 from MCGallaspy/central-develop
rtibbles Sep 22, 2015
90d20c6
Merge pull request #4498 from MCGallaspy/central-develop
rtibbles Sep 24, 2015
d7cdc84
Merge pull request #4513 from learningequality/0.15.x
rtibbles Oct 8, 2015
dc56afc
Merge pull request #4683 from learningequality/0.15.x
aronasorman Nov 24, 2015
c789b22
Merge remote-tracking branch 'origin/0.16.x' into central-develop
aronasorman Mar 17, 2016
bf2cfa4
Merge pull request #5014 from learningequality/update-central-develop
jamalex Mar 21, 2016
cb25c26
Merge pull request #5034 from jamalex/pin_npm_versions
jamalex Mar 23, 2016
45cc3e4
Add options object to reference org_id from to ZoneSelectView in data…
rtibbles Apr 20, 2016
a118a2d
Merge pull request #5095 from rtibbles/central-develop-org-id
jamalex Apr 20, 2016
bdf518c
Remove .gitmodules file causing RTD to break
Nov 14, 2016
635c5ea
Remove unused submodule for RTD to build
Nov 16, 2016
a2b59b0
Make version visible in docs for installation guide - fixes #5165
Mar 16, 2017
3555f82
Merge tag '0.16.x' into central-develop
Jul 4, 2019
9272dcf
Merge remote-tracking branch 'upstream/0.16.x' into central-develop
Jul 4, 2019
3fccd47
Merge branch 'central-develop' into central-develop-into-0.17.x
Jul 15, 2019
a56efba
Remove duplicated line
Jul 15, 2019
54bc417
Remove unused JS and cherry-picked CSS from #3033
Jul 16, 2019
650a95d
Remove unused .json file from #3033
Jul 16, 2019
e554397
Remove Nalanda-specific code from #3033
Jul 16, 2019
338fc49
call_outside_command_with_output moved to central server
Jul 17, 2019
f2ae87c
Remove debug statement
Jul 17, 2019
5161c9b
Remove unreferenced JS library jquery.cookie.js
Sep 2, 2019
bc367a0
Unify approach from 0.17.x and central-develop
Sep 2, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ var ZoneSelectView = Backbone.View.extend({

template: require('./hbtemplates/zone-select.handlebars'),

initialize: function() {
initialize: function(options) {
// Create collections
this.zone_list = new Models.ZoneCollection();

Expand All @@ -117,7 +117,7 @@ var ZoneSelectView = Backbone.View.extend({
// Fetch collection by org_id
this.zone_list.fetch({
data: $.param({
"org_id": this.options.org_id,
"org_id": options.org_id,
"limit": 0
})
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ require("browsernizr/test/canvas");
require("browsernizr/test/touchevents");
var Modernizr = require("browsernizr");

// Expose this as a global object for use in central server inline JS.
global.getCookie = require("utils/get_cookie");

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This needs to be configurable and only switched on in the central server.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay, this might actually be harmless to the rest of the KA Lite application, wouldn't you think so @rtibbles ?

global.$ = $;
global._ = _;
global.sessionModel = new SessionModel();
Expand Down
67 changes: 67 additions & 0 deletions kalite/packages/bundled/fle_utils/django_utils/command.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,73 @@ def call_command_async(cmd, *args, **kwargs):
return call_command_subprocess(cmd, *args, **kwargs)


def call_outside_command_with_output(command, *args, **kwargs):
"""
Runs call_command for a KA Lite installation at the given location,
and returns the output.
"""

if settings.IS_SOURCE:
assert "kalite_dir" in kwargs, "don't forget to specify the kalite_dir"
kalite_dir = kwargs.pop('kalite_dir')
else:
kalite_dir = None

# some custom variables that have to be put inside kwargs
# or else will mess up the way the command is called
output_to_stdout = kwargs.pop('output_to_stdout', False)
output_to_stderr = kwargs.pop('output_to_stderr', False)
wait = kwargs.pop('wait', True)

# build the command
if kalite_dir:
kalite_bin = os.path.join(kalite_dir, "bin", "kalite")
else:
kalite_bin = 'kalite'

cmd = (kalite_bin, "manage", command) if os.name != "nt" else (sys.executable, kalite_bin, "manage", command)
for arg in args:
cmd += (arg,)

kwargs_keys = kwargs.keys()

# Ensure --settings occurs first, as otherwise docopt parsing barfs
kwargs_keys = sorted(kwargs_keys, cmp=lambda x,y: -1 if x=="settings" else 0)

for key in kwargs_keys:
val = kwargs[key]
key = key.replace(u"_",u"-")
prefix = u"--" if command != "runcherrypyserver" else u"" # hack, but ... whatever!
if isinstance(val, bool):
cmd += (u"%s%s" % (prefix, key),)
else:
# TODO(jamalex): remove this replacement, after #4066 is fixed:
# https://github.com/learningequality/ka-lite/issues/4066
cleaned_val = unicode(val).replace(" ", "")
cmd += (u"%s%s=%s" % (prefix, key, cleaned_val),)

# we also need to change the environment to point to the the local
# kalite settings. This is especially important for when the
# central server calls this function, as if we don't change this,
# kalitectl.py wil look for centralserver.settings instead of
# kalite.settings.
new_env = os.environ.copy()
new_env["DJANGO_SETTINGS_MODULE"] = kwargs.get("settings") or "kalite.settings"
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should ideally be configurable and only switched on in the central server. The whole function is only used in a test, though, centralserver/central/tests/utils/distributed_server_factory.py.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since all this code is used from the central server's test suite, I'm moving it there.


p = subprocess.Popen(
cmd,
shell=False,
# cwd=os.path.split(cmd[0])[0],
stdout=None if output_to_stdout else subprocess.PIPE,
stderr=None if output_to_stderr else subprocess.PIPE,
env=new_env,
)
out = p.communicate() if wait else (None, None)

# tuple output of stdout, stderr, exit code and process object
return out + (1 if out[1] else 0, p)


class LocaleAwareCommand(BaseCommand):
option_list = BaseCommand.option_list + (
make_option('--locale',
Expand Down
6 changes: 3 additions & 3 deletions kalite/packages/bundled/securesync/api_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@

class BaseClient(object):

def __init__(self, host="%s://%s/" % (settings.SECURESYNC_PROTOCOL, settings.CENTRAL_SERVER_HOST), require_trusted=True, verbose=True):
self.parsed_url = urllib2.urlparse.urlparse(host)
self.url = "%s://%s" % (self.parsed_url.scheme, self.parsed_url.netloc)
def __init__(self, host=None, require_trusted=True, verbose=True):
self.url = host or settings.CENTRAL_SERVER_URL
self.parsed_url = urllib2.urlparse.urlparse(self.url)
self.require_trusted = require_trusted
self.verbose = verbose

Expand Down
6 changes: 4 additions & 2 deletions kalite/packages/bundled/securesync/devices/api_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,15 +49,17 @@ def register_device(request):
try:
if not client_device.verify():
# We've been getting this verification error a lot, even when we shouldn't. Send more details to us by email so we can diagnose.
msg = "\n\n".join([request.body, client_device._hashable_representation(), str(client_device.validate()), client_device.signed_by_id, client_device.id, str(request)])
import inspect
d = client_device
msg = "\n\n".join([str(msg) for msg in [request.body, d._hashable_representation(), d.__dict__, d.__class__, inspect.getfile(d.__class__), local_version, d.description, d.signed_by_id, d.id, request]])
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks like debugging noise?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reverting back to the former debug email.

send_mail("Client device did not verify", msg, "[email protected]", ["[email protected]"])
return JsonResponseMessageError("Client device must be self-signed with a signature matching its own public key!", code=EC.CLIENT_DEVICE_INVALID_SIGNATURE)
except Exception as e:
# Can't properly namespace to a particular Exception here, since the only reason we would be getting here is
# that what should be proper exception namespacing in code being called isn't correctly catching this exception
msg = "\n\n".join([request.body, client_device._hashable_representation(), "Exception: %s" % e, str(type(e)), client_device.signed_by_id, client_device.id, str(request)])
send_mail("Exception while verifying client device", msg, "[email protected]", ["[email protected]"])
return JsonResponseMessageError("Client device must be self-signed with a signature matching its own public key!", code=EC.CLIENT_DEVICE_INVALID_SIGNATURE)
return JsonResponseMessageError("Client device must be self-signed with a signature matching its own public key.", code=EC.CLIENT_DEVICE_INVALID_SIGNATURE)

try:
zone = register_self_registered_device(client_device, models, data)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ def handle(self, *args, **options):
csrftoken = s.cookies['csrftoken_central']
login_data = dict(username=options["username"], password=options["password"], csrfmiddlewaretoken=csrftoken, next='/')
r = s.post(login_url, data=login_data, headers={"Referer": login_url})
assert r.status_code == 200, "Error logging into central server: " + r.content
assert r.status_code == 200 and "Incorrect user" not in r.content, "Error logging into central server: " + r.content
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The change looks like a desired precision from the commit msg: 34a27be


# register on the central server
reg_url = client.get_registration_url()
Expand All @@ -80,5 +80,3 @@ def handle(self, *args, **options):
own_device = Device.get_own_device()
assert own_device.is_registered(), "Device was not registered successfully..."
sys.stdout.write("Device '%s' has been successfully registered to zone '%s'!\n" % (own_device.id, own_device.get_zone().id))


2 changes: 1 addition & 1 deletion kalite/version.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
# Must also be of the form N.N.N for internal use, where N is a non-negative integer
MAJOR_VERSION = "0"
MINOR_VERSION = "17"
PATCH_VERSION = "5"
PATCH_VERSION = "6.dev"
VERSION = "%s.%s.%s" % (MAJOR_VERSION, MINOR_VERSION, PATCH_VERSION)
SHORTVERSION = "%s.%s" % (MAJOR_VERSION, MINOR_VERSION)

Expand Down
97 changes: 97 additions & 0 deletions static-libraries/js/jquery.cookie.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
/**
* Cookie plugin
*
* Copyright (c) 2006 Klaus Hartl (stilbuero.de)
* Dual licensed under the MIT and GPL licenses:
* http://www.opensource.org/licenses/mit-license.php
* http://www.gnu.org/licenses/gpl.html
*
*/

/**
* Create a cookie with the given name and value and other optional parameters.
*
* @example $.cookie('the_cookie', 'the_value');
* @desc Set the value of a cookie.
* @example $.cookie('the_cookie', 'the_value', { expires: 7, path: '/', domain: 'jquery.com', secure: true });
* @desc Create a cookie with all available options.
* @example $.cookie('the_cookie', 'the_value');
* @desc Create a session cookie.
* @example $.cookie('the_cookie', null);
* @desc Delete a cookie by passing null as value. Keep in mind that you have to use the same path and domain
* used when the cookie was set.
*
* @param String name The name of the cookie.
* @param String value The value of the cookie.
* @param Object options An object literal containing key/value pairs to provide optional cookie attributes.
* @option Number|Date expires Either an integer specifying the expiration date from now on in days or a Date object.
* If a negative value is specified (e.g. a date in the past), the cookie will be deleted.
* If set to null or omitted, the cookie will be a session cookie and will not be retained
* when the the browser exits.
* @option String path The value of the path atribute of the cookie (default: path of page that created the cookie).
* @option String domain The value of the domain attribute of the cookie (default: domain of page that created the cookie).
* @option Boolean secure If true, the secure attribute of the cookie will be set and the cookie transmission will
* require a secure protocol (like HTTPS).
* @type undefined
*
* @name $.cookie
* @cat Plugins/Cookie
* @author Klaus Hartl/[email protected]
*/

/**
* Get the value of a cookie with the given name.
*
* @example $.cookie('the_cookie');
* @desc Get the value of a cookie.
*
* @param String name The name of the cookie.
* @return The value of the cookie.
* @type String
*
* @name $.cookie
* @cat Plugins/Cookie
* @author Klaus Hartl/[email protected]
*/
jQuery.cookie = function(name, value, options) {
if (typeof value != 'undefined') { // name and value given, set cookie
options = options || {};
if (value === null) {
value = '';
options = $.extend({}, options); // clone object since it's unexpected behavior if the expired property were changed
options.expires = -1;
}
var expires = '';
if (options.expires && (typeof options.expires == 'number' || options.expires.toUTCString)) {
var date;
if (typeof options.expires == 'number') {
date = new Date();
date.setTime(date.getTime() + (options.expires * 24 * 60 * 60 * 1000));
} else {
date = options.expires;
}
expires = '; expires=' + date.toUTCString(); // use expires attribute, max-age is not supported by IE
}
// NOTE Needed to parenthesize options.path and options.domain
// in the following expressions, otherwise they evaluate to undefined
// in the packed version for some reason...
var path = options.path ? '; path=' + (options.path) : '';
var domain = options.domain ? '; domain=' + (options.domain) : '';
var secure = options.secure ? '; secure' : '';
document.cookie = [name, '=', encodeURIComponent(value), expires, path, domain, secure].join('');
} else { // only name given, get cookie
var cookieValue = null;
if (document.cookie && document.cookie != '') {
var cookies = document.cookie.split(';');
for (var i = 0; i < cookies.length; i++) {
var cookie = jQuery.trim(cookies[i]);
// Does this cookie string begin with the name we want?
if (cookie.substring(0, name.length + 1) == (name + '=')) {
cookieValue = decodeURIComponent(cookie.substring(name.length + 1));
break;
}
}
}
return cookieValue;
}
};