Giter Site home page Giter Site logo

Comments (13)

cdeszaq avatar cdeszaq commented on May 21, 2024

I ran across this article which links to an "improved version" of the plugin that adds multiple cookie functionality. http://jquery-howto.blogspot.com/2010/09/jquery-cookies-getsetdelete-plugin.html#jQuery-Cookie-plugin

from jquery-cookie.

sunjay avatar sunjay commented on May 21, 2024

My issue deals with more of getting all the cookie values. Say for example if the user didn't know which cookies he or she wanted, or if he or she just wanted to inspect all of them.

from jquery-cookie.

sunjay avatar sunjay commented on May 21, 2024

Whoops! Sorry, I accidentally closed the issue.

from jquery-cookie.

carhartl avatar carhartl commented on May 21, 2024

Still struggling to find a real use case for this. If you need to know whether a cookie exists or not you can just check

$.cookie('foo') === null

from jquery-cookie.

oomlaut avatar oomlaut commented on May 21, 2024

@sunjay03 "Say for example if the user didn't know which cookies he or she wanted, or if he or she just wanted to inspect all of them."
In Chrome, for example, in the Resources tab of the inspection panel there is an expandable heading for Cookies, where you can view all the cookie data associated with the current domain. Does this address the issue you mention?

from jquery-cookie.

sunjay avatar sunjay commented on May 21, 2024

Here is a real example:
You are writing a script which deals with saving page settings for the user. Instead of writing a million lines of code to find each setting individually, you decide to save each setting with a certain prefix:

var PREFIX = "p_setting_";
// example: save each setting individually (where the values would be found through the user's input or something
$.cookie(PREFIX+"background-color", "blue");
$.cookie(PREFIX+"background-image", "someimage.png");
$.cookie(PREFIX+"font-family", "Verdana");
// etc.

// if $.cookie() supported returning an object with all the names and values, it would be easy to load the settings back into the page.

$.each($.cookie(), function(setting, value) {
    if (setting.substr(0, PREFIX.length) === PREFIX) {
        $('body').css(setting.substr(PREFIX.length), value);
    }
});

// Where as the alternative:
$('body').css("background-color", $.cookie(PREFIX+"background-color"));
$('body').css("background-image", $.cookie(PREFIX+"background-image"));
$('body').css("font-family", $.cookie(PREFIX+"font-family"));
// etc.

// This example may not look very hard, but as the number of settings get larger, this method would get very tedious. 

This use case demonstrates the power of adding the functionality of having either an object or a multidimensional array returned as the result of an empty $.cookie() call. It would allow for quick iteration of all values and in cases like this, more optimized code.

from jquery-cookie.

sunjay avatar sunjay commented on May 21, 2024

I don't know why it keeps closing the issue. Sorry about that.

from jquery-cookie.

pboling avatar pboling commented on May 21, 2024

@sunjay03: there are two forks which do this. benz303 did the work, and I merged his $.cookie() work in with another bug fix from sidereel. If you want to checkout my fork: https://github.com/pboling/jquery-cookie

from jquery-cookie.

Krinkle avatar Krinkle commented on May 21, 2024

Another use case is clearing of cookies. One may want to have some kind of killer function that deletes all cookies (or at least all with a certain prefix)

from jquery-cookie.

johan avatar johan commented on May 21, 2024

This batch read, and the corresponding batch write:
$.cookie({ "object": "with", "cookies": "to", "set": "or", "delete": null });
...are implemented in pull request #123

from jquery-cookie.

muxa avatar muxa commented on May 21, 2024

I've implemented a version of this (https://github.com/muxa/jquery-cookie) - $.cookie() returns an array of cookie names. Pull request pending (#129).
Update: tests added

from jquery-cookie.

carhartl avatar carhartl commented on May 21, 2024

I believe the use case @sunjay03 brought up is now fulfillable with the newly added json support, and I believe in a technically superior way even (just keep all of the belonging properties in a single object that gets serialized to the cookie).

Regarding the "clear all cookies" use case I'm probably going to merge @muxa's PR (#129).

from jquery-cookie.

carhartl avatar carhartl commented on May 21, 2024

c32ed09

from jquery-cookie.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.