{"id":22642768,"url":"https://github.com/datchley/jquery-utils","last_synced_at":"2025-03-29T05:43:04.604Z","repository":{"id":21585810,"uuid":"24905834","full_name":"datchley/jquery-utils","owner":"datchley","description":"jQuery Utilities and Extensions","archived":false,"fork":false,"pushed_at":"2014-11-16T03:48:34.000Z","size":280,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-02-03T16:59:21.163Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/datchley.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2014-10-07T18:43:27.000Z","updated_at":"2018-06-21T14:40:14.000Z","dependencies_parsed_at":"2022-08-19T16:50:56.187Z","dependency_job_id":null,"html_url":"https://github.com/datchley/jquery-utils","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/datchley%2Fjquery-utils","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/datchley%2Fjquery-utils/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/datchley%2Fjquery-utils/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/datchley%2Fjquery-utils/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/datchley","download_url":"https://codeload.github.com/datchley/jquery-utils/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246145015,"owners_count":20730493,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-12-09T05:08:23.978Z","updated_at":"2025-03-29T05:43:04.581Z","avatar_url":"https://github.com/datchley.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# jQuery Utils  \n[![Build Status](https://travis-ci.org/datchley/jquery-utils.svg?branch=master)](https://travis-ci.org/datchley/jquery-utils)\n\n[![Sauce Test Status](https://saucelabs.com/browser-matrix/datchley.svg)](https://saucelabs.com/u/datchley)\n\nSupports jQuery **1.8.x** to latest **1.11.x**\n\nThis is a collection of jQuery extensions that provide for a number of\nactions that I repeat often in jQuery based apps; or have been useful\nthings that were needed that would probably benefit the jQuery user \ncommunity at some point.\n\nThough some of the concepts are mine; a number were the idea of a co-worker,\nTom Bremer.\n\nYou can install the modules together or separately, based on need. There are\ncurrently two main extensions:\n\n+ Class-like Properties extension\n+ DOM Utilities for manipulation\n+ String utility methods\n\n## Class-like Properties\nThis extension lets you treat an attribute's value as a collection of names/strings, \njust like the 'class' attribute. \n\nFor example, given a custom attribute called `test-prop`, you can do the following:\n\n```html\n\u003cdiv  id=\"my-element\" test-prop=\"a b c\"\u003e\u003c/div\u003e\n\u003cscript\u003e\n    var $elm = $('#my-element');\n\n    // Check for cprop values\n    if ($elm.hasCProp('test-prop', 'a')) {\n        // Append cprop values\n        $elm.addCProp('test-prop', 'd e f');\n    }\n    else {\n        if ($elm.hasCProp('test-prop', 'x y x')) {\n            // Remove cprop values\n            $elm.removeCProp('test-prop', 'x');\n        }\n    }\n\n    // toggle a cprop value\n    $(document).on('click', function() {\n        $elm.toggleCProp('test-prop', 'b');\n    });\n\n\u003c/script\u003e\n```\n\n+ **$.hasCProp(property_name, value)**\n\n  Check if the custom property name _property_name_ has any of the names\n  contained in value.\n  - **property_name** `{string}` - is the string name of the custom property or attribute\n  - **value** `{string}` - is a string of space separated names to check against.\n\n+ **$.addCProp(property_name, value)**\n \n  Append the names contained in _values_ to the custom property _property_name_. Will not\n  duplicate if already exists.\n  - **property_name** `{string}` - is the string name of the custom property or attribute\n  - **value** `{string}` - is a string of space separated names to check against.\n  \n+ **$.removeCProp(property_name, value)**\n\n  Remove the names contained in _values_ from the custom property _property_name_.\n  - **property_name** `{string}` - is the string name of the custom property or attribute\n  - **value** `{string}` - is a string of space separated names to check against.\n  \n+ **$.toggleCProp(property_name [, value, flag])**\n\n  Add or remove one or more names from the value of the _property_name_ custom property for each \n  element in the set of matched elements, depending on either the name's presence or the value of the flag argument.\n  - **property_name** `{string}` - is the string name of the custom property or attribute\n  - **value** `{string}` - is a string of space separated names to add or remove\n  - **flag** `{boolean}` - a boolean value determining whether the names in _value_ are added (_true_)\n    or removed (_false).\n  \n  \n## DOM Utilities\nSome useful extensions for manipulating and managing the DOM.\n\nThis extension provides:\n+ $.moveTo() - for moving elements to another element\n+ $.isElement() - to check if objects are HTMLElements or DOMNodes\n+ `DOMChanged` event - triggered when using jQuery DOM manipulation methods\n\nFor example:\n\n```html\n\u003cdiv id=\"m1\" class=\"moveable\"\u003eItem\u003c/div\u003e\n\u003cdiv id=\"m2\" class=\"moveable\"\u003eItem\u003c/div\u003e\n\u003cdiv id=\"m3\" class=\"moveable\"\u003eItem\u003c/div\u003e\n\u003cdiv id=\"container\"\u003e\u003c/div\u003e\n\n\u003cscript\u003e\n    var locations = ['inside','before','after'],\n        $container = $('#container'),\n        $moveables = $('.moveable'),\n        i = 0;\n\n    $moveables.each(function() {\n        if ($.isElement(this)) {\n            $(this).moveTo($container, locations[i++]);\n        }\n    });\n\u003c/script\u003e\n```\n+ **$.isElement(object)**\n\n  Retruns _true_ if the _object_ passed in is an HTMLElement or DOM Node. Returns\n  _false_ otherwise.\n  - **object** `{mixed}` - the object to test\n\n+ **$.moveTo(container, location [, wrapper])**\n \n  Move every element in the set of matched elements in relation to the target\n  _container_, based on the passed _location_ and optionally wrapped by _wrapper_.\n  - **container** `{Selector|HTML|Element|jQuery}` - the target element in or around\n    which the elements will be moved.\n  - **location** `{string}` - one of `inside`, to move the elements inside the target\n    as the first child, `after` to move them directly after the target,  or `before` \n    to move them directly before the target container.\n  - **wrapper** `{Selector|HTML|Element|jQuery}` - optional wrapper element to wrap\n    all the match elements after they are moved.\n\n+ **DOMChanged** Event\n\n  The `DOMChanged` event is triggered when using any of the jQuery DOM manipulation\n  methods that remove or place an element.  The type of method is passed in a data\n  object as a parameter, ie., `{ 'method': 'append' }`.\n  \n## String methods\nThis provies a handful of useful string manipulation methods, both as jQuery methods and as extensions to the native String object.\n\nFor example,\n\n```javascript\n\nvar html=\"\u003cp\u003ea string with special chars\u003c/p\u003e\";\n    escaped = html.escapeHtml();\n\n// escaped = \"\u0026lt;p\u0026gt;a string with special chars\u0026lt;\u0026#x2F;p\u0026gt;\"\n\nvar input = \"$\" + 4.56,\n    escaped_input = input.escapeRegExp();\n\n// escaped_input = \"\\$4\\.56\"\n\n```\n\n+ **$.escapeHtml(_string_)** or **_string_.escapeHtml()**\n    \n    Converts html special characters into their respective html entities or escape sequence so they can be output correctly for viewing.\n\n+ **$.escapeRegExp(_string_)** or **_string_.escapeRegExp()**\n\n    Will escape any regular expression meta characters in a string so that it can be used to build a RegExp object and properly match those meta characters.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdatchley%2Fjquery-utils","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdatchley%2Fjquery-utils","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdatchley%2Fjquery-utils/lists"}