diff --git a/.bowerrc b/.bowerrc
new file mode 100644
index 00000000..a33fd7ab
--- /dev/null
+++ b/.bowerrc
@@ -0,0 +1,4 @@
+{
+ "directory": "libs",
+ "json": "package.json"
+}
\ No newline at end of file
diff --git a/.gitignore b/.gitignore
index 784f0ac6..440a178d 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,2 +1,7 @@
node_modules/
+libs/
gh-pages/
+demo/
+.idea
+.DS_Store
+.idea
diff --git a/CHANGELOG.md b/CHANGELOG.md
new file mode 100644
index 00000000..6d6f1a22
--- /dev/null
+++ b/CHANGELOG.md
@@ -0,0 +1,185 @@
+
+### v0.5.6 (2014-09-25)
+
+
+#### Bug Fixes
+
+* **draggable:** namespace events with unique ids ([79aff38c](http://github.com/ducksboard/gridster.js/commit/79aff38c60cc6ce2c0f0160bd3c6f93cb2511642))
+
+
+### v0.5.5 (2014-07-25)
+
+
+#### Bug Fixes
+
+* **gridster:** fire `positionschanged` when widget orig position changes ([9926ceff](http://github.com/ducksboard/gridster.js/commit/9926ceff59cba49c71542e45aa095be35eb1df58))
+
+
+### v0.5.4 (2014-07-16)
+
+
+#### Bug Fixes
+
+* **gridster:** serialize returns an Array object, not a jQuery object ([93df6cf6](http://github.com/ducksboard/gridster.js/commit/93df6cf6907fd0fb8787b3d068c9a9c467dcc020), closes [#394](http://github.com/ducksboard/gridster.js/issues/394))
+
+
+### v0.5.3 (2014-07-04)
+
+
+#### Bug Fixes
+
+* **gridster:**
+ * custom `ignore_dragging` overwrites the default value ([6bcfa6e1](http://github.com/ducksboard/gridster.js/commit/6bcfa6e16e4a88cbb5efff1ce29308737884a89d))
+ * sort widgets appropriately when reading them from DOM ([5c6d25cb](http://github.com/ducksboard/gridster.js/commit/5c6d25cbbe3de021806408f3cff6cb1e139c0a25))
+
+
+#### Features
+
+* make gridster AMD compatible ([589d7fd5](http://github.com/ducksboard/gridster.js/commit/589d7fd509a570fd02666c2f8231545211d6c83f))
+* **gridster:** move widget up when added if there is space available ([8ec307b6](http://github.com/ducksboard/gridster.js/commit/8ec307b6f7173e94610409adcb1671372cc2c67d))
+
+
+### v0.5.2 (2014-06-16)
+
+
+#### Bug Fixes
+
+* **draggable:**
+ * handle both touch and click events ([021a6c23](http://github.com/ducksboard/gridster.js/commit/021a6c23e851210c1b817bd353a1e5e19ce10b90), closes [#207](http://github.com/ducksboard/gridster.js/issues/207), [#236](http://github.com/ducksboard/gridster.js/issues/236), [#329](http://github.com/ducksboard/gridster.js/issues/329), [#380](http://github.com/ducksboard/gridster.js/issues/380))
+ * replaced scrollX/Y with scrollLeft/Top ([bb7463a3](http://github.com/ducksboard/gridster.js/commit/bb7463a3241750397492dfbac133cea193f0254f))
+ * fix offset during drag ([c726c4ad](http://github.com/ducksboard/gridster.js/commit/c726c4ad9c18fea95e4b46b9bacd36c42aa9691c))
+ * bind drag events to $document ([dd6c7420](http://github.com/ducksboard/gridster.js/commit/dd6c7420087d5810a9f6b02bf9d81a04a60ae840))
+* **gridster:**
+ * fix add_widget to use correct size_y when adding rows ([7d22e6c8](http://github.com/ducksboard/gridster.js/commit/7d22e6c8b201de33e33def77a93dc9009d0aa4cb))
+ * Removing previously added style tags before adding new one. ([93c46ff4](http://github.com/ducksboard/gridster.js/commit/93c46ff45ebe59f3658b7f32f05b67109aa87311))
+
+
+#### Features
+
+* **draggable:**
+ * allow ignore_dragging config option to be a function ([69fcfe45](http://github.com/ducksboard/gridster.js/commit/69fcfe459678e833cb53de040b9fbc96dd687543))
+ * option to not remove helper on drag stop ([03910df9](http://github.com/ducksboard/gridster.js/commit/03910df967a1ae7bcb2fa3aadd58255e0bcbf327))
+
+
+### v0.5.1 (2014-03-05)
+
+
+#### Features
+
+* **collision:** overlapping region as a config option ([720d487e](http://github.com/ducksboard/gridster.js/commit/720d487e3988593e2c60909c88aaff13fbd4f842))
+* **coords:**
+ * allow both (left/x1) and (top/y1) attr keys ([6f22217f](http://github.com/ducksboard/gridster.js/commit/6f22217f056e4fc52f6405f2af49596105aae150))
+ * add destroy method ([fdeee4f6](http://github.com/ducksboard/gridster.js/commit/fdeee4f636266c7a0579ced833f04fec013b6863))
+* **draggable:** keep container position prop if different than static ([04868a38](http://github.com/ducksboard/gridster.js/commit/04868a384d655d110f2d153d2fddb94b1c6d54a9))
+* **gridster:** destroy element's data and optionally remove from DOM ([dc09f191](http://github.com/ducksboard/gridster.js/commit/dc09f191d8503669cfa4737122c77cb0f5b9c3d2))
+
+
+## v0.5.0 (2014-02-14)
+
+
+#### Bug Fixes
+
+* **autogrow:** refining autogrow_cols behavior and grid width issues ([835c2df8](http://github.com/ducksboard/gridster.js/commit/835c2df84419a92b1641b687fcf083f3ff102627))
+* **resize.stop:** Call resize.stop at the latest possible moment ([e21f63a0](http://github.com/ducksboard/gridster.js/commit/e21f63a05a539f5c611eb49cd6861b1e38b36531))
+
+
+#### Features
+
+* **draggable:** Add toggle draggable method. ([073fdc40](http://github.com/ducksboard/gridster.js/commit/073fdc40e0a94dd371646fc54cd420e3ddab0254))
+
+
+### v0.4.4 (2014-02-13)
+
+
+#### Features
+
+* **resize:** add start/stop/resize event triggers ([7ca8deec](http://github.com/ducksboard/gridster.js/commit/7ca8deec8559d950097a6dc351cb0c6fcef3458d))
+
+
+### v0.4.3 (2014-02-11)
+
+
+#### Bug Fixes
+
+* **generated-styles:** cleaning cached serializations properly ([f8b04f29](http://github.com/ducksboard/gridster.js/commit/f8b04f298e12e46ca9b07f0bae0abc6b08ed6e18))
+
+
+### v0.4.2 (2014-02-07)
+
+
+#### Bug Fixes
+
+* recalculate grid width when adding widgets ([47745978](http://github.com/ducksboard/gridster.js/commit/4774597834300601fc81d5111a31a8c1672c55e1))
+
+
+### v0.4.1 (2014-02-07)
+
+#### Bug Fixes
+
+* add resize.min_size option to default config object ([5672edb0](http://github.com/ducksboard/gridster.js/commit/5672edb05e39c6b9ff5e3ca31d68c9e94dfaa617))
+
+
+## v0.4.0 (2014-02-07)
+
+
+#### Bug Fixes
+
+* **gridster:**
+ * leaking options with multiple Gridster instances ([07c71097](http://github.com/ducksboard/gridster.js/commit/07c7109771094d98be51d68448a20e1d2987b35d))
+ * resize.axes default option only 'both' ([62988780](http://github.com/ducksboard/gridster.js/commit/6298878077d5db129daa9780939fec5237b82af9))
+* **licenses:** add required copyright message for underscore ([b563c094](http://github.com/ducksboard/gridster.js/commit/b563c094cf0f3a5da2288492f95759ae32e8967c))
+* **readme:** link title jsfiddle -> jsbin, edit 5) of process steps ([0641aa89](http://github.com/ducksboard/gridster.js/commit/0641aa89833ecf9d167f7d8e89ee8bd5b4304248))
+
+
+#### Features
+
+* **draggable:**
+ * method to set drag limits dynamically ([d4482ec1](http://github.com/ducksboard/gridster.js/commit/d4482ec1476f8a0b6fb6cdeb25b7774ef678d81c))
+ * support horizontal scrolling while dragging ([ae4921b7](http://github.com/ducksboard/gridster.js/commit/ae4921b70798944211267cacf8a89e62d0818369))
+* **gridster:** increase grid width when dragging or resizing ([37c4e943](http://github.com/ducksboard/gridster.js/commit/37c4e94358b9392710452b9e7f96454837bf9845))
+* **resize:** add option to set min_size of a widget ([ff511872](http://github.com/ducksboard/gridster.js/commit/ff511872e65992ee89bd2a88d862caaf99733f38))
+
+
+## v0.3.0 (2013-11-18)
+
+
+#### Features
+
+* **draggable:**
+ * method to set drag limits dynamically ([d4482ec1](http://github.com/ducksboard/gridster.js/commit/d4482ec1476f8a0b6fb6cdeb25b7774ef678d81c))
+ * support horizontal scrolling while dragging ([ae4921b7](http://github.com/ducksboard/gridster.js/commit/ae4921b70798944211267cacf8a89e62d0818369))
+* **gridster:** increase grid width when dragging or resizing ([b61df653](http://github.com/ducksboard/gridster.js/commit/b61df6535f728970fb8c6f25a208275dbde66550))
+
+
+### v0.2.1 (2013-10-28)
+
+
+#### Features
+
+* **resize:** Add start/stop/resize callbacks ([d4ec7140](http://github.com/ducksboard/gridster.js/commit/d4ec7140f736bc30697c75b54ed3242ddf1d75b9))
+
+
+## v0.2.0 (2013-10-26)
+
+
+#### Bug Fixes
+
+* fixes and improvements in widget-resizing. ([ae02b32b](http://github.com/ducksboard/gridster.js/commit/ae02b32b9210c6328f4acc339e215ae50c134f77), closes [#32](http://github.com/ducksboard/gridster.js/issues/32))
+* **gridster:**
+ * the preview holder should not always use `li` ([1ade74e2](http://github.com/ducksboard/gridster.js/commit/1ade74e239485b07e870fca44e1eafb3ff1ae283))
+ * overlapping widget problem ([31fd8d6b](http://github.com/ducksboard/gridster.js/commit/31fd8d6ba893e4c39b91ba30d429e37f3da30b24))
+ * Orphan preview holder when dragging is interrupted ([1b13617d](http://github.com/ducksboard/gridster.js/commit/1b13617df2ce53235bdf3a1e38f1555f529663c3))
+ * remove_widget Returns the instance of the Gridster Class ([5bfbc5c0](http://github.com/ducksboard/gridster.js/commit/5bfbc5c0b5ab49c2a7c651327ce2e0f30f594985))
+
+
+#### Features
+
+* **draggable:**
+ * new config option to move or not the dragged element ([4d9b2a84](http://github.com/ducksboard/gridster.js/commit/4d9b2a84f11cb7cb2ddad51c158d92b82e7bc447))
+ * CSS selectors support in `ignore_dragging` config opt ([0f956249](http://github.com/ducksboard/gridster.js/commit/0f95624925be97aee7a8450707e04e887e4dac58))
+ * pass previous position to the drag callback ([055cc0e4](http://github.com/ducksboard/gridster.js/commit/055cc0e4f6f9de5721986515656ac894855f9e02))
+ * Don't start new drag if previous one hasn't stopped ([91ca6572](http://github.com/ducksboard/gridster.js/commit/91ca65721c2eb32b5dec82cdc5e5e7f81dac329e))
+ * pass useful data to all drag callbacks ([8dda2410](http://github.com/ducksboard/gridster.js/commit/8dda2410f300592706985c05141ca6b702977dc0))
+* **gridster:** drag-and-drop widget resizing ([e1924053](http://github.com/ducksboard/gridster.js/commit/e19240532de0bad35ffe6e5fc63934819390adc5))
+* **utils:** add delay helper to utils ([faa6c5db](http://github.com/ducksboard/gridster.js/commit/faa6c5db0002feccf681e9f919ed583eef152773))
+
diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md
new file mode 100644
index 00000000..032a9fae
--- /dev/null
+++ b/CONTRIBUTING.md
@@ -0,0 +1,143 @@
+# Contributing to this project
+
+Please take a moment to review this document in order to make the contribution
+process easy and effective for everyone involved.
+
+Following these guidelines helps to communicate that you respect the time of
+the developers managing and developing this open source project. In return,
+they should reciprocate that respect in addressing your issue or assessing
+patches and features.
+
+
+## Using the issue tracker
+
+The issue tracker is the preferred channel for [bug reports](#bugs),
+[features requests](#features) and [submitting pull
+requests](#pull-requests), but please respect the following restrictions:
+
+* Please **do not** use the issue tracker for personal support requests (use
+ [Stack Overflow](http://stackoverflow.com)).
+
+* Please **do not** derail or troll issues. Keep the discussion on topic and
+ respect the opinions of others.
+
+
+
+## Bug reports
+
+A bug is a _demonstrable problem_ that is caused by the code in the repository.
+Good bug reports are extremely helpful - thank you!
+
+Guidelines for bug reports:
+
+1. **Use the GitHub issue search** — check if the issue has already been
+ reported.
+
+2. **Check if the issue has been fixed** — try to reproduce it using the
+ latest `master` or development branch in the repository.
+
+3. **Isolate the problem** — ideally create a [reduced test
+ case](http://css-tricks.com/6263-reduced-test-cases/) and a live example (you can use something like [jsfiddle](http://jsfiddle.net/) or [jsbin](http://jsbin.com/)) .
+
+A good bug report shouldn't leave others needing to chase you up for more
+information. Please try to be as detailed as possible in your report. What is
+your environment? What steps will reproduce the issue? What browser(s) and OS
+experience the problem? What would you expect to be the outcome? All these
+details will help people to fix any potential bugs.
+
+Example:
+
+> Short and descriptive example bug report title
+>
+> A summary of the issue and the browser/OS environment in which it occurs. If
+> suitable, include the steps required to reproduce the bug.
+>
+> 1. This is the first step
+> 2. This is the second step
+> 3. Further steps, etc.
+>
+> `` - a link to the reduced test case
+>
+> Any other information you want to share that is relevant to the issue being
+> reported. This might include the lines of code that you have identified as
+> causing the bug, and potential solutions (and your opinions on their
+> merits).
+
+
+
+## Feature requests
+
+Feature requests are welcome. But take a moment to find out whether your idea
+fits with the scope and aims of the project. It's up to *you* to make a strong
+case to convince the project's developers of the merits of this feature. Please
+provide as much detail and context as possible.
+
+**Please, use the GitHub issue search** to check if the feature has already been requested.
+
+
+
+## Pull requests
+
+Good pull requests - patches, improvements, new features - are a fantastic
+help. They should remain focused in scope and avoid containing unrelated
+commits.
+
+**Please ask first** before embarking on any significant pull request (e.g.
+implementing features, refactoring code, porting to a different language),
+otherwise you risk spending a lot of time working on something that the
+project's developers might not want to merge into the project.
+
+Code must follow, mostly, these [coding conventions](http://javascript.crockford.com/code.html) .
+
+Adhering to the following this process is the best way to get your work
+included in the project:
+
+1. [Fork](http://help.github.com/fork-a-repo/) the project, clone your fork,
+ and configure the remotes:
+
+ ```bash
+ # Clone your fork of the repo into the current directory
+ git clone https://github.com//gridster.js
+ # Navigate to the newly cloned directory
+ cd gridster.js
+ # Assign the original repo to a remote called "upstream"
+ git remote add upstream https://github.com/ducksboard/gridster.js
+ ```
+
+2. If you cloned a while ago, get the latest changes from upstream:
+
+ ```bash
+ git checkout master
+ git pull upstream master
+ ```
+
+3. Create a new topic branch (off the main project development branch) to
+ contain your feature, change, or fix:
+
+ ```bash
+ git checkout -b
+ ```
+
+4. Commit your changes in logical chunks. Please adhere to these [git commit
+ message guidelines](https://docs.google.com/document/d/1QrDFcIiPjSLDn3EL15IJygNPiHORgU1_OOAqWjiDU5Y)
+ or your code is unlikely be merged into the main project. Use Git's
+ [interactive rebase](https://help.github.com/articles/interactive-rebase)
+ feature to tidy up your commits before making them public.
+
+5. Merge or rebase the upstream development branch into your topic branch:
+
+ ```bash
+ git pull --rebase upstream master
+ ```
+
+6. Push your topic branch up to your fork:
+
+ ```bash
+ git push origin
+ ```
+
+7. [Open a Pull Request](https://help.github.com/articles/using-pull-requests/)
+ with a clear title and description.
+
+**IMPORTANT**: By submitting a patch, you agree to allow the project owner to
+license your work under the same license as that used by the project.
diff --git a/Gruntfile.js b/Gruntfile.js
new file mode 100644
index 00000000..48be9132
--- /dev/null
+++ b/Gruntfile.js
@@ -0,0 +1,183 @@
+/*global module:false*/
+module.exports = function(grunt) {
+
+ // Project configuration.
+ grunt.initConfig({
+ pkg: grunt.file.readJSON('package.json'),
+ meta: {
+ banner: '/*! <%= pkg.title || pkg.name %> - v<%= pkg.version %> - ' +
+ '<%= grunt.template.today("yyyy-mm-dd") %>\n' +
+ '<%= pkg.homepage ? "* " + pkg.homepage : "" %>\n' +
+ '* Copyright (c) <%= grunt.template.today("yyyy") %> <%= pkg.author.name %>;' +
+ ' Licensed <%= _.pluck(pkg.licenses, "type").join(", ") %> */\n\n',
+
+ minibanner: '/*! <%= pkg.title || pkg.name %> - v<%= pkg.version %> - ' +
+ '<%= grunt.template.today("yyyy-mm-dd") %> - ' +
+ '<%= pkg.homepage ? "* " + pkg.homepage + " - " : "" %>' +
+ 'Copyright (c) <%= grunt.template.today("yyyy") %> <%= pkg.author.name %>;' +
+ ' Licensed <%= _.pluck(pkg.licenses, "type").join(", ") %> */ '
+ },
+ concat: {
+ options: {
+ stripBanners: true,
+ banner: '<%= meta.banner %>'
+ },
+ dist_js: {
+ src: ['src/jquery.coords.js', 'src/jquery.collision.js', 'src/utils.js', 'src/jquery.draggable.js', 'src/jquery.<%= pkg.name %>.js'],
+ dest: 'dist/jquery.<%= pkg.name %>.js'
+ },
+
+ dist_extras_js: {
+ src: ['src/jquery.coords.js', 'src/jquery.collision.js', 'src/utils.js', 'src/jquery.draggable.js', 'src/jquery.<%= pkg.name %>.js', 'src/jquery.<%= pkg.name %>.extras.js'],
+ dest: 'dist/jquery.<%= pkg.name %>.with-extras.js'
+ },
+
+ dist_css: {
+ src: ['src/jquery.<%= pkg.name %>.css'],
+ dest: 'dist/jquery.<%= pkg.name %>.css'
+ },
+
+ dist_demo_js: {
+ src: ['src/jquery.coords.js', 'src/jquery.collision.js', 'src/utils.js', 'src/jquery.draggable.js', 'src/jquery.<%= pkg.name %>.js'],
+ dest: 'gh-pages/dist/jquery.<%= pkg.name %>.js'
+ },
+
+ dist_extras_demo_js: {
+ src: ['src/jquery.coords.js', 'src/jquery.collision.js', 'src/utils.js', 'src/jquery.draggable.js', 'src/jquery.<%= pkg.name %>.js', 'src/jquery.<%= pkg.name %>.extras.js'],
+ dest: 'gh-pages/dist/jquery.<%= pkg.name %>.with-extras.js'
+ },
+
+ dist_demo_css: {
+ src: ['src/jquery.<%= pkg.name %>.css'],
+ dest: 'gh-pages/dist/jquery.<%= pkg.name %>.css'
+ }
+ },
+ uglify: {
+ options: {
+ banner: '<%= meta.minibanner %>'
+ },
+ dist: {
+ files: {
+ 'dist/jquery.<%= pkg.name %>.min.js': ['<%= concat.dist_js.dest %>']
+ }
+ },
+
+ dist_extras: {
+ files: {
+ 'dist/jquery.<%= pkg.name %>.with-extras.min.js': ['<%= concat.dist_extras_js.dest %>']
+ }
+ },
+
+ dist_demo: {
+ files: {
+ 'gh-pages/dist/jquery.<%= pkg.name %>.min.js': ['<%= concat.dist_js.dest %>'],
+ }
+ },
+
+ dist_extras_demo: {
+ files: {
+ 'gh-pages/dist/jquery.<%= pkg.name %>.with-extras.min.js': ['<%= concat.dist_extras_js.dest %>']
+ }
+ }
+ },
+ cssmin: {
+ compress: {
+ options: {
+ keepSpecialComments: 0,
+ banner: '<%= meta.minibanner %>'
+ },
+ files: {
+ "dist/jquery.<%= pkg.name %>.min.css": ["dist/jquery.<%= pkg.name %>.css"],
+ "gh-pages/dist/jquery.<%= pkg.name %>.min.css": ["dist/jquery.<%= pkg.name %>.css"]
+ }
+ }
+ },
+ jshint: {
+ files: ['grunt.js', 'src/**/*.js', 'test/**/*.js']
+ },
+ watch: {
+ files: ['<%= lint.files %>', 'src/jquery.<%= pkg.name %>.css'],
+ tasks: 'min concat'
+ },
+ jshint: {
+ options: {
+ curly: true,
+ eqeqeq: true,
+ immed: true,
+ latedef: true,
+ newcap: true,
+ noarg: true,
+ sub: true,
+ undef: true,
+ boss: true,
+ eqnull: true,
+ browser: true
+ },
+ globals: {
+ jQuery: true
+ }
+ },
+ yuidoc: {
+ compile: {
+ "name": 'gridster.js',
+ "description": 'gridster.js, a drag-and-drop multi-column jQuery grid plugin',
+ "version": '0.1.0',
+ "url": 'http://gridster.net/',
+ "logo": 'https://ducksboard.com/static/images/svg/logo-ducksboard-black-small.svg',
+ options: {
+ paths: "src/",
+ outdir: "gh-pages/docs/"
+ }
+ }
+ },
+
+ bump: {
+ options: {
+ files: ['package.json'],
+ updateConfigs: ['pkg'],
+ commit: true,
+ commitMessage: 'Release v%VERSION%',
+ commitFiles: ['package.json', 'CHANGELOG.md', 'dist/'], // '-a' for all files
+ createTag: true,
+ tagName: 'v%VERSION%',
+ tagMessage: 'Version %VERSION%',
+ push: false,
+ pushTo: 'origin',
+ gitDescribeOptions: '--tags --always --abbrev=1 --dirty=-d' // options to use with '$ git describe'
+ }
+ },
+
+ changelog: {
+ options: {
+ dest: 'CHANGELOG.md'
+ }
+ },
+
+ watch: {
+ files: ['libs/*.js', 'src/*.js', 'src/*.css', 'Gruntfile.js'],
+ tasks: ['concat', 'uglify', 'cssmin']
+ }
+ });
+
+
+ grunt.loadNpmTasks('grunt-contrib-watch');
+ grunt.loadNpmTasks('grunt-contrib-jshint');
+ grunt.loadNpmTasks('grunt-contrib-concat');
+ grunt.loadNpmTasks('grunt-contrib-uglify');
+ grunt.loadNpmTasks('grunt-contrib-cssmin');
+ grunt.loadNpmTasks('grunt-contrib-yuidoc');
+ grunt.loadNpmTasks('grunt-bump');
+ grunt.loadNpmTasks('grunt-conventional-changelog');
+
+ // Default task.
+ grunt.registerTask('default', ['jshint', 'concat', 'uglify', 'cssmin']);
+ grunt.registerTask('build', ['default']);
+ grunt.registerTask('docs', ['yuidoc']);
+
+ grunt.registerTask('release', ['build', 'bump-only:patch', 'build', 'docs', 'changelog']);
+ grunt.registerTask('release:minor', ['build', 'bump-only:minor', 'build', 'docs', 'changelog']);
+ grunt.registerTask('release:major', ['build', 'bump-only:major', 'build', 'docs', 'changelog']);
+ grunt.registerTask('release:git', ['build', 'bump-only:git', 'build', 'docs', 'changelog', 'bump-commit']);
+ grunt.registerTask('release:commit', ['bump-commit']);
+
+};
diff --git a/README.md b/README.md
index 689f1d49..00eff37f 100644
--- a/README.md
+++ b/README.md
@@ -1,18 +1,50 @@
Gridster.js
===========
+[](https://bitdeli.com/free "Bitdeli Badge")
+
Gridster is a jQuery plugin that makes building intuitive draggable
layouts from elements spanning multiple columns. You can even
dynamically add and remove elements from the grid.
More at [http://gridster.net/](http://gridster.net/).
-License
-=======
+[Releases](https://github.com/ducksboard/gridster.js/releases)
+
+[CHANGELOG](https://github.com/ducksboard/gridster.js/blob/master/CHANGELOG.md)
+
+Gridster is maintained by Ducksboard occasionally but not actively.
+@dustmoo and @pushmatrix have also write permissions as Gridster maintainers
+they are. Thank you guys!
+
+## Forks
+
+Mr @dustmoo (maintainer of Gridster) has his own fork of gridster.js
+with some new interesting features like widget-swapping and static widgets.
+
+Can be found here: [dustmoo/gridster.js](https://github.com/dustmoo/gridster.js)
+
+@dustmoo is working in his spare time to merge all these changes into
+ducksboard/gridster.js
+
+If anyone would like to help @dustmoo improve his fork and reconcile
+it with the main library he would be happy for the help.
+
+
+## Contributing to this project
+
+Anyone and everyone is welcome to contribute. Please take a moment to review the guidelines for contributing.
+
+* [Bug reports](CONTRIBUTING.md#bugs)
+* [Feature requests](CONTRIBUTING.md#features)
+* [Pull requests](CONTRIBUTING.md#pull-requests)
+
+
+## License
Distributed under the MIT license.
-Whodunit
-========
+## Whodunit
-Gridster is built by [Ducksboard](http://ducksboard.com/).
+Gridster is built by [Ducksboard](http://ducksboard.com/) with the help of all
+these [wonderful people](https://github.com/ducksboard/gridster.js/graphs/contributors).
diff --git a/dist/jquery.gridster.css b/dist/jquery.gridster.css
index d2965b86..2d1ae608 100644
--- a/dist/jquery.gridster.css
+++ b/dist/jquery.gridster.css
@@ -1,6 +1,6 @@
-/*! gridster.js - v0.1.0 - 2012-08-14
+/*! gridster.js - v0.5.6 - 2014-09-25
* http://gridster.net/
-* Copyright (c) 2012 ducksboard; Licensed MIT */
+* Copyright (c) 2014 ducksboard; Licensed MIT */
.gridster {
position:relative;
@@ -8,25 +8,33 @@
.gridster > * {
margin: 0 auto;
- -webkit-transition: height .4s;
- -moz-transition: height .4s;
- -o-transition: height .4s;
- -ms-transition: height .4s;
- transition: height .4s;
+ -webkit-transition: height .4s, width .4s;
+ -moz-transition: height .4s, width .4s;
+ -o-transition: height .4s, width .4s;
+ -ms-transition: height .4s, width .4s;
+ transition: height .4s, width .4s;
}
-.gridster .gs_w{
+.gridster .gs-w {
z-index: 2;
position: absolute;
}
-.ready .gs_w:not(.preview-holder) {
+.ready .gs-w:not(.preview-holder) {
-webkit-transition: opacity .3s, left .3s, top .3s;
-moz-transition: opacity .3s, left .3s, top .3s;
-o-transition: opacity .3s, left .3s, top .3s;
transition: opacity .3s, left .3s, top .3s;
}
+.ready .gs-w:not(.preview-holder),
+.ready .resize-preview-holder {
+ -webkit-transition: opacity .3s, left .3s, top .3s, width .3s, height .3s;
+ -moz-transition: opacity .3s, left .3s, top .3s, width .3s, height .3s;
+ -o-transition: opacity .3s, left .3s, top .3s, width .3s, height .3s;
+ transition: opacity .3s, left .3s, top .3s, width .3s, height .3s;
+}
+
.gridster .preview-holder {
z-index: 1;
position: absolute;
@@ -43,7 +51,8 @@
transition: left .3s, top .3s!important;
}
-.gridster .dragging {
+.gridster .dragging,
+.gridster .resizing {
z-index: 10!important;
-webkit-transition: all 0s !important;
-moz-transition: all 0s !important;
@@ -51,7 +60,62 @@
transition: all 0s !important;
}
+
+.gs-resize-handle {
+ position: absolute;
+ z-index: 1;
+}
+
+.gs-resize-handle-both {
+ width: 20px;
+ height: 20px;
+ bottom: -8px;
+ right: -8px;
+ background-image: url('data:image/svg+xml;base64,PD94bWwgdmVyc2lvbj0iMS4wIiBzdGFuZGFsb25lPSJubyI/Pg08IS0tIEdlbmVyYXRvcjogQWRvYmUgRmlyZXdvcmtzIENTNiwgRXhwb3J0IFNWRyBFeHRlbnNpb24gYnkgQWFyb24gQmVhbGwgKGh0dHA6Ly9maXJld29ya3MuYWJlYWxsLmNvbSkgLiBWZXJzaW9uOiAwLjYuMSAgLS0+DTwhRE9DVFlQRSBzdmcgUFVCTElDICItLy9XM0MvL0RURCBTVkcgMS4xLy9FTiIgImh0dHA6Ly93d3cudzMub3JnL0dyYXBoaWNzL1NWRy8xLjEvRFREL3N2ZzExLmR0ZCI+DTxzdmcgaWQ9IlVudGl0bGVkLVBhZ2UlMjAxIiB2aWV3Qm94PSIwIDAgNiA2IiBzdHlsZT0iYmFja2dyb3VuZC1jb2xvcjojZmZmZmZmMDAiIHZlcnNpb249IjEuMSINCXhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyIgeG1sbnM6eGxpbms9Imh0dHA6Ly93d3cudzMub3JnLzE5OTkveGxpbmsiIHhtbDpzcGFjZT0icHJlc2VydmUiDQl4PSIwcHgiIHk9IjBweCIgd2lkdGg9IjZweCIgaGVpZ2h0PSI2cHgiDT4NCTxnIG9wYWNpdHk9IjAuMzAyIj4NCQk8cGF0aCBkPSJNIDYgNiBMIDAgNiBMIDAgNC4yIEwgNCA0LjIgTCA0LjIgNC4yIEwgNC4yIDAgTCA2IDAgTCA2IDYgTCA2IDYgWiIgZmlsbD0iIzAwMDAwMCIvPg0JPC9nPg08L3N2Zz4=');
+ background-position: top left;
+ background-repeat: no-repeat;
+ cursor: se-resize;
+ z-index: 20;
+}
+
+.gs-resize-handle-x {
+ top: 0;
+ bottom: 13px;
+ right: -5px;
+ width: 10px;
+ cursor: e-resize;
+}
+
+.gs-resize-handle-y {
+ left: 0;
+ right: 13px;
+ bottom: -5px;
+ height: 10px;
+ cursor: s-resize;
+}
+
+.gs-w:hover .gs-resize-handle,
+.resizing .gs-resize-handle {
+ opacity: 1;
+}
+
+.gs-resize-handle,
+.gs-w.dragging .gs-resize-handle {
+ opacity: 0;
+}
+
+.gs-resize-disabled .gs-resize-handle {
+ display: none!important;
+}
+
+[data-max-sizex="1"] .gs-resize-handle-x,
+[data-max-sizey="1"] .gs-resize-handle-y,
+[data-max-sizey="1"][data-max-sizex="1"] .gs-resize-handle {
+ display: none !important;
+}
+
/* Uncomment this if you set helper : "clone" in draggable options */
/*.gridster .player {
opacity:0;
-}*/
+}
+*/
\ No newline at end of file
diff --git a/dist/jquery.gridster.js b/dist/jquery.gridster.js
index d3ad0556..b9ebb277 100644
--- a/dist/jquery.gridster.js
+++ b/dist/jquery.gridster.js
@@ -1,8 +1,16 @@
-/*! gridster.js - v0.1.0 - 2012-08-14
+/*! gridster.js - v0.5.6 - 2014-09-25
* http://gridster.net/
-* Copyright (c) 2012 ducksboard; Licensed MIT */
+* Copyright (c) 2014 ducksboard; Licensed MIT */
-;(function($, window, document, undefined){
+;(function(root, factory) {
+
+ if (typeof define === 'function' && define.amd) {
+ define('gridster-coords', ['jquery'], factory);
+ } else {
+ root.GridsterCoords = factory(root.$ || root.jQuery);
+ }
+
+}(this, function($) {
/**
* Creates objects with coordinates (x1, y1, x2, y2, cx, cy, width, height)
* to simulate DOM elements on the screen.
@@ -55,6 +63,9 @@
var d = this.data;
+ typeof d.left === 'undefined' && (d.left = d.x1);
+ typeof d.top === 'undefined' && (d.top = d.y1);
+
this.coords.x1 = d.left;
this.coords.y1 = d.top;
this.coords.x2 = d.left + d.width;
@@ -89,6 +100,10 @@
return this.coords;
};
+ fn.destroy = function() {
+ this.el.removeData('coords');
+ delete this.el;
+ };
//jQuery adapter
$.fn.coords = function() {
@@ -101,12 +116,24 @@
return ins;
};
-}(jQuery, window, document));
+ return Coords;
+
+}));
+
+;(function(root, factory) {
+
+ if (typeof define === 'function' && define.amd) {
+ define('gridster-collision', ['jquery', 'gridster-coords'], factory);
+ } else {
+ root.GridsterCollision = factory(root.$ || root.jQuery,
+ root.GridsterCoords);
+ }
-;(function($, window, document, undefined){
+}(this, function($, Coords) {
var defaults = {
- colliders_context: document.body
+ colliders_context: document.body,
+ overlapping_region: 'C'
// ,on_overlap: function(collider_data){},
// on_overlap_start : function(collider_data){},
// on_overlap_stop : function(collider_data){}
@@ -124,6 +151,9 @@
* of HTMLElements or an Array of Coords instances.
* @param {Object} [options] An Object with all options you want to
* overwrite:
+ * @param {String} [options.overlapping_region] Determines when collision
+ * is valid, depending on the overlapped area. Values can be: 'N', 'S',
+ * 'W', 'E', 'C' or 'all'. Default is 'C'.
* @param {Function} [options.on_overlap_start] Executes a function the first
* time each `collider ` is overlapped.
* @param {Function} [options.on_overlap_stop] Executes a function when a
@@ -138,16 +168,12 @@
this.$element = el;
this.last_colliders = [];
this.last_colliders_coords = [];
- if (typeof colliders === 'string' || colliders instanceof jQuery) {
- this.$colliders = $(colliders,
- this.options.colliders_context).not(this.$element);
- }else{
- this.colliders = $(colliders);
- }
+ this.set_colliders(colliders);
this.init();
}
+ Collision.defaults = defaults;
var fn = Collision.prototype;
@@ -228,6 +254,7 @@
fn.find_collisions = function(player_data_coords){
var self = this;
+ var overlapping_region = this.options.overlapping_region;
var colliders_coords = [];
var colliders_data = [];
var $colliders = (this.colliders || this.$colliders);
@@ -251,7 +278,8 @@
player_coords, collider_coords);
//todo: make this an option
- if (region === 'C'){
+ if (region === overlapping_region || overlapping_region === 'all') {
+
var area_coords = self.calculate_overlapped_area_coords(
player_coords, collider_coords);
var area = self.calculate_overlapped_area(area_coords);
@@ -274,7 +302,7 @@
if (self.options.on_overlap_stop || self.options.on_overlap_start) {
this.manage_colliders_start_stop(colliders_coords,
- self.options.on_overlap_stop, self.options.on_overlap_start);
+ self.options.on_overlap_start, self.options.on_overlap_stop);
}
this.last_colliders_coords = colliders_coords;
@@ -285,12 +313,8 @@
fn.get_closest_colliders = function(player_data_coords){
var colliders = this.find_collisions(player_data_coords);
- var min_area = 100;
- colliders.sort(function(a, b){
- if (a.area <= min_area) {
- return 1;
- }
+ colliders.sort(function(a, b) {
/* if colliders are being overlapped by the "C" (center) region,
* we have to set a lower index in the array to which they are placed
* above in the grid. */
@@ -302,7 +326,7 @@
}
}
- if (a.area < b.area){
+ if (a.area < b.area) {
return 1;
}
@@ -312,16 +336,59 @@
};
+ fn.set_colliders = function(colliders) {
+ if (typeof colliders === 'string' || colliders instanceof $) {
+ this.$colliders = $(colliders,
+ this.options.colliders_context).not(this.$element);
+ }else{
+ this.colliders = $(colliders);
+ }
+ };
+
+
//jQuery adapter
$.fn.collision = function(collider, options) {
return new Collision( this, collider, options );
};
+ return Collision;
-}(jQuery, window, document));
+}));
;(function(window, undefined) {
- /* Debounce and throttle functions taken from underscore.js */
+
+ /* Delay, debounce and throttle functions taken from underscore.js
+ *
+ * Copyright (c) 2009-2013 Jeremy Ashkenas, DocumentCloud and
+ * Investigative Reporters & Editors
+ *
+ * Permission is hereby granted, free of charge, to any person
+ * obtaining a copy of this software and associated documentation
+ * files (the "Software"), to deal in the Software without
+ * restriction, including without limitation the rights to use,
+ * copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following
+ * conditions:
+ *
+ * The above copyright notice and this permission notice shall be
+ * included in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
+ * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+ * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
+ * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+ * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+ * OTHER DEALINGS IN THE SOFTWARE.
+ */
+
+ window.delay = function(func, wait) {
+ var args = Array.prototype.slice.call(arguments, 2);
+ return setTimeout(function(){ return func.apply(null, args); }, wait);
+ };
+
window.debounce = function(func, wait, immediate) {
var timeout;
return function() {
@@ -336,7 +403,6 @@
};
};
-
window.throttle = function(func, wait) {
var context, args, timeout, throttling, more, result;
var whenDone = debounce(
@@ -362,27 +428,46 @@
})(window);
-;(function($, window, document, undefined){
+;(function(root, factory) {
+
+ if (typeof define === 'function' && define.amd) {
+ define('gridster-draggable', ['jquery'], factory);
+ } else {
+ root.GridsterDraggable = factory(root.$ || root.jQuery);
+ }
+
+}(this, function($) {
var defaults = {
- items: '.gs_w',
+ items: 'li',
distance: 1,
limit: true,
offset_left: 0,
- autoscroll: true
- // ,drag: function(e){},
- // start : function(e, ui){},
- // stop : function(e){}
+ autoscroll: true,
+ ignore_dragging: ['INPUT', 'TEXTAREA', 'SELECT', 'BUTTON'], // or function
+ handle: null,
+ container_width: 0, // 0 == auto
+ move_element: true,
+ helper: false, // or 'clone'
+ remove_helper: true
+ // drag: function(e) {},
+ // start : function(e, ui) {},
+ // stop : function(e) {}
};
var $window = $(window);
+ var dir_map = { x : 'left', y : 'top' };
var isTouch = !!('ontouchstart' in window);
- var pointer_events = {
- start: isTouch ? 'touchstart' : 'mousedown.draggable',
- move: isTouch ? 'touchmove' : 'mousemove.draggable',
- end: isTouch ? 'touchend' : 'mouseup.draggable'
+
+ var capitalize = function(str) {
+ return str.charAt(0).toUpperCase() + str.slice(1);
};
+ var idCounter = 0;
+ var uniqId = function() {
+ return ++idCounter + '';
+ }
+
/**
* Basic drag implementation for DOM elements inside a container.
* Provide start/stop/drag callbacks.
@@ -399,6 +484,9 @@
* the mouse must move before dragging should start.
* @param {Boolean} [options.limit] Constrains dragging to the width of
* the container
+ * @param {Object|Function} [options.ignore_dragging] Array of node names
+ * that sould not trigger dragging, by default is `['INPUT', 'TEXTAREA',
+ * 'SELECT', 'BUTTON']`. If a function is used return true to ignore dragging.
* @param {offset_left} [options.offset_left] Offset added to the item
* that is being dragged.
* @param {Number} [options.drag] Executes a callback when the mouse is
@@ -411,25 +499,57 @@
*/
function Draggable(el, options) {
this.options = $.extend({}, defaults, options);
- this.$body = $(document.body);
+ this.$document = $(document);
this.$container = $(el);
this.$dragitems = $(this.options.items, this.$container);
this.is_dragging = false;
this.player_min_left = 0 + this.options.offset_left;
+ this.id = uniqId();
+ this.ns = '.gridster-draggable-' + this.id;
this.init();
}
+ Draggable.defaults = defaults;
+
var fn = Draggable.prototype;
fn.init = function() {
- this.calculate_positions();
- this.$container.css('position', 'relative');
- this.enable();
+ var pos = this.$container.css('position');
+ this.calculate_dimensions();
+ this.$container.css('position', pos === 'static' ? 'relative' : pos);
+ this.disabled = false;
+ this.events();
+
+ $(window).bind(this.nsEvent('resize'),
+ throttle($.proxy(this.calculate_dimensions, this), 200));
+ };
- $(window).bind('resize',
- throttle($.proxy(this.calculate_positions, this), 200));
+ fn.nsEvent = function(ev) {
+ return (ev || '') + this.ns;
};
+ fn.events = function() {
+ this.pointer_events = {
+ start: this.nsEvent('touchstart') + ' ' + this.nsEvent('mousedown'),
+ move: this.nsEvent('touchmove') + ' ' + this.nsEvent('mousemove'),
+ end: this.nsEvent('touchend') + ' ' + this.nsEvent('mouseup'),
+ };
+
+ this.$container.on(this.nsEvent('selectstart'),
+ $.proxy(this.on_select_start, this));
+
+ this.$container.on(this.pointer_events.start, this.options.items,
+ $.proxy(this.drag_handler, this));
+
+ this.$document.on(this.pointer_events.end, $.proxy(function(e) {
+ this.is_dragging = false;
+ if (this.disabled) { return; }
+ this.$document.off(this.pointer_events.move);
+ if (this.drag_start) {
+ this.on_dragstop(e);
+ }
+ }, this));
+ };
fn.get_actual_pos = function($el) {
var pos = $el.position();
@@ -438,10 +558,10 @@
fn.get_mouse_pos = function(e) {
- if (isTouch) {
+ if (e.originalEvent && e.originalEvent.touches) {
var oe = e.originalEvent;
e = oe.touches.length ? oe.touches[0] : oe.changedTouches[0];
- };
+ }
return {
left: e.clientX,
@@ -457,77 +577,119 @@
mouse_actual_pos.left - this.mouse_init_pos.left);
var diff_y = Math.round(mouse_actual_pos.top - this.mouse_init_pos.top);
- var left = Math.round(this.el_init_offset.left + diff_x - this.baseX);
- var top = Math.round(
- this.el_init_offset.top + diff_y - this.baseY + this.scrollOffset);
+ var left = Math.round(this.el_init_offset.left +
+ diff_x - this.baseX + $(window).scrollLeft() - this.win_offset_x);
+ var top = Math.round(this.el_init_offset.top +
+ diff_y - this.baseY + $(window).scrollTop() - this.win_offset_y);
if (this.options.limit) {
if (left > this.player_max_left) {
left = this.player_max_left;
- }else if(left < this.player_min_left) {
+ } else if(left < this.player_min_left) {
left = this.player_min_left;
}
}
return {
- left: left,
- top: top,
- mouse_left: mouse_actual_pos.left,
- mouse_top: mouse_actual_pos.top
+ position: {
+ left: left,
+ top: top
+ },
+ pointer: {
+ left: mouse_actual_pos.left,
+ top: mouse_actual_pos.top,
+ diff_left: diff_x + ($(window).scrollLeft() - this.win_offset_x),
+ diff_top: diff_y + ($(window).scrollTop() - this.win_offset_y)
+ }
};
};
- fn.manage_scroll = function(offset) {
- /* scroll document */
- var nextScrollTop;
- var scrollTop = $window.scrollTop();
- var min_window_y = scrollTop;
- var max_window_y = min_window_y + this.window_height;
+ fn.get_drag_data = function(e) {
+ var offset = this.get_offset(e);
+ offset.$player = this.$player;
+ offset.$helper = this.helper ? this.$helper : this.$player;
+
+ return offset;
+ };
+
+
+ fn.set_limits = function(container_width) {
+ container_width || (container_width = this.$container.width());
+ this.player_max_left = (container_width - this.player_width +
+ - this.options.offset_left);
+
+ this.options.container_width = container_width;
+
+ return this;
+ };
+
+
+ fn.scroll_in = function(axis, data) {
+ var dir_prop = dir_map[axis];
+
+ var area_size = 50;
+ var scroll_inc = 30;
+
+ var is_x = axis === 'x';
+ var window_size = is_x ? this.window_width : this.window_height;
+ var doc_size = is_x ? $(document).width() : $(document).height();
+ var player_size = is_x ? this.$player.width() : this.$player.height();
- var mouse_down_zone = max_window_y - 50;
- var mouse_up_zone = min_window_y + 50;
+ var next_scroll;
+ var scroll_offset = $window['scroll' + capitalize(dir_prop)]();
+ var min_window_pos = scroll_offset;
+ var max_window_pos = min_window_pos + window_size;
- var abs_mouse_left = offset.mouse_left;
- var abs_mouse_top = min_window_y + offset.mouse_top;
+ var mouse_next_zone = max_window_pos - area_size; // down/right
+ var mouse_prev_zone = min_window_pos + area_size; // up/left
- var max_player_y = (this.doc_height - this.window_height +
- this.player_height);
+ var abs_mouse_pos = min_window_pos + data.pointer[dir_prop];
- if (abs_mouse_top >= mouse_down_zone) {
- nextScrollTop = scrollTop + 30;
- if (nextScrollTop < max_player_y) {
- $window.scrollTop(nextScrollTop);
- this.scrollOffset = this.scrollOffset + 30;
+ var max_player_pos = (doc_size - window_size + player_size);
+
+ if (abs_mouse_pos >= mouse_next_zone) {
+ next_scroll = scroll_offset + scroll_inc;
+ if (next_scroll < max_player_pos) {
+ $window['scroll' + capitalize(dir_prop)](next_scroll);
+ this['scroll_offset_' + axis] += scroll_inc;
}
- };
+ }
- if (abs_mouse_top <= mouse_up_zone) {
- nextScrollTop = scrollTop - 30;
- if (nextScrollTop > 0) {
- $window.scrollTop(nextScrollTop);
- this.scrollOffset = this.scrollOffset - 30;
+ if (abs_mouse_pos <= mouse_prev_zone) {
+ next_scroll = scroll_offset - scroll_inc;
+ if (next_scroll > 0) {
+ $window['scroll' + capitalize(dir_prop)](next_scroll);
+ this['scroll_offset_' + axis] -= scroll_inc;
}
- };
- }
+ }
+
+ return this;
+ };
+
+
+ fn.manage_scroll = function(data) {
+ this.scroll_in('x', data);
+ this.scroll_in('y', data);
+ };
- fn.calculate_positions = function(e) {
+ fn.calculate_dimensions = function(e) {
this.window_height = $window.height();
- }
+ this.window_width = $window.width();
+ };
fn.drag_handler = function(e) {
var node = e.target.nodeName;
-
- if (e.which !== 1 && !isTouch) {
+ // skip if drag is disabled, or click was not done with the mouse primary button
+ if (this.disabled || e.which !== 1 && !isTouch) {
return;
}
- if (node === 'INPUT' || node === 'TEXTAREA' || node === 'SELECT' ||
- node === 'BUTTON') {
+ if (this.ignore_drag(e)) {
return;
- };
+ }
var self = this;
var first = true;
@@ -537,7 +699,7 @@
this.mouse_init_pos = this.get_mouse_pos(e);
this.offsetY = this.mouse_init_pos.top - this.el_init_pos.top;
- this.$body.on(pointer_events.move, function(mme){
+ this.$document.on(this.pointer_events.move, function(mme) {
var mouse_actual_pos = self.get_mouse_pos(mme);
var diff_x = Math.abs(
mouse_actual_pos.left - self.mouse_init_pos.left);
@@ -545,7 +707,7 @@
mouse_actual_pos.top - self.mouse_init_pos.top);
if (!(diff_x > self.options.distance ||
diff_y > self.options.distance)
- ) {
+ ) {
return false;
}
@@ -555,90 +717,87 @@
return false;
}
- if (self.is_dragging == true) {
+ if (self.is_dragging === true) {
self.on_dragmove.call(self, mme);
}
return false;
});
- return false;
+ if (!isTouch) { return false; }
};
fn.on_dragstart = function(e) {
e.preventDefault();
- this.drag_start = true;
- this.is_dragging = true;
+
+ if (this.is_dragging) { return this; }
+
+ this.drag_start = this.is_dragging = true;
var offset = this.$container.offset();
this.baseX = Math.round(offset.left);
this.baseY = Math.round(offset.top);
- this.doc_height = $(document).height();
+ this.initial_container_width = this.options.container_width || this.$container.width();
if (this.options.helper === 'clone') {
this.$helper = this.$player.clone()
.appendTo(this.$container).addClass('helper');
this.helper = true;
- }else{
+ } else {
this.helper = false;
}
- this.scrollOffset = 0;
+
+ this.win_offset_y = $(window).scrollTop();
+ this.win_offset_x = $(window).scrollLeft();
+ this.scroll_offset_y = 0;
+ this.scroll_offset_x = 0;
this.el_init_offset = this.$player.offset();
this.player_width = this.$player.width();
this.player_height = this.$player.height();
- this.player_max_left = (this.$container.width() - this.player_width +
- this.options.offset_left);
+
+ this.set_limits(this.options.container_width);
if (this.options.start) {
- this.options.start.call(this.$player, e, {
- helper: this.helper ? this.$helper : this.$player
- });
+ this.options.start.call(this.$player, e, this.get_drag_data(e));
}
return false;
};
fn.on_dragmove = function(e) {
- var offset = this.get_offset(e);
+ var data = this.get_drag_data(e);
- this.options.autoscroll && this.manage_scroll(offset);
+ this.options.autoscroll && this.manage_scroll(data);
- (this.helper ? this.$helper : this.$player).css({
- 'position': 'absolute',
- 'left' : offset.left,
- 'top' : offset.top
- });
+ if (this.options.move_element) {
+ (this.helper ? this.$helper : this.$player).css({
+ 'position': 'absolute',
+ 'left' : data.position.left,
+ 'top' : data.position.top
+ });
+ }
- var ui = {
- 'position': {
- 'left': offset.left,
- 'top': offset.top
- }
- };
+ var last_position = this.last_position || data.position;
+ data.prev_position = last_position;
if (this.options.drag) {
- this.options.drag.call(this.$player, e, ui);
+ this.options.drag.call(this.$player, e, data);
}
+
+ this.last_position = data.position;
return false;
};
fn.on_dragstop = function(e) {
- var offset = this.get_offset(e);
+ var data = this.get_drag_data(e);
this.drag_start = false;
- var ui = {
- 'position': {
- 'left': offset.left,
- 'top': offset.top
- }
- };
-
if (this.options.stop) {
- this.options.stop.call(this.$player, e, ui);
+ this.options.stop.call(this.$player, e, data);
}
- if (this.helper) {
+ if (this.helper && this.options.remove_helper) {
this.$helper.remove();
}
@@ -646,78 +805,104 @@
};
fn.on_select_start = function(e) {
- return false;
- }
-
+ if (this.disabled) { return; }
- fn.enable = function(){
- this.$container.on('selectstart', this.on_select_start);
-
- this.$container.on(pointer_events.start, this.options.items, $.proxy(
- this.drag_handler, this));
+ if (this.ignore_drag(e)) {
+ return;
+ }
- this.$body.on(pointer_events.end, $.proxy(function(e) {
- this.is_dragging = false;
- this.$body.off(pointer_events.move);
- if (this.drag_start) {
- this.on_dragstop(e);
- }
- }, this));
+ return false;
};
-
- fn.disable = function(){
- this.$container.off(pointer_events.start);
- this.$body.off(pointer_events.end);
- this.$container.off('selectstart', this.on_select_start);
+ fn.enable = function() {
+ this.disabled = false;
};
+ fn.disable = function() {
+ this.disabled = true;
+ };
- fn.destroy = function(){
+ fn.destroy = function() {
this.disable();
+
+ this.$container.off(this.ns);
+ this.$document.off(this.ns);
+ $(window).off(this.ns);
+
$.removeData(this.$container, 'drag');
};
+ fn.ignore_drag = function(event) {
+ if (this.options.handle) {
+ return !$(event.target).is(this.options.handle);
+ }
+
+ if ($.isFunction(this.options.ignore_dragging)) {
+ return this.options.ignore_dragging(event);
+ }
+
+ return $(event.target).is(this.options.ignore_dragging.join(', '));
+ };
//jQuery adapter
$.fn.drag = function ( options ) {
- return this.each(function () {
- if (!$.data(this, 'drag')) {
- $.data(this, 'drag', new Draggable( this, options ));
- }
- });
+ return new Draggable(this, options);
};
+ return Draggable;
+
+}));
+
+;(function(root, factory) {
-}(jQuery, window, document));
+ if (typeof define === 'function' && define.amd) {
+ define(['jquery', 'gridster-draggable', 'gridster-collision'], factory);
+ } else {
+ root.Gridster = factory(root.$ || root.jQuery, root.GridsterDraggable,
+ root.GridsterCollision);
+ }
-;(function($, window, document, undefined) {
+ }(this, function($, Draggable, Collision) {
var defaults = {
- widget_selector: '> li',
+ namespace: '',
+ widget_selector: 'li',
widget_margins: [10, 10],
widget_base_dimensions: [400, 225],
extra_rows: 0,
extra_cols: 0,
min_cols: 1,
+ max_cols: Infinity,
min_rows: 15,
- max_size_x: 6,
- max_size_y: 6,
+ max_size_x: false,
+ autogrow_cols: false,
autogenerate_stylesheet: true,
avoid_overlapped_widgets: true,
+ auto_init: true,
serialize_params: function($w, wgd) {
return {
col: wgd.col,
- row: wgd.row
+ row: wgd.row,
+ size_x: wgd.size_x,
+ size_y: wgd.size_y
};
},
collision: {},
draggable: {
- distance: 4
+ items: '.gs-w',
+ distance: 4,
+ ignore_dragging: Draggable.defaults.ignore_dragging.slice(0)
+ },
+ resize: {
+ enabled: false,
+ axes: ['both'],
+ handle_append_to: '',
+ handle_class: 'gs-resize-handle',
+ max_size: [Infinity, Infinity],
+ min_size: [1, 1]
}
};
-
/**
* @class Gridster
* @uses Draggable
@@ -739,11 +924,11 @@
* @param {Number} [options.extra_rows] Add more rows in addition to
* those that have been calculated.
* @param {Number} [options.min_cols] The minimum required columns.
+ * @param {Number} [options.max_cols] The maximum columns possible (set to null
+ * for no maximum).
* @param {Number} [options.min_rows] The minimum required rows.
* @param {Number} [options.max_size_x] The maximum number of columns
* that a widget can span.
- * @param {Number} [options.max_size_y] The maximum number of rows
- * that a widget can span.
* @param {Boolean} [options.autogenerate_stylesheet] If true, all the
* CSS required to position all widgets in their respective columns
* and rows will be generated automatically and injected to the
@@ -753,6 +938,8 @@
* @param {Boolean} [options.avoid_overlapped_widgets] Avoid that widgets loaded
* from the DOM can be overlapped. It is helpful if the positions were
* bad stored in the database or if there was any conflict.
+ * @param {Boolean} [options.auto_init] Automatically call gridster init
+ * method or not when the plugin is instantiated.
* @param {Function} [options.serialize_params] Return the data you want
* for each widget in the serialization. Two arguments are passed:
* `$w`: the jQuery wrapped HTMLElement, and `wgd`: the grid
@@ -763,37 +950,158 @@
* @param {Object} [options.draggable] An Object with all options for
* Draggable class you want to overwrite. See Draggable docs for more
* info.
+ * @param {Object|Function} [options.draggable.ignore_dragging] Note that
+ * if you use a Function, and resize is enabled, you should ignore the
+ * resize handlers manually (options.resize.handle_class).
+ * @param {Object} [options.resize] An Object with resize config options.
+ * @param {Boolean} [options.resize.enabled] Set to true to enable
+ * resizing.
+ * @param {Array} [options.resize.axes] Axes in which widgets can be
+ * resized. Possible values: ['x', 'y', 'both'].
+ * @param {String} [options.resize.handle_append_to] Set a valid CSS
+ * selector to append resize handles to.
+ * @param {String} [options.resize.handle_class] CSS class name used
+ * by resize handles.
+ * @param {Array} [options.resize.max_size] Limit widget dimensions
+ * when resizing. Array values should be integers:
+ * `[max_cols_occupied, max_rows_occupied]`
+ * @param {Array} [options.resize.min_size] Limit widget dimensions
+ * when resizing. Array values should be integers:
+ * `[min_cols_occupied, min_rows_occupied]`
+ * @param {Function} [options.resize.start] Function executed
+ * when resizing starts.
+ * @param {Function} [otions.resize.resize] Function executed
+ * during the resizing.
+ * @param {Function} [options.resize.stop] Function executed
+ * when resizing stops.
*
* @constructor
*/
function Gridster(el, options) {
- this.options = $.extend(true, defaults, options);
- this.$el = $(el);
- this.$wrapper = this.$el.parent();
- this.$widgets = $(this.options.widget_selector, this.$el).addClass('gs_w');
- this.widgets = [];
- this.$changed = $([]);
- this.wrapper_width = this.$wrapper.width();
- this.min_widget_width = (this.options.widget_margins[0] * 2) +
- this.options.widget_base_dimensions[0];
- this.min_widget_height = (this.options.widget_margins[1] * 2) +
- this.options.widget_base_dimensions[1];
- this.init();
+ this.options = $.extend(true, {}, defaults, options);
+ this.$el = $(el);
+ this.$wrapper = this.$el.parent();
+ this.$widgets = this.$el.children(
+ this.options.widget_selector).addClass('gs-w');
+ this.widgets = [];
+ this.$changed = $([]);
+ this.wrapper_width = this.$wrapper.width();
+ this.min_widget_width = (this.options.widget_margins[0] * 2) +
+ this.options.widget_base_dimensions[0];
+ this.min_widget_height = (this.options.widget_margins[1] * 2) +
+ this.options.widget_base_dimensions[1];
+
+ this.generated_stylesheets = [];
+ this.$style_tags = $([]);
+
+ this.options.auto_init && this.init();
}
+ Gridster.defaults = defaults;
Gridster.generated_stylesheets = [];
+
+ /**
+ * Sorts an Array of grid coords objects (representing the grid coords of
+ * each widget) in ascending way.
+ *
+ * @method sort_by_row_asc
+ * @param {Array} widgets Array of grid coords objects
+ * @return {Array} Returns the array sorted.
+ */
+ Gridster.sort_by_row_asc = function(widgets) {
+ widgets = widgets.sort(function(a, b) {
+ if (!a.row) {
+ a = $(a).coords().grid;
+ b = $(b).coords().grid;
+ }
+
+ if (a.row > b.row) {
+ return 1;
+ }
+ return -1;
+ });
+
+ return widgets;
+ };
+
+
+ /**
+ * Sorts an Array of grid coords objects (representing the grid coords of
+ * each widget) placing first the empty cells upper left.
+ *
+ * @method sort_by_row_and_col_asc
+ * @param {Array} widgets Array of grid coords objects
+ * @return {Array} Returns the array sorted.
+ */
+ Gridster.sort_by_row_and_col_asc = function(widgets) {
+ widgets = widgets.sort(function(a, b) {
+ if (a.row > b.row || a.row === b.row && a.col > b.col) {
+ return 1;
+ }
+ return -1;
+ });
+
+ return widgets;
+ };
+
+
+ /**
+ * Sorts an Array of grid coords objects by column (representing the grid
+ * coords of each widget) in ascending way.
+ *
+ * @method sort_by_col_asc
+ * @param {Array} widgets Array of grid coords objects
+ * @return {Array} Returns the array sorted.
+ */
+ Gridster.sort_by_col_asc = function(widgets) {
+ widgets = widgets.sort(function(a, b) {
+ if (a.col > b.col) {
+ return 1;
+ }
+ return -1;
+ });
+
+ return widgets;
+ };
+
+
+ /**
+ * Sorts an Array of grid coords objects (representing the grid coords of
+ * each widget) in descending way.
+ *
+ * @method sort_by_row_desc
+ * @param {Array} widgets Array of grid coords objects
+ * @return {Array} Returns the array sorted.
+ */
+ Gridster.sort_by_row_desc = function(widgets) {
+ widgets = widgets.sort(function(a, b) {
+ if (a.row + a.size_y < b.row + b.size_y) {
+ return 1;
+ }
+ return -1;
+ });
+ return widgets;
+ };
+
+
+
+ /** Instance Methods **/
+
var fn = Gridster.prototype;
fn.init = function() {
- this.generate_grid_and_stylesheet();
- this.get_widgets_from_DOM();
- this.set_dom_grid_height();
- this.$wrapper.addClass('ready');
- this.draggable();
+ this.options.resize.enabled && this.setup_resize();
+ this.generate_grid_and_stylesheet();
+ this.get_widgets_from_DOM();
+ this.set_dom_grid_height();
+ this.set_dom_grid_width();
+ this.$wrapper.addClass('ready');
+ this.draggable();
+ this.options.resize.enabled && this.resizable();
- $(window).bind(
- 'resize', throttle($.proxy(this.recalculate_faux_grid, this), 200));
+ $(window).bind('resize.gridster', throttle(
+ $.proxy(this.recalculate_faux_grid, this), 200));
};
@@ -822,54 +1130,410 @@
};
+
+ /**
+ * Disables drag-and-drop widget resizing.
+ *
+ * @method disable
+ * @return {Class} Returns instance of gridster Class.
+ */
+ fn.disable_resize = function() {
+ this.$el.addClass('gs-resize-disabled');
+ this.resize_api.disable();
+ return this;
+ };
+
+
+ /**
+ * Enables drag-and-drop widget resizing.
+ *
+ * @method enable
+ * @return {Class} Returns instance of gridster Class.
+ */
+ fn.enable_resize = function() {
+ this.$el.removeClass('gs-resize-disabled');
+ this.resize_api.enable();
+ return this;
+ };
+
+
/**
* Add a new widget to the grid.
*
* @method add_widget
- * @param {String} html The string representing the HTML of the widget.
- * @param {Number} size_x The nº of rows the widget occupies horizontally.
- * @param {Number} size_y The nº of columns the widget occupies vertically.
+ * @param {String|HTMLElement} html The string representing the HTML of the widget
+ * or the HTMLElement.
+ * @param {Number} [size_x] The nº of rows the widget occupies horizontally.
+ * @param {Number} [size_y] The nº of columns the widget occupies vertically.
+ * @param {Number} [col] The column the widget should start in.
+ * @param {Number} [row] The row the widget should start in.
+ * @param {Array} [max_size] max_size Maximun size (in units) for width and height.
+ * @param {Array} [min_size] min_size Minimum size (in units) for width and height.
* @return {HTMLElement} Returns the jQuery wrapped HTMLElement representing.
* the widget that was just created.
*/
- fn.add_widget = function(html, size_x, size_y) {
- var next_pos = this.next_position(size_x, size_y);
+ fn.add_widget = function(html, size_x, size_y, col, row, max_size, min_size) {
+ var pos;
+ size_x || (size_x = 1);
+ size_y || (size_y = 1);
+
+ if (!col & !row) {
+ pos = this.next_position(size_x, size_y);
+ } else {
+ pos = {
+ col: col,
+ row: row,
+ size_x: size_x,
+ size_y: size_y
+ };
+
+ this.empty_cells(col, row, size_x, size_y);
+ }
var $w = $(html).attr({
- 'data-col': next_pos.col,
- 'data-row': next_pos.row,
- 'data-sizex' : next_pos.size_x,
- 'data-sizey' : next_pos.size_y
- }).addClass('gs_w').appendTo(this.$el).hide();
+ 'data-col': pos.col,
+ 'data-row': pos.row,
+ 'data-sizex' : size_x,
+ 'data-sizey' : size_y
+ }).addClass('gs-w').appendTo(this.$el).hide();
this.$widgets = this.$widgets.add($w);
this.register_widget($w);
+ this.add_faux_rows(pos.size_y);
+ //this.add_faux_cols(pos.size_x);
+
+ if (max_size) {
+ this.set_widget_max_size($w, max_size);
+ }
+
+ if (min_size) {
+ this.set_widget_min_size($w, min_size);
+ }
+
+ this.set_dom_grid_width();
this.set_dom_grid_height();
+ this.drag_api.set_limits(this.cols * this.min_widget_width);
+
return $w.fadeIn();
};
/**
- * Get the most left column below to add a new widget.
+ * Change widget size limits.
*
- * @method next_position
- * @param {Number} size_x The nº of rows the widget occupies horizontally.
- * @param {Number} size_y The nº of columns the widget occupies vertically.
- * @return {Object} Returns a grid coords object representing the future
- * widget coords.
+ * @method set_widget_min_size
+ * @param {HTMLElement|Number} $widget The jQuery wrapped HTMLElement
+ * representing the widget or an index representing the desired widget.
+ * @param {Array} min_size Minimum size (in units) for width and height.
+ * @return {HTMLElement} Returns instance of gridster Class.
*/
- fn.next_position = function(size_x, size_y) {
- size_x || (size_x = 1);
- size_y || (size_y = 1);
- var ga = this.gridmap;
- var cols_l = ga.length;
- var valid_pos = [];
+ fn.set_widget_min_size = function($widget, min_size) {
+ $widget = typeof $widget === 'number' ?
+ this.$widgets.eq($widget) : $widget;
+
+ if (!$widget.length) { return this; }
+
+ var wgd = $widget.data('coords').grid;
+ wgd.min_size_x = min_size[0];
+ wgd.min_size_y = min_size[1];
+
+ return this;
+ };
+
+
+ /**
+ * Change widget size limits.
+ *
+ * @method set_widget_max_size
+ * @param {HTMLElement|Number} $widget The jQuery wrapped HTMLElement
+ * representing the widget or an index representing the desired widget.
+ * @param {Array} max_size Maximun size (in units) for width and height.
+ * @return {HTMLElement} Returns instance of gridster Class.
+ */
+ fn.set_widget_max_size = function($widget, max_size) {
+ $widget = typeof $widget === 'number' ?
+ this.$widgets.eq($widget) : $widget;
+
+ if (!$widget.length) { return this; }
+
+ var wgd = $widget.data('coords').grid;
+ wgd.max_size_x = max_size[0];
+ wgd.max_size_y = max_size[1];
+
+ return this;
+ };
+
+
+ /**
+ * Append the resize handle into a widget.
+ *
+ * @method add_resize_handle
+ * @param {HTMLElement} $widget The jQuery wrapped HTMLElement
+ * representing the widget.
+ * @return {HTMLElement} Returns instance of gridster Class.
+ */
+ fn.add_resize_handle = function($w) {
+ var append_to = this.options.resize.handle_append_to;
+ $(this.resize_handle_tpl).appendTo( append_to ? $(append_to, $w) : $w);
+
+ return this;
+ };
+
+
+ /**
+ * Change the size of a widget. Width is limited to the current grid width.
+ *
+ * @method resize_widget
+ * @param {HTMLElement} $widget The jQuery wrapped HTMLElement
+ * representing the widget.
+ * @param {Number} size_x The number of columns that will occupy the widget.
+ * By default size_x is limited to the space available from
+ * the column where the widget begins, until the last column to the right.
+ * @param {Number} size_y The number of rows that will occupy the widget.
+ * @param {Function} [callback] Function executed when the widget is removed.
+ * @return {HTMLElement} Returns $widget.
+ */
+ fn.resize_widget = function($widget, size_x, size_y, callback) {
+ var wgd = $widget.coords().grid;
+ var col = wgd.col;
+ var max_cols = this.options.max_cols;
+ var old_size_y = wgd.size_y;
+ var old_col = wgd.col;
+ var new_col = old_col;
+
+ size_x || (size_x = wgd.size_x);
+ size_y || (size_y = wgd.size_y);
+
+ if (max_cols !== Infinity) {
+ size_x = Math.min(size_x, max_cols - col + 1);
+ }
+
+ if (size_y > old_size_y) {
+ this.add_faux_rows(Math.max(size_y - old_size_y, 0));
+ }
+
+ var player_rcol = (col + size_x - 1);
+ if (player_rcol > this.cols) {
+ this.add_faux_cols(player_rcol - this.cols);
+ }
+
+ var new_grid_data = {
+ col: new_col,
+ row: wgd.row,
+ size_x: size_x,
+ size_y: size_y
+ };
+
+ this.mutate_widget_in_gridmap($widget, wgd, new_grid_data);
+
+ this.set_dom_grid_height();
+ this.set_dom_grid_width();
+
+ if (callback) {
+ callback.call(this, new_grid_data.size_x, new_grid_data.size_y);
+ }
+
+ return $widget;
+ };
+
+
+ /**
+ * Mutate widget dimensions and position in the grid map.
+ *
+ * @method mutate_widget_in_gridmap
+ * @param {HTMLElement} $widget The jQuery wrapped HTMLElement
+ * representing the widget to mutate.
+ * @param {Object} wgd Current widget grid data (col, row, size_x, size_y).
+ * @param {Object} new_wgd New widget grid data.
+ * @return {HTMLElement} Returns instance of gridster Class.
+ */
+ fn.mutate_widget_in_gridmap = function($widget, wgd, new_wgd) {
+ var old_size_x = wgd.size_x;
+ var old_size_y = wgd.size_y;
+
+ var old_cells_occupied = this.get_cells_occupied(wgd);
+ var new_cells_occupied = this.get_cells_occupied(new_wgd);
+
+ var empty_cols = [];
+ $.each(old_cells_occupied.cols, function(i, col) {
+ if ($.inArray(col, new_cells_occupied.cols) === -1) {
+ empty_cols.push(col);
+ }
+ });
+
+ var occupied_cols = [];
+ $.each(new_cells_occupied.cols, function(i, col) {
+ if ($.inArray(col, old_cells_occupied.cols) === -1) {
+ occupied_cols.push(col);
+ }
+ });
+
+ var empty_rows = [];
+ $.each(old_cells_occupied.rows, function(i, row) {
+ if ($.inArray(row, new_cells_occupied.rows) === -1) {
+ empty_rows.push(row);
+ }
+ });
+
+ var occupied_rows = [];
+ $.each(new_cells_occupied.rows, function(i, row) {
+ if ($.inArray(row, old_cells_occupied.rows) === -1) {
+ occupied_rows.push(row);
+ }
+ });
+
+ this.remove_from_gridmap(wgd);
+
+ if (occupied_cols.length) {
+ var cols_to_empty = [
+ new_wgd.col, new_wgd.row, new_wgd.size_x, Math.min(old_size_y, new_wgd.size_y), $widget
+ ];
+ this.empty_cells.apply(this, cols_to_empty);
+ }
+
+ if (occupied_rows.length) {
+ var rows_to_empty = [new_wgd.col, new_wgd.row, new_wgd.size_x, new_wgd.size_y, $widget];
+ this.empty_cells.apply(this, rows_to_empty);
+ }
+
+ // not the same that wgd = new_wgd;
+ wgd.col = new_wgd.col;
+ wgd.row = new_wgd.row;
+ wgd.size_x = new_wgd.size_x;
+ wgd.size_y = new_wgd.size_y;
+
+ this.add_to_gridmap(new_wgd, $widget);
+
+ $widget.removeClass('player-revert');
+
+ //update coords instance attributes
+ $widget.data('coords').update({
+ width: (new_wgd.size_x * this.options.widget_base_dimensions[0] +
+ ((new_wgd.size_x - 1) * this.options.widget_margins[0]) * 2),
+ height: (new_wgd.size_y * this.options.widget_base_dimensions[1] +
+ ((new_wgd.size_y - 1) * this.options.widget_margins[1]) * 2)
+ });
+
+ $widget.attr({
+ 'data-col': new_wgd.col,
+ 'data-row': new_wgd.row,
+ 'data-sizex': new_wgd.size_x,
+ 'data-sizey': new_wgd.size_y
+ });
+
+ if (empty_cols.length) {
+ var cols_to_remove_holes = [
+ empty_cols[0], new_wgd.row,
+ empty_cols.length,
+ Math.min(old_size_y, new_wgd.size_y),
+ $widget
+ ];
+
+ this.remove_empty_cells.apply(this, cols_to_remove_holes);
+ }
+
+ if (empty_rows.length) {
+ var rows_to_remove_holes = [
+ new_wgd.col, new_wgd.row, new_wgd.size_x, new_wgd.size_y, $widget
+ ];
+ this.remove_empty_cells.apply(this, rows_to_remove_holes);
+ }
+
+ this.move_widget_up($widget);
+
+ return this;
+ };
+
+
+ /**
+ * Move down widgets in cells represented by the arguments col, row, size_x,
+ * size_y
+ *
+ * @method empty_cells
+ * @param {Number} col The column where the group of cells begin.
+ * @param {Number} row The row where the group of cells begin.
+ * @param {Number} size_x The number of columns that the group of cells
+ * occupy.
+ * @param {Number} size_y The number of rows that the group of cells
+ * occupy.
+ * @param {HTMLElement} $exclude Exclude widgets from being moved.
+ * @return {Class} Returns the instance of the Gridster Class.
+ */
+ fn.empty_cells = function(col, row, size_x, size_y, $exclude) {
+ var $nexts = this.widgets_below({
+ col: col,
+ row: row - size_y,
+ size_x: size_x,
+ size_y: size_y
+ });
+
+ $nexts.not($exclude).each($.proxy(function(i, w) {
+ var wgd = $(w).coords().grid;
+ if ( !(wgd.row <= (row + size_y - 1))) { return; }
+ var diff = (row + size_y) - wgd.row;
+ this.move_widget_down($(w), diff);
+ }, this));
+
+ this.set_dom_grid_height();
+
+ return this;
+ };
+
+
+ /**
+ * Move up widgets below cells represented by the arguments col, row, size_x,
+ * size_y.
+ *
+ * @method remove_empty_cells
+ * @param {Number} col The column where the group of cells begin.
+ * @param {Number} row The row where the group of cells begin.
+ * @param {Number} size_x The number of columns that the group of cells
+ * occupy.
+ * @param {Number} size_y The number of rows that the group of cells
+ * occupy.
+ * @param {HTMLElement} exclude Exclude widgets from being moved.
+ * @return {Class} Returns the instance of the Gridster Class.
+ */
+ fn.remove_empty_cells = function(col, row, size_x, size_y, exclude) {
+ var $nexts = this.widgets_below({
+ col: col,
+ row: row,
+ size_x: size_x,
+ size_y: size_y
+ });
+
+ $nexts.not(exclude).each($.proxy(function(i, widget) {
+ this.move_widget_up( $(widget), size_y );
+ }, this));
+
+ this.set_dom_grid_height();
+
+ return this;
+ };
+
+
+ /**
+ * Get the most left column below to add a new widget.
+ *
+ * @method next_position
+ * @param {Number} size_x The nº of rows the widget occupies horizontally.
+ * @param {Number} size_y The nº of columns the widget occupies vertically.
+ * @return {Object} Returns a grid coords object representing the future
+ * widget coords.
+ */
+ fn.next_position = function(size_x, size_y) {
+ size_x || (size_x = 1);
+ size_y || (size_y = 1);
+ var ga = this.gridmap;
+ var cols_l = ga.length;
+ var valid_pos = [];
+ var rows_l;
for (var c = 1; c < cols_l; c++) {
- var rows_l = ga[c].length;
+ rows_l = ga[c].length;
for (var r = 1; r <= rows_l; r++) {
var can_move_to = this.can_move_to({
size_x: size_x,
@@ -888,7 +1552,7 @@
}
if (valid_pos.length) {
- return this.sort_by_row_and_col_asc(valid_pos)[0];
+ return Gridster.sort_by_row_and_col_asc(valid_pos)[0];
}
return false;
};
@@ -899,12 +1563,21 @@
*
* @method remove_widget
* @param {HTMLElement} el The jQuery wrapped HTMLElement you want to remove.
+ * @param {Boolean|Function} silent If true, widgets below the removed one
+ * will not move up. If a Function is passed it will be used as callback.
+ * @param {Function} callback Function executed when the widget is removed.
* @return {Class} Returns the instance of the Gridster Class.
*/
- fn.remove_widget = function(el, callback) {
- var $el = el instanceof jQuery ? el : $(el);
+ fn.remove_widget = function(el, silent, callback) {
+ var $el = el instanceof $ ? el : $(el);
var wgd = $el.coords().grid;
+ // if silent is a function assume it's a callback
+ if ($.isFunction(silent)) {
+ callback = silent;
+ silent = false;
+ }
+
this.cells_occupied_by_placeholder = {};
this.$widgets = this.$widgets.not($el);
@@ -915,9 +1588,11 @@
$el.fadeOut($.proxy(function() {
$el.remove();
- $nexts.each($.proxy(function(i, widget) {
- this.move_widget_up( $(widget), wgd.size_y );
- }, this));
+ if (!silent) {
+ $nexts.each($.proxy(function(i, widget) {
+ this.move_widget_up( $(widget), wgd.size_y );
+ }, this));
+ }
this.set_dom_grid_height();
@@ -925,6 +1600,24 @@
callback.call(this, el);
}
}, this));
+
+ return this;
+ };
+
+
+ /**
+ * Remove all widgets from the grid.
+ *
+ * @method remove_all_widgets
+ * @param {Function} callback Function executed for each widget removed.
+ * @return {Class} Returns the instance of the Gridster Class.
+ */
+ fn.remove_all_widgets = function(callback) {
+ this.$widgets.each($.proxy(function(i, el){
+ this.remove_widget(el, true, callback);
+ }, this));
+
+ return this;
};
@@ -940,13 +1633,11 @@
*/
fn.serialize = function($widgets) {
$widgets || ($widgets = this.$widgets);
- var result = [];
- $widgets.each($.proxy(function(i, widget) {
- result.push(this.options.serialize_params(
- $(widget), $(widget).coords().grid ) );
- }, this));
- return result;
+ return $widgets.map($.proxy(function(i, widget) {
+ var $w = $(widget);
+ return this.options.serialize_params($w, $w.coords().grid);
+ }, this)).get();
};
@@ -964,45 +1655,74 @@
/**
- * Creates the grid coords object representing the widget a add it to the
+ * Convert widgets from DOM elements to "widget grid data" Objects.
+ *
+ * @method dom_to_coords
+ * @param {HTMLElement} $widget The widget to be converted.
+ */
+ fn.dom_to_coords = function($widget) {
+ return {
+ 'col': parseInt($widget.attr('data-col'), 10),
+ 'row': parseInt($widget.attr('data-row'), 10),
+ 'size_x': parseInt($widget.attr('data-sizex'), 10) || 1,
+ 'size_y': parseInt($widget.attr('data-sizey'), 10) || 1,
+ 'max_size_x': parseInt($widget.attr('data-max-sizex'), 10) || false,
+ 'max_size_y': parseInt($widget.attr('data-max-sizey'), 10) || false,
+ 'min_size_x': parseInt($widget.attr('data-min-sizex'), 10) || false,
+ 'min_size_y': parseInt($widget.attr('data-min-sizey'), 10) || false,
+ 'el': $widget
+ };
+ };
+
+
+ /**
+ * Creates the grid coords object representing the widget an add it to the
* mapped array of positions.
*
* @method register_widget
- * @return {Array} Returns the instance of the Gridster class.
+ * @param {HTMLElement|Object} $el jQuery wrapped HTMLElement representing
+ * the widget, or an "widget grid data" Object with (col, row, el ...).
+ * @return {Boolean} Returns true if the widget final position is different
+ * than the original.
*/
fn.register_widget = function($el) {
+ var isDOM = $el instanceof jQuery;
+ var wgd = isDOM ? this.dom_to_coords($el) : $el;
+ var posChanged = false;
+ isDOM || ($el = wgd.el);
- var wgd = {
- 'col': parseInt($el.attr('data-col'), 10),
- 'row': parseInt($el.attr('data-row'), 10),
- 'size_x': parseInt($el.attr('data-sizex'), 10),
- 'size_y': parseInt($el.attr('data-sizey'), 10),
- 'el': $el
- };
+ var empty_upper_row = this.can_go_widget_up(wgd);
+ if (empty_upper_row) {
+ wgd.row = empty_upper_row;
+ $el.attr('data-row', empty_upper_row);
+ this.$el.trigger('gridster:positionchanged', [wgd]);
+ posChanged = true;
+ }
if (this.options.avoid_overlapped_widgets &&
!this.can_move_to(
{size_x: wgd.size_x, size_y: wgd.size_y}, wgd.col, wgd.row)
) {
- wgd = this.next_position(wgd.size_x, wgd.size_y);
- wgd.el = $el;
+ $.extend(wgd, this.next_position(wgd.size_x, wgd.size_y));
$el.attr({
'data-col': wgd.col,
'data-row': wgd.row,
'data-sizex': wgd.size_x,
'data-sizey': wgd.size_y
});
+ posChanged = true;
}
// attach Coord object to player data-coord attribute
$el.data('coords', $el.coords());
-
// Extend Coord object with grid position info
$el.data('coords').grid = wgd;
this.add_to_gridmap(wgd, $el);
- this.widgets.push($el);
- return this;
+
+ this.options.resize.enabled && this.add_resize_handle($el);
+
+ return posChanged;
};
@@ -1073,14 +1793,16 @@
var self = this;
var draggable_options = $.extend(true, {}, this.options.draggable, {
offset_left: this.options.widget_margins[0],
- items: '.gs_w',
+ offset_top: this.options.widget_margins[1],
+ container_width: this.cols * this.min_widget_width,
+ limit: true,
start: function(event, ui) {
self.$widgets.filter('.player-revert')
.removeClass('player-revert');
self.$player = $(this);
- self.$helper = self.options.draggable.helper === 'clone' ?
- $(ui.helper) : self.$player;
+ self.$helper = $(ui.$helper);
+
self.helper = !self.$helper.is(self.$player);
self.on_start_drag.call(self, event, ui);
@@ -1096,7 +1818,59 @@
}, 60)
});
- this.drag_api = this.$el.drag(draggable_options).data('drag');
+ this.drag_api = this.$el.drag(draggable_options);
+ return this;
+ };
+
+
+ /**
+ * Bind resize events to get resize working.
+ *
+ * @method resizable
+ * @return {Class} Returns instance of gridster Class.
+ */
+ fn.resizable = function() {
+ this.resize_api = this.$el.drag({
+ items: '.' + this.options.resize.handle_class,
+ offset_left: this.options.widget_margins[0],
+ container_width: this.container_width,
+ move_element: false,
+ resize: true,
+ limit: this.options.autogrow_cols ? false : true,
+ start: $.proxy(this.on_start_resize, this),
+ stop: $.proxy(function(event, ui) {
+ delay($.proxy(function() {
+ this.on_stop_resize(event, ui);
+ }, this), 120);
+ }, this),
+ drag: throttle($.proxy(this.on_resize, this), 60)
+ });
+
+ return this;
+ };
+
+
+ /**
+ * Setup things required for resizing. Like build templates for drag handles.
+ *
+ * @method setup_resize
+ * @return {Class} Returns instance of gridster Class.
+ */
+ fn.setup_resize = function() {
+ this.resize_handle_class = this.options.resize.handle_class;
+ var axes = this.options.resize.axes;
+ var handle_tpl = '';
+
+ this.resize_handle_tpl = $.map(axes, function(type) {
+ return handle_tpl.replace('{type}', type);
+ }).join('');
+
+ if ($.isArray(this.options.draggable.ignore_dragging)) {
+ this.options.draggable.ignore_dragging.push(
+ '.' + this.resize_handle_class);
+ }
+
return this;
};
@@ -1105,20 +1879,29 @@
* This function is executed when the player begins to be dragged.
*
* @method on_start_drag
- * @param {Event} The original browser event
- * @param {Object} A prepared ui object.
+ * @param {Event} event The original browser event
+ * @param {Object} ui A prepared ui object with useful drag-related data
*/
fn.on_start_drag = function(event, ui) {
-
this.$helper.add(this.$player).add(this.$wrapper).addClass('dragging');
+ this.highest_col = this.get_highest_occupied_cell().col;
+
this.$player.addClass('player');
this.player_grid_data = this.$player.coords().grid;
this.placeholder_grid_data = $.extend({}, this.player_grid_data);
- //set new grid height along the dragging period
- this.$el.css('height', this.$el.height() +
- (this.player_grid_data.size_y * this.min_widget_height));
+ this.set_dom_grid_height(this.$el.height() +
+ (this.player_grid_data.size_y * this.min_widget_height));
+
+ this.set_dom_grid_width(this.cols);
+
+ var pgd_sizex = this.player_grid_data.size_x;
+ var cols_diff = this.cols - this.highest_col;
+
+ if (this.options.autogrow_cols && cols_diff <= pgd_sizex) {
+ this.add_faux_cols(Math.min(pgd_sizex - cols_diff, 1));
+ }
var colliders = this.faux_grid;
var coords = this.$player.data('coords').coords;
@@ -1131,12 +1914,11 @@
this.last_cols = [];
this.last_rows = [];
-
// see jquery.collision.js
this.collision_api = this.$helper.collision(
colliders, this.options.collision);
- this.$preview_holder = $('', {
+ this.$preview_holder = $('<' + this.$player.get(0).tagName + ' />', {
'class': 'preview-holder',
'data-row': this.$player.attr('data-row'),
'data-col': this.$player.attr('data-col'),
@@ -1156,32 +1938,44 @@
* This function is executed when the player is being dragged.
*
* @method on_drag
- * @param {Event} The original browser event
- * @param {Object} A prepared ui object.
+ * @param {Event} event The original browser event
+ * @param {Object} ui A prepared ui object with useful drag-related data
*/
fn.on_drag = function(event, ui) {
//break if dragstop has been fired
if (this.$player === null) {
return false;
- };
+ }
var abs_offset = {
left: ui.position.left + this.baseX,
top: ui.position.top + this.baseY
};
+ // auto grow cols
+ if (this.options.autogrow_cols) {
+ var prcol = this.placeholder_grid_data.col +
+ this.placeholder_grid_data.size_x - 1;
+
+ // "- 1" due to adding at least 1 column in on_start_drag
+ if (prcol >= this.cols - 1 && this.options.max_cols >= this.cols + 1) {
+ this.add_faux_cols(1);
+ this.set_dom_grid_width(this.cols + 1);
+ this.drag_api.set_limits(this.container_width);
+ }
+
+ this.collision_api.set_colliders(this.faux_grid);
+ }
+
this.colliders_data = this.collision_api.get_closest_colliders(
abs_offset);
this.on_overlapped_column_change(
- this.on_start_overlapping_column,
- this.on_stop_overlapping_column
- );
+ this.on_start_overlapping_column, this.on_stop_overlapping_column);
this.on_overlapped_row_change(
- this.on_start_overlapping_row,
- this.on_stop_overlapping_row
- );
+ this.on_start_overlapping_row, this.on_stop_overlapping_row);
+
if (this.helper && this.$player) {
this.$player.css({
@@ -1195,12 +1989,13 @@
}
};
+
/**
* This function is executed when the player stops being dragged.
*
* @method on_stop_drag
- * @param {Event} The original browser event
- * @param {Object} A prepared ui object.
+ * @param {Event} event The original browser event
+ * @param {Object} ui A prepared ui object with useful drag-related data
*/
fn.on_stop_drag = function(event, ui) {
this.$helper.add(this.$player).add(this.$wrapper)
@@ -1208,7 +2003,8 @@
ui.position.left = ui.position.left + this.baseX;
ui.position.top = ui.position.top + this.baseY;
- this.colliders_data = this.collision_api.get_closest_colliders(ui.position);
+ this.colliders_data = this.collision_api.get_closest_colliders(
+ ui.position);
this.on_overlapped_column_change(
this.on_start_overlapping_column,
@@ -1229,24 +2025,233 @@
'top': ''
});
- this.$changed = this.$changed.add(this.$player);
+ this.$changed = this.$changed.add(this.$player);
+
+ this.cells_occupied_by_player = this.get_cells_occupied(
+ this.placeholder_grid_data);
+ this.set_cells_player_occupies(
+ this.placeholder_grid_data.col, this.placeholder_grid_data.row);
+
+ this.$player.coords().grid.row = this.placeholder_grid_data.row;
+ this.$player.coords().grid.col = this.placeholder_grid_data.col;
+
+ if (this.options.draggable.stop) {
+ this.options.draggable.stop.call(this, event, ui);
+ }
+
+ this.$preview_holder.remove();
+
+ this.$player = null;
+ this.$helper = null;
+ this.placeholder_grid_data = {};
+ this.player_grid_data = {};
+ this.cells_occupied_by_placeholder = {};
+ this.cells_occupied_by_player = {};
+
+ this.set_dom_grid_height();
+ this.set_dom_grid_width();
+
+ if (this.options.autogrow_cols) {
+ this.drag_api.set_limits(this.cols * this.min_widget_width);
+ }
+ };
+
+
+ /**
+ * This function is executed every time a widget starts to be resized.
+ *
+ * @method on_start_resize
+ * @param {Event} event The original browser event
+ * @param {Object} ui A prepared ui object with useful drag-related data
+ */
+ fn.on_start_resize = function(event, ui) {
+ this.$resized_widget = ui.$player.closest('.gs-w');
+ this.resize_coords = this.$resized_widget.coords();
+ this.resize_wgd = this.resize_coords.grid;
+ this.resize_initial_width = this.resize_coords.coords.width;
+ this.resize_initial_height = this.resize_coords.coords.height;
+ this.resize_initial_sizex = this.resize_coords.grid.size_x;
+ this.resize_initial_sizey = this.resize_coords.grid.size_y;
+ this.resize_initial_col = this.resize_coords.grid.col;
+ this.resize_last_sizex = this.resize_initial_sizex;
+ this.resize_last_sizey = this.resize_initial_sizey;
+
+ this.resize_max_size_x = Math.min(this.resize_wgd.max_size_x ||
+ this.options.resize.max_size[0],
+ this.options.max_cols - this.resize_initial_col + 1);
+ this.resize_max_size_y = this.resize_wgd.max_size_y ||
+ this.options.resize.max_size[1];
+
+ this.resize_min_size_x = (this.resize_wgd.min_size_x ||
+ this.options.resize.min_size[0] || 1);
+ this.resize_min_size_y = (this.resize_wgd.min_size_y ||
+ this.options.resize.min_size[1] || 1);
+
+ this.resize_initial_last_col = this.get_highest_occupied_cell().col;
+
+ this.set_dom_grid_width(this.cols);
+
+ this.resize_dir = {
+ right: ui.$player.is('.' + this.resize_handle_class + '-x'),
+ bottom: ui.$player.is('.' + this.resize_handle_class + '-y')
+ };
+
+ this.$resized_widget.css({
+ 'min-width': this.options.widget_base_dimensions[0],
+ 'min-height': this.options.widget_base_dimensions[1]
+ });
+
+ var nodeName = this.$resized_widget.get(0).tagName;
+ this.$resize_preview_holder = $('<' + nodeName + ' />', {
+ 'class': 'preview-holder resize-preview-holder',
+ 'data-row': this.$resized_widget.attr('data-row'),
+ 'data-col': this.$resized_widget.attr('data-col'),
+ 'css': {
+ 'width': this.resize_initial_width,
+ 'height': this.resize_initial_height
+ }
+ }).appendTo(this.$el);
+
+ this.$resized_widget.addClass('resizing');
+
+ if (this.options.resize.start) {
+ this.options.resize.start.call(this, event, ui, this.$resized_widget);
+ }
+
+ this.$el.trigger('gridster:resizestart');
+ };
+
+
+ /**
+ * This function is executed every time a widget stops being resized.
+ *
+ * @method on_stop_resize
+ * @param {Event} event The original browser event
+ * @param {Object} ui A prepared ui object with useful drag-related data
+ */
+ fn.on_stop_resize = function(event, ui) {
+ this.$resized_widget
+ .removeClass('resizing')
+ .css({
+ 'width': '',
+ 'height': ''
+ });
+
+ delay($.proxy(function() {
+ this.$resize_preview_holder
+ .remove()
+ .css({
+ 'min-width': '',
+ 'min-height': ''
+ });
+
+ if (this.options.resize.stop) {
+ this.options.resize.stop.call(this, event, ui, this.$resized_widget);
+ }
+
+ this.$el.trigger('gridster:resizestop');
+ }, this), 300);
+
+ this.set_dom_grid_width();
+
+ if (this.options.autogrow_cols) {
+ this.drag_api.set_limits(this.cols * this.min_widget_width);
+ }
+ };
+
+
+ /**
+ * This function is executed when a widget is being resized.
+ *
+ * @method on_resize
+ * @param {Event} event The original browser event
+ * @param {Object} ui A prepared ui object with useful drag-related data
+ */
+ fn.on_resize = function(event, ui) {
+ var rel_x = (ui.pointer.diff_left);
+ var rel_y = (ui.pointer.diff_top);
+ var wbd_x = this.options.widget_base_dimensions[0];
+ var wbd_y = this.options.widget_base_dimensions[1];
+ var margin_x = this.options.widget_margins[0];
+ var margin_y = this.options.widget_margins[1];
+ var max_size_x = this.resize_max_size_x;
+ var min_size_x = this.resize_min_size_x;
+ var max_size_y = this.resize_max_size_y;
+ var min_size_y = this.resize_min_size_y;
+ var autogrow = this.options.autogrow_cols;
+ var width;
+ var max_width = Infinity;
+ var max_height = Infinity;
+
+ var inc_units_x = Math.ceil((rel_x / (wbd_x + margin_x * 2)) - 0.2);
+ var inc_units_y = Math.ceil((rel_y / (wbd_y + margin_y * 2)) - 0.2);
+
+ var size_x = Math.max(1, this.resize_initial_sizex + inc_units_x);
+ var size_y = Math.max(1, this.resize_initial_sizey + inc_units_y);
+
+ var max_cols = (this.container_width / this.min_widget_width) -
+ this.resize_initial_col + 1;
+ var limit_width = ((max_cols * this.min_widget_width) - margin_x * 2);
+
+ size_x = Math.max(Math.min(size_x, max_size_x), min_size_x);
+ size_x = Math.min(max_cols, size_x);
+ width = (max_size_x * wbd_x) + ((size_x - 1) * margin_x * 2);
+ max_width = Math.min(width, limit_width);
+ min_width = (min_size_x * wbd_x) + ((size_x - 1) * margin_x * 2);
+
+ size_y = Math.max(Math.min(size_y, max_size_y), min_size_y);
+ max_height = (max_size_y * wbd_y) + ((size_y - 1) * margin_y * 2);
+ min_height = (min_size_y * wbd_y) + ((size_y - 1) * margin_y * 2);
+
+ if (this.resize_dir.right) {
+ size_y = this.resize_initial_sizey;
+ } else if (this.resize_dir.bottom) {
+ size_x = this.resize_initial_sizex;
+ }
+
+ if (autogrow) {
+ var last_widget_col = this.resize_initial_col + size_x - 1;
+ if (autogrow && this.resize_initial_last_col <= last_widget_col) {
+ this.set_dom_grid_width(Math.max(last_widget_col + 1, this.cols));
+
+ if (this.cols < last_widget_col) {
+ this.add_faux_cols(last_widget_col - this.cols);
+ }
+ }
+ }
+
+ var css_props = {};
+ !this.resize_dir.bottom && (css_props.width = Math.max(Math.min(
+ this.resize_initial_width + rel_x, max_width), min_width));
+ !this.resize_dir.right && (css_props.height = Math.max(Math.min(
+ this.resize_initial_height + rel_y, max_height), min_height));
- this.cells_occupied_by_player = this.get_cells_occupied(
- this.placeholder_grid_data);
- this.set_cells_player_occupies(
- this.placeholder_grid_data.col, this.placeholder_grid_data.row);
+ this.$resized_widget.css(css_props);
- this.$player.coords().grid.row = this.placeholder_grid_data.row;
- this.$player.coords().grid.col = this.placeholder_grid_data.col;
+ if (size_x !== this.resize_last_sizex ||
+ size_y !== this.resize_last_sizey) {
- if (this.options.draggable.stop) {
- this.options.draggable.stop.call(this, event, ui);
+ this.resize_widget(this.$resized_widget, size_x, size_y);
+ this.set_dom_grid_width(this.cols);
+
+ this.$resize_preview_holder.css({
+ 'width': '',
+ 'height': ''
+ }).attr({
+ 'data-row': this.$resized_widget.attr('data-row'),
+ 'data-sizex': size_x,
+ 'data-sizey': size_y
+ });
}
- this.$preview_holder.remove();
- this.$player = null;
+ if (this.options.resize.resize) {
+ this.options.resize.resize.call(this, event, ui, this.$resized_widget);
+ }
- this.set_dom_grid_height();
+ this.$el.trigger('gridster:resize');
+
+ this.resize_last_sizex = size_x;
+ this.resize_last_sizey = size_y;
};
@@ -1263,7 +2268,7 @@
*/
fn.on_overlapped_column_change = function(start_callback, stop_callback) {
if (!this.colliders_data.length) {
- return;
+ return this;
}
var cols = this.get_targeted_columns(
this.colliders_data[0].el.data.col);
@@ -1296,14 +2301,14 @@
*
* @param {Function} start_callback Function executed when a new row begins
* to be overlapped. The row is passed as first argument.
- * @param {Function} stop_callback Function executed when a row stops being
+ * @param {Function} end_callback Function executed when a row stops being
* overlapped. The row is passed as first argument.
* @method on_overlapped_row_change
* @return {Class} Returns the instance of the Gridster Class.
*/
fn.on_overlapped_row_change = function(start_callback, end_callback) {
if (!this.colliders_data.length) {
- return;
+ return this;
}
var rows = this.get_targeted_rows(this.colliders_data[0].el.data.row);
var last_n_rows = this.last_rows.length;
@@ -1329,18 +2334,18 @@
/**
* Sets the current position of the player
*
- * @param {Function} start_callback Function executed when a new row begins
- * to be overlapped. The row is passed as first argument.
- * @param {Function} stop_callback Function executed when a row stops being
- * overlapped. The row is passed as first argument.
+ * @param {Number} col
+ * @param {Number} row
+ * @param {Boolean} no_player
* @method set_player
- * @return {Class} Returns the instance of the Gridster Class.
+ * @return {object}
*/
- fn.set_player = function(col, row) {
- this.empty_cells_player_occupies();
-
+ fn.set_player = function(col, row, no_player) {
var self = this;
- var cell = self.colliders_data[0].el.data;
+ if (!no_player) {
+ this.empty_cells_player_occupies();
+ }
+ var cell = !no_player ? self.colliders_data[0].el.data : {col: col};
var to_col = cell.col;
var to_row = row || cell.row;
@@ -1384,9 +2389,9 @@
* a upper row and which not.
*
* @method widgets_contraints
- * @param {HTMLElements} $widgets A jQuery wrapped collection of
+ * @param {jQuery} $widgets A jQuery wrapped collection of
* HTMLElements.
- * @return {Array} Returns a literal Object with two keys: `can_go_up` &
+ * @return {object} Returns a literal Object with two keys: `can_go_up` &
* `can_not_go_up`. Each contains a set of HTMLElements.
*/
fn.widgets_constraints = function($widgets) {
@@ -1401,7 +2406,7 @@
if (this.can_go_widget_up(wgd)) {
$widgets_can_go_up = $widgets_can_go_up.add($w);
wgd_can_go_up.push(wgd);
- }else{
+ } else {
wgd_can_not_go_up.push(wgd);
}
}, this));
@@ -1409,97 +2414,18 @@
$widgets_can_not_go_up = $widgets.not($widgets_can_go_up);
return {
- can_go_up: this.sort_by_row_asc(wgd_can_go_up),
- can_not_go_up: this.sort_by_row_desc(wgd_can_not_go_up)
+ can_go_up: Gridster.sort_by_row_asc(wgd_can_go_up),
+ can_not_go_up: Gridster.sort_by_row_desc(wgd_can_not_go_up)
};
};
- /**
- * Sorts an Array of grid coords objects (representing the grid coords of
- * each widget) in ascending way.
- *
- * @method sort_by_row_asc
- * @param {Array} widgets Array of grid coords objects
- * @return {Array} Returns the array sorted.
- */
- fn.sort_by_row_asc = function(widgets) {
- widgets = widgets.sort(function(a, b) {
- if (a.row > b.row) {
- return 1;
- }
- return -1;
- });
-
- return widgets;
- };
-
-
- /**
- * Sorts an Array of grid coords objects (representing the grid coords of
- * each widget) placing first the empty cells upper left.
- *
- * @method sort_by_row_and_col_asc
- * @param {Array} widgets Array of grid coords objects
- * @return {Array} Returns the array sorted.
- */
- fn.sort_by_row_and_col_asc = function(widgets) {
- widgets = widgets.sort(function(a, b) {
- if (a.row > b.row || a.row == b.row && a.col > b.col) {
- return 1;
- }
- return -1;
- });
-
- return widgets;
- };
-
-
- /**
- * Sorts an Array of grid coords objects by column (representing the grid
- * coords of each widget) in ascending way.
- *
- * @method sort_by_col_asc
- * @param {Array} widgets Array of grid coords objects
- * @return {Array} Returns the array sorted.
- */
- fn.sort_by_col_asc = function(widgets) {
- widgets = widgets.sort(function(a, b) {
- if (a.col > b.col) {
- return 1;
- }
- return -1;
- });
-
- return widgets;
- };
-
-
- /**
- * Sorts an Array of grid coords objects (representing the grid coords of
- * each widget) in descending way.
- *
- * @method sort_by_row_desc
- * @param {Array} widgets Array of grid coords objects
- * @return {Array} Returns the array sorted.
- */
- fn.sort_by_row_desc = function(widgets) {
- widgets = widgets.sort(function(a, b) {
- if (a.row + a.size_y < b.row + b.size_y) {
- return 1;
- }
- return -1;
- });
- return widgets;
- };
-
-
/**
* Sorts an Array of grid coords objects (representing the grid coords of
* each widget) in descending way.
*
* @method manage_movements
- * @param {HTMLElements} $widgets A jQuery collection of HTMLElements
+ * @param {jQuery} $widgets A jQuery collection of HTMLElements
* representing the widgets you want to move.
* @param {Number} to_col The column to which we want to move the widgets.
* @param {Number} to_row The row to which we want to move the widgets.
@@ -1607,13 +2533,15 @@
* @return {Boolean} Returns true or false.
*/
fn.is_empty = function(col, row) {
- if (typeof this.gridmap[col] !== 'undefined' &&
- typeof this.gridmap[col][row] !== 'undefined' &&
- this.gridmap[col][row] === false
- ) {
- return true;
- }
- return false;
+ if (typeof this.gridmap[col] !== 'undefined') {
+ if(typeof this.gridmap[col][row] !== 'undefined' &&
+ this.gridmap[col][row] === false
+ ) {
+ return true;
+ }
+ return false;
+ }
+ return true;
};
@@ -1680,13 +2608,14 @@
/**
- * Get widgets overlapping with the player.
+ * Get widgets overlapping with the player or with the object passed
+ * representing the grid cells.
*
* @method get_widgets_under_player
* @return {HTMLElement} Returns a jQuery collection of HTMLElements
*/
- fn.get_widgets_under_player = function() {
- var cells = this.cells_occupied_by_player;
+ fn.get_widgets_under_player = function(cells) {
+ cells || (cells = this.cells_occupied_by_player || {cols: [], rows: []});
var $widgets = $([]);
$.each(cells.cols, $.proxy(function(i, col) {
@@ -1720,7 +2649,7 @@
size_x: phgd.size_x
});
- //Prevents widgets go out of the grid
+ // Prevents widgets go out of the grid
var right_col = (col + phgd.size_x - 1);
if (right_col > this.cols) {
col = col - (right_col - col);
@@ -1747,6 +2676,17 @@
}, this));
}
+ var $widgets_under_ph = this.get_widgets_under_player(
+ this.cells_occupied_by_placeholder);
+
+ if ($widgets_under_ph.length) {
+ $widgets_under_ph.each($.proxy(function(i, widget) {
+ var $w = $(widget);
+ this.move_widget_down(
+ $w, row + phgd.size_y - $w.data('coords').grid.row);
+ }, this));
+ }
+
};
@@ -1780,7 +2720,7 @@
) {
upper_rows[tcol].push(r);
min_row = r < min_row ? r : min_row;
- }else{
+ } else {
break;
}
}
@@ -1790,7 +2730,9 @@
return true; //break
}
- upper_rows[tcol].sort();
+ upper_rows[tcol].sort(function(a, b) {
+ return a - b;
+ });
});
if (!result) { return false; }
@@ -1814,33 +2756,26 @@
var upper_rows = [];
var min_row = 10000;
- if (widget_grid_data.col < this.player_grid_data.col &&
- (widget_grid_data.col + widget_grid_data.size_y - 1) >
- (this.player_grid_data.col + this.player_grid_data.size_y - 1)
- ) {
- return false;
- };
-
- /* generate an array with columns as index and array with upper rows
+ /* generate an array with columns as index and array with topmost rows
* empty as value */
this.for_each_column_occupied(widget_grid_data, function(tcol) {
var grid_col = this.gridmap[tcol];
upper_rows[tcol] = [];
var r = p_bottom_row + 1;
-
+ // iterate over each row
while (--r > 0) {
if (this.is_widget(tcol, r) && !this.is_player_in(tcol, r)) {
if (!grid_col[r].is(widget_grid_data.el)) {
break;
- };
+ }
}
if (!this.is_player(tcol, r) &&
!this.is_placeholder_in(tcol, r) &&
!this.is_player_in(tcol, r)) {
upper_rows[tcol].push(r);
- };
+ }
if (r < min_row) {
min_row = r;
@@ -1852,7 +2787,9 @@
return true; //break
}
- upper_rows[tcol].sort();
+ upper_rows[tcol].sort(function(a, b) {
+ return a - b;
+ });
});
if (!result) { return false; }
@@ -1902,7 +2839,7 @@
if (valid_rows[0] !== p_top_row) {
new_row = valid_rows[0] || false;
}
- }else{
+ } else {
if (valid_rows[0] !== p_top_row) {
new_row = this.get_consecutive_numbers_index(
valid_rows, size_y);
@@ -1926,7 +2863,7 @@
break;
}
first = false;
- }else{
+ } else {
result = [];
first = true;
}
@@ -1942,7 +2879,7 @@
* Get widgets overlapping with the player.
*
* @method get_widgets_overlapped
- * @return {HTMLElements} Returns a jQuery collection of HTMLElements.
+ * @return {jQuery} Returns a jQuery collection of HTMLElements.
*/
fn.get_widgets_overlapped = function() {
var $w;
@@ -1956,7 +2893,6 @@
// if there is a widget in the player position
if (!this.gridmap[col]) { return true; } //next iteration
var $w = this.gridmap[col][row];
-
if (this.is_occupied(col, row) && !this.is_player($w) &&
$.inArray($w, used) === -1
) {
@@ -1976,7 +2912,7 @@
*
* @method on_start_overlapping_column
* @param {Number} col The collided column.
- * @return {HTMLElements} Returns a jQuery collection of HTMLElements.
+ * @return {jQuery} Returns a jQuery collection of HTMLElements.
*/
fn.on_start_overlapping_column = function(col) {
this.set_player(col, false);
@@ -1987,8 +2923,8 @@
* A callback executed when the player begins to collide with a row.
*
* @method on_start_overlapping_row
- * @param {Number} col The collided row.
- * @return {HTMLElements} Returns a jQuery collection of HTMLElements.
+ * @param {Number} row The collided row.
+ * @return {jQuery} Returns a jQuery collection of HTMLElements.
*/
fn.on_start_overlapping_row = function(row) {
this.set_player(false, row);
@@ -2000,7 +2936,7 @@
*
* @method on_stop_overlapping_column
* @param {Number} col The collided row.
- * @return {HTMLElements} Returns a jQuery collection of HTMLElements.
+ * @return {jQuery} Returns a jQuery collection of HTMLElements.
*/
fn.on_stop_overlapping_column = function(col) {
this.set_player(col, false);
@@ -2018,7 +2954,7 @@
*
* @method on_stop_overlapping_row
* @param {Number} row The collided row.
- * @return {HTMLElements} Returns a jQuery collection of HTMLElements.
+ * @return {jQuery} Returns a jQuery collection of HTMLElements.
*/
fn.on_stop_overlapping_row = function(row) {
this.set_player(false, row);
@@ -2128,16 +3064,20 @@
* Move down the specified widget and all below it.
*
* @method move_widget_down
- * @param {HTMLElement} $widget The jQuery object representing the widget
+ * @param {jQuery} $widget The jQuery object representing the widget
* you want to move.
- * @param {Number} The number of cells that the widget has to move.
+ * @param {Number} y_units The number of cells that the widget has to move.
* @return {Class} Returns the instance of the Gridster Class.
*/
fn.move_widget_down = function($widget, y_units) {
- var el_grid_data = $widget.coords().grid;
- var actual_row = el_grid_data.row;
- var moved = [];
- var y_diff = y_units;
+ var el_grid_data, actual_row, moved, y_diff;
+
+ if (y_units <= 0) { return false; }
+
+ el_grid_data = $widget.coords().grid;
+ actual_row = el_grid_data.row;
+ moved = [];
+ y_diff = y_units;
if (!$widget) { return false; }
@@ -2201,7 +3141,7 @@
!this.is_placeholder_in(tcol, r)
) {
urc[tcol].push(r);
- }else{
+ } else {
break;
}
}
@@ -2266,7 +3206,7 @@
*
* @method widgets_below
* @param {HTMLElement} $el The jQuery wrapped HTMLElement.
- * @return {HTMLElements} A jQuery collection of HTMLElements.
+ * @return {jQuery} A jQuery collection of HTMLElements.
*/
fn.widgets_below = function($el) {
var el_grid_data = $.isPlainObject($el) ? $el : $el.coords().grid;
@@ -2276,17 +3216,15 @@
var $nexts = $([]);
this.for_each_column_occupied(el_grid_data, function(col) {
- self.for_each_widget_below(col, next_row,
- function(tcol, trow) {
- if (!self.is_player(this) &&
- $.inArray(this, $nexts) === -1) {
- $nexts = $nexts.add(this);
- return true; // break
- }
- });
+ self.for_each_widget_below(col, next_row, function(tcol, trow) {
+ if (!self.is_player(this) && $.inArray(this, $nexts) === -1) {
+ $nexts = $nexts.add(this);
+ return true; // break
+ }
+ });
});
- return this.sort_by_row_asc($nexts);
+ return Gridster.sort_by_row_asc($nexts);
};
@@ -2331,6 +3269,7 @@
this.for_each_column_occupied(el_grid_data, function(col) {
var $w = this.is_widget(col, prev_row);
+
if (this.is_occupied(col, prev_row) ||
this.is_player(col, prev_row) ||
this.is_placeholder_in(col, prev_row) ||
@@ -2345,7 +3284,6 @@
};
-
/**
* Check if it's possible to move a widget to a specific col/row. It takes
* into account the dimensions (`size_y` and `size_x` attrs. of the grid
@@ -2356,9 +3294,10 @@
* the widget.
* @param {Object} col The col to check.
* @param {Object} row The row to check.
+ * @param {Number} [max_row] The max row allowed.
* @return {Boolean} Returns true if all cells are empty, else return false.
*/
- fn.can_move_to = function(widget_grid_data, col, row) {
+ fn.can_move_to = function(widget_grid_data, col, row, max_row) {
var ga = this.gridmap;
var $w = widget_grid_data.el;
var future_wd = {
@@ -2373,7 +3312,11 @@
var right_col = col + widget_grid_data.size_x - 1;
if (right_col > this.cols) {
return false;
- };
+ }
+
+ if (max_row && max_row < row + widget_grid_data.size_y - 1) {
+ return false;
+ }
this.for_each_cell_occupied(future_wd, function(tcol, trow) {
var $tw = this.is_widget(tcol, trow);
@@ -2432,7 +3375,7 @@
fn.get_cells_occupied = function(el_grid_data) {
var cells = { cols: [], rows: []};
var i;
- if (arguments[1] instanceof jQuery) {
+ if (arguments[1] instanceof $) {
el_grid_data = arguments[1].coords().grid;
}
@@ -2516,7 +3459,7 @@
var cr, max;
var action = type + '/' + direction;
- if (arguments[2] instanceof jQuery) {
+ if (arguments[2] instanceof $) {
var el_grid_data = arguments[2].coords().grid;
col = el_grid_data.col;
row = el_grid_data.row;
@@ -2600,26 +3543,23 @@
fn.get_highest_occupied_cell = function() {
var r;
var gm = this.gridmap;
- var rows = [];
+ var rl = gm[1].length;
+ var rows = [], cols = [];
var row_in_col = [];
for (var c = gm.length - 1; c >= 1; c--) {
- for (r = gm[c].length - 1; r >= 1; r--) {
+ for (r = rl - 1; r >= 1; r--) {
if (this.is_widget(c, r)) {
rows.push(r);
- row_in_col[r] = c;
+ cols.push(c);
break;
}
}
}
- var highest_row = Math.max.apply(Math, rows);
-
- this.highest_occupied_cell = {
- col: row_in_col[highest_row],
- row: highest_row
+ return {
+ col: Math.max.apply(Math, cols),
+ row: Math.max.apply(Math, rows)
};
-
- return this.highest_occupied_cell;
};
@@ -2646,7 +3586,7 @@
}
return $widgets;
- }
+ };
/**
@@ -2655,9 +3595,34 @@
* @method set_dom_grid_height
* @return {Object} Returns the instance of the Gridster class.
*/
- fn.set_dom_grid_height = function() {
- var r = this.get_highest_occupied_cell().row;
- this.$el.css('height', r * this.min_widget_height);
+ fn.set_dom_grid_height = function(height) {
+ if (typeof height === 'undefined') {
+ var r = this.get_highest_occupied_cell().row;
+ height = r * this.min_widget_height;
+ }
+
+ this.container_height = height;
+ this.$el.css('height', this.container_height);
+ return this;
+ };
+
+ /**
+ * Set the current width of the parent grid.
+ *
+ * @method set_dom_grid_width
+ * @return {Object} Returns the instance of the Gridster class.
+ */
+ fn.set_dom_grid_width = function(cols) {
+ if (typeof cols === 'undefined') {
+ cols = this.get_highest_occupied_cell().col;
+ }
+
+ var max_cols = (this.options.autogrow_cols ? this.options.max_cols :
+ this.cols);
+
+ cols = Math.min(max_cols, Math.max(cols, this.options.min_cols));
+ this.container_width = cols * this.min_widget_width;
+ this.$el.css('width', this.container_width);
return this;
};
@@ -2672,16 +3637,16 @@
*/
fn.generate_stylesheet = function(opts) {
var styles = '';
- var extra_cells = 10;
- var max_size_y = this.options.max_size_y;
- var max_size_x = this.options.max_size_x;
+ var max_size_x = this.options.max_size_x || this.cols;
+ var max_rows = 0;
+ var max_cols = 0;
var i;
var rules;
opts || (opts = {});
opts.cols || (opts.cols = this.cols);
opts.rows || (opts.rows = this.rows);
- opts.namespace || (opts.namespace = '');
+ opts.namespace || (opts.namespace = this.options.namespace);
opts.widget_base_dimensions ||
(opts.widget_base_dimensions = this.options.widget_base_dimensions);
opts.widget_margins ||
@@ -2691,42 +3656,45 @@
opts.min_widget_height = (opts.widget_margins[1] * 2) +
opts.widget_base_dimensions[1];
- var serialized_opts = $.param(opts);
// don't duplicate stylesheets for the same configuration
+ var serialized_opts = $.param(opts);
if ($.inArray(serialized_opts, Gridster.generated_stylesheets) >= 0) {
return false;
}
+ this.generated_stylesheets.push(serialized_opts);
Gridster.generated_stylesheets.push(serialized_opts);
/* generate CSS styles for cols */
- for (i = opts.cols + extra_cells; i >= 0; i--) {
+ for (i = opts.cols; i >= 0; i--) {
styles += (opts.namespace + ' [data-col="'+ (i + 1) + '"] { left:' +
((i * opts.widget_base_dimensions[0]) +
(i * opts.widget_margins[0]) +
- ((i + 1) * opts.widget_margins[0])) + 'px;} ');
+ ((i + 1) * opts.widget_margins[0])) + 'px; }\n');
}
/* generate CSS styles for rows */
- for (i = opts.rows + extra_cells; i >= 0; i--) {
+ for (i = opts.rows; i >= 0; i--) {
styles += (opts.namespace + ' [data-row="' + (i + 1) + '"] { top:' +
((i * opts.widget_base_dimensions[1]) +
(i * opts.widget_margins[1]) +
- ((i + 1) * opts.widget_margins[1]) ) + 'px;} ');
+ ((i + 1) * opts.widget_margins[1]) ) + 'px; }\n');
}
- for (var y = 1; y <= max_size_y; y++) {
+ for (var y = 1; y <= opts.rows; y++) {
styles += (opts.namespace + ' [data-sizey="' + y + '"] { height:' +
(y * opts.widget_base_dimensions[1] +
- (y - 1) * (opts.widget_margins[1] * 2)) + 'px;}');
+ (y - 1) * (opts.widget_margins[1] * 2)) + 'px; }\n');
}
for (var x = 1; x <= max_size_x; x++) {
styles += (opts.namespace + ' [data-sizex="' + x + '"] { width:' +
(x * opts.widget_base_dimensions[0] +
- (x - 1) * (opts.widget_margins[0] * 2)) + 'px;}');
+ (x - 1) * (opts.widget_margins[0] * 2)) + 'px; }\n');
}
+ this.remove_style_tags();
+
return this.add_style_tag(styles);
};
@@ -2739,18 +3707,39 @@
* @return {Object} Returns the instance of the Gridster class.
*/
fn.add_style_tag = function(css) {
- var d = document;
- var tag = d.createElement('style');
+ var d = document;
+ var tag = d.createElement('style');
+
+ d.getElementsByTagName('head')[0].appendChild(tag);
+ tag.setAttribute('type', 'text/css');
+
+ if (tag.styleSheet) {
+ tag.styleSheet.cssText = css;
+ } else {
+ tag.appendChild(document.createTextNode(css));
+ }
+
+ this.$style_tags = this.$style_tags.add(tag);
+
+ return this;
+ };
+
- d.getElementsByTagName('head')[0].appendChild(tag);
- tag.setAttribute('type', 'text/css');
+ /**
+ * Remove the style tag with the associated id from the head of the document
+ *
+ * @method remove_style_tag
+ * @return {Object} Returns the instance of the Gridster class.
+ */
+ fn.remove_style_tags = function() {
+ var all_styles = Gridster.generated_stylesheets;
+ var ins_styles = this.generated_stylesheets;
- if (tag.styleSheet) {
- tag.styleSheet.cssText = css;
- }else{
- tag.appendChild(document.createTextNode(css));
- }
- return this;
+ this.$style_tags.remove();
+
+ Gridster.generated_stylesheets = $.map(all_styles, function(s) {
+ if ($.inArray(s, ins_styles) === -1) { return s; }
+ });
};
@@ -2771,7 +3760,23 @@
for (col = cols; col > 0; col--) {
this.gridmap[col] = [];
for (row = rows; row > 0; row--) {
- var coords = $({
+ this.add_faux_cell(row, col);
+ }
+ }
+ return this;
+ };
+
+
+ /**
+ * Add cell to the faux grid.
+ *
+ * @method add_faux_cell
+ * @param {Number} row The row for the new faux cell.
+ * @param {Number} col The col for the new faux cell.
+ * @return {Object} Returns the instance of the Gridster class.
+ */
+ fn.add_faux_cell = function(row, col) {
+ var coords = $({
left: this.baseX + ((col - 1) * this.min_widget_width),
top: this.baseY + (row -1) * this.min_widget_height,
width: this.min_widget_width,
@@ -2782,10 +3787,67 @@
original_row: row
}).coords();
- this.gridmap[col][row] = false;
- this.faux_grid.push(coords);
+ if (!$.isArray(this.gridmap[col])) {
+ this.gridmap[col] = [];
+ }
+
+ this.gridmap[col][row] = false;
+ this.faux_grid.push(coords);
+
+ return this;
+ };
+
+
+ /**
+ * Add rows to the faux grid.
+ *
+ * @method add_faux_rows
+ * @param {Number} rows The number of rows you want to add to the faux grid.
+ * @return {Object} Returns the instance of the Gridster class.
+ */
+ fn.add_faux_rows = function(rows) {
+ var actual_rows = this.rows;
+ var max_rows = actual_rows + (rows || 1);
+
+ for (var r = max_rows; r > actual_rows; r--) {
+ for (var c = this.cols; c >= 1; c--) {
+ this.add_faux_cell(r, c);
+ }
+ }
+
+ this.rows = max_rows;
+
+ if (this.options.autogenerate_stylesheet) {
+ this.generate_stylesheet();
+ }
+
+ return this;
+ };
+
+ /**
+ * Add cols to the faux grid.
+ *
+ * @method add_faux_cols
+ * @param {Number} cols The number of cols you want to add to the faux grid.
+ * @return {Object} Returns the instance of the Gridster class.
+ */
+ fn.add_faux_cols = function(cols) {
+ var actual_cols = this.cols;
+ var max_cols = actual_cols + (cols || 1);
+ max_cols = Math.min(max_cols, this.options.max_cols);
+
+ for (var c = actual_cols + 1; c <= max_cols; c++) {
+ for (var r = this.rows; r >= 1; r--) {
+ this.add_faux_cell(r, c);
}
}
+
+ this.cols = max_cols;
+
+ if (this.options.autogenerate_stylesheet) {
+ this.generate_stylesheet();
+ }
+
return this;
};
@@ -2807,7 +3869,6 @@
left: this.baseX + (coords.data.col -1) * this.min_widget_width,
top: this.baseY + (coords.data.row -1) * this.min_widget_height
});
-
}, this));
return this;
@@ -2821,9 +3882,21 @@
* @return {Object} Returns the instance of the Gridster class.
*/
fn.get_widgets_from_DOM = function() {
- this.$widgets.each($.proxy(function(i, widget) {
- this.register_widget($(widget));
+ var widgets_coords = this.$widgets.map($.proxy(function(i, widget) {
+ var $w = $(widget);
+ return this.dom_to_coords($w);
}, this));
+
+ widgets_coords = Gridster.sort_by_row_and_col_asc(widgets_coords);
+
+ var changes = $(widgets_coords).map($.proxy(function(i, wgd) {
+ return this.register_widget(wgd) || null;
+ }, this));
+
+ if (changes.length) {
+ this.$el.trigger('gridster:positionschanged');
+ }
+
return this;
};
@@ -2837,32 +3910,33 @@
*/
fn.generate_grid_and_stylesheet = function() {
var aw = this.$wrapper.width();
- var ah = this.$wrapper.height();
+ var max_cols = this.options.max_cols;
var cols = Math.floor(aw / this.min_widget_width) +
this.options.extra_cols;
- var rows = Math.floor(ah / this.min_widget_height) +
- this.options.extra_rows;
var actual_cols = this.$widgets.map(function() {
return $(this).attr('data-col');
- });
- actual_cols = Array.prototype.slice.call(actual_cols, 0);
- //needed to pass tests with phantomjs
- actual_cols.length || (actual_cols = [0]);
+ }).get();
- var actual_rows = this.$widgets.map(function() {
- return $(this).attr('data-row');
- });
- actual_rows = Array.prototype.slice.call(actual_rows, 0);
//needed to pass tests with phantomjs
- actual_rows.length || (actual_rows = [0]);
+ actual_cols.length || (actual_cols = [0]);
var min_cols = Math.max.apply(Math, actual_cols);
- var min_rows = Math.max.apply(Math, actual_rows);
this.cols = Math.max(min_cols, cols, this.options.min_cols);
- this.rows = Math.max(min_rows, rows, this.options.min_rows);
+
+ if (max_cols !== Infinity && max_cols >= min_cols && max_cols < this.cols) {
+ this.cols = max_cols;
+ }
+
+ // get all rows that could be occupied by the current widgets
+ var max_rows = this.options.extra_rows;
+ this.$widgets.each(function(i, w) {
+ max_rows += (+$(w).attr('data-sizey'));
+ });
+
+ this.rows = Math.max(max_rows, this.options.min_rows);
this.baseX = ($(window).width() - aw) / 2;
this.baseY = this.$wrapper.offset().top;
@@ -2871,20 +3945,43 @@
this.generate_stylesheet();
}
- /* more faux rows that needed are created so that there are cells
- * where drag beyond the limits */
return this.generate_faux_grid(this.rows, this.cols);
};
+ /**
+ * Destroy this gridster by removing any sign of its presence, making it easy to avoid memory leaks
+ *
+ * @method destroy
+ * @param {Boolean} remove If true, remove gridster from DOM.
+ * @return {Object} Returns the instance of the Gridster class.
+ */
+ fn.destroy = function(remove) {
+ this.$el.removeData('gridster');
+
+ // remove bound callback on window resize
+ $(window).unbind('.gridster');
+
+ if (this.drag_api) {
+ this.drag_api.destroy();
+ }
+
+ this.remove_style_tags();
+
+ remove && this.$el.remove();
+
+ return this;
+ };
+
//jQuery adapter
$.fn.gridster = function(options) {
- return this.each(function() {
- if (!$(this).data('gridster')) {
- $(this).data('gridster', new Gridster( this, options ));
- }
- });
+ return this.each(function() {
+ if (! $(this).data('gridster')) {
+ $(this).data('gridster', new Gridster( this, options ));
+ }
+ });
};
+ return Gridster;
-}(jQuery, window, document));
+}));
diff --git a/dist/jquery.gridster.min.css b/dist/jquery.gridster.min.css
index deeeab94..9d9fe844 100644
--- a/dist/jquery.gridster.min.css
+++ b/dist/jquery.gridster.min.css
@@ -1,3 +1,2 @@
-/*! gridster.js - v0.1.0 - 2012-08-13
-* http://gridster.net/
-* Copyright (c) 2012 ducksboard; Licensed MIT */.gridster{position:relative}.gridster>*{margin:0 auto;-webkit-transition:height .4s;-moz-transition:height .4s;-o-transition:height .4s;-ms-transition:height .4s;transition:height .4s}.gridster .gs_w{z-index:2;position:absolute}.ready .gs_w:not(.preview-holder){-webkit-transition:opacity .3s,left .3s,top .3s;-moz-transition:opacity .3s,left .3s,top .3s;-o-transition:opacity .3s,left .3s,top .3s;transition:opacity .3s,left .3s,top .3s}.gridster .preview-holder{z-index:1;position:absolute;background-color:#fff;border-color:#fff;opacity:.3}.gridster .player-revert{z-index:10!important;-webkit-transition:left .3s,top .3s!important;-moz-transition:left .3s,top .3s!important;-o-transition:left .3s,top .3s!important;transition:left .3s,top .3s!important}.gridster .dragging{z-index:10!important;-webkit-transition:all 0s!important;-moz-transition:all 0s!important;-o-transition:all 0s!important;transition:all 0s!important}
\ No newline at end of file
+/*! gridster.js - v0.5.6 - 2014-09-25 - * http://gridster.net/ - Copyright (c) 2014 ducksboard; Licensed MIT */
+.gridster{position:relative}.gridster>*{margin:0 auto;-webkit-transition:height .4s,width .4s;-moz-transition:height .4s,width .4s;-o-transition:height .4s,width .4s;-ms-transition:height .4s,width .4s;transition:height .4s,width .4s}.gridster .gs-w{z-index:2;position:absolute}.ready .gs-w:not(.preview-holder){-webkit-transition:opacity .3s,left .3s,top .3s;-moz-transition:opacity .3s,left .3s,top .3s;-o-transition:opacity .3s,left .3s,top .3s;transition:opacity .3s,left .3s,top .3s}.ready .gs-w:not(.preview-holder),.ready .resize-preview-holder{-webkit-transition:opacity .3s,left .3s,top .3s,width .3s,height .3s;-moz-transition:opacity .3s,left .3s,top .3s,width .3s,height .3s;-o-transition:opacity .3s,left .3s,top .3s,width .3s,height .3s;transition:opacity .3s,left .3s,top .3s,width .3s,height .3s}.gridster .preview-holder{z-index:1;position:absolute;background-color:#fff;border-color:#fff;opacity:.3}.gridster .player-revert{z-index:10!important;-webkit-transition:left .3s,top .3s!important;-moz-transition:left .3s,top .3s!important;-o-transition:left .3s,top .3s!important;transition:left .3s,top .3s!important}.gridster .dragging,.gridster .resizing{z-index:10!important;-webkit-transition:all 0s!important;-moz-transition:all 0s!important;-o-transition:all 0s!important;transition:all 0s!important}.gs-resize-handle{position:absolute;z-index:1}.gs-resize-handle-both{width:20px;height:20px;bottom:-8px;right:-8px;background-image:url(data:image/svg+xml;base64,PD94bWwgdmVyc2lvbj0iMS4wIiBzdGFuZGFsb25lPSJubyI/Pg08IS0tIEdlbmVyYXRvcjogQWRvYmUgRmlyZXdvcmtzIENTNiwgRXhwb3J0IFNWRyBFeHRlbnNpb24gYnkgQWFyb24gQmVhbGwgKGh0dHA6Ly9maXJld29ya3MuYWJlYWxsLmNvbSkgLiBWZXJzaW9uOiAwLjYuMSAgLS0+DTwhRE9DVFlQRSBzdmcgUFVCTElDICItLy9XM0MvL0RURCBTVkcgMS4xLy9FTiIgImh0dHA6Ly93d3cudzMub3JnL0dyYXBoaWNzL1NWRy8xLjEvRFREL3N2ZzExLmR0ZCI+DTxzdmcgaWQ9IlVudGl0bGVkLVBhZ2UlMjAxIiB2aWV3Qm94PSIwIDAgNiA2IiBzdHlsZT0iYmFja2dyb3VuZC1jb2xvcjojZmZmZmZmMDAiIHZlcnNpb249IjEuMSINCXhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyIgeG1sbnM6eGxpbms9Imh0dHA6Ly93d3cudzMub3JnLzE5OTkveGxpbmsiIHhtbDpzcGFjZT0icHJlc2VydmUiDQl4PSIwcHgiIHk9IjBweCIgd2lkdGg9IjZweCIgaGVpZ2h0PSI2cHgiDT4NCTxnIG9wYWNpdHk9IjAuMzAyIj4NCQk8cGF0aCBkPSJNIDYgNiBMIDAgNiBMIDAgNC4yIEwgNCA0LjIgTCA0LjIgNC4yIEwgNC4yIDAgTCA2IDAgTCA2IDYgTCA2IDYgWiIgZmlsbD0iIzAwMDAwMCIvPg0JPC9nPg08L3N2Zz4=);background-position:top left;background-repeat:no-repeat;cursor:se-resize;z-index:20}.gs-resize-handle-x{top:0;bottom:13px;right:-5px;width:10px;cursor:e-resize}.gs-resize-handle-y{left:0;right:13px;bottom:-5px;height:10px;cursor:s-resize}.gs-w:hover .gs-resize-handle,.resizing .gs-resize-handle{opacity:1}.gs-resize-handle,.gs-w.dragging .gs-resize-handle{opacity:0}.gs-resize-disabled .gs-resize-handle{display:none!important}[data-max-sizex="1"] .gs-resize-handle-x,[data-max-sizey="1"] .gs-resize-handle-y,[data-max-sizey="1"][data-max-sizex="1"] .gs-resize-handle{display:none!important}
\ No newline at end of file
diff --git a/dist/jquery.gridster.min.js b/dist/jquery.gridster.min.js
index 7f35fe17..a256947a 100644
--- a/dist/jquery.gridster.min.js
+++ b/dist/jquery.gridster.min.js
@@ -1,4 +1,2 @@
-/*! gridster.js - v0.1.0 - 2012-08-14
-* http://gridster.net/
-* Copyright (c) 2012 ducksboard; Licensed MIT */
-(function(a,b,c,d){function e(b){return b[0]&&a.isPlainObject(b[0])?this.data=b[0]:this.el=b,this.isCoords=!0,this.coords={},this.init(),this}var f=e.prototype;f.init=function(){this.set(),this.original_coords=this.get()},f.set=function(a,b){var c=this.el;c&&!a&&(this.data=c.offset(),this.data.width=c.width(),this.data.height=c.height());if(c&&a&&!b){var d=c.offset();this.data.top=d.top,this.data.left=d.left}var e=this.data;return this.coords.x1=e.left,this.coords.y1=e.top,this.coords.x2=e.left+e.width,this.coords.y2=e.top+e.height,this.coords.cx=e.left+e.width/2,this.coords.cy=e.top+e.height/2,this.coords.width=e.width,this.coords.height=e.height,this.coords.el=c||!1,this},f.update=function(b){if(!b&&!this.el)return this;if(b){var c=a.extend({},this.data,b);return this.data=c,this.set(!0,!0)}return this.set(!0),this},f.get=function(){return this.coords},a.fn.coords=function(){if(this.data("coords"))return this.data("coords");var a=new e(this,arguments[0]);return this.data("coords",a),a}})(jQuery,window,document),function(a,b,c,d){function f(b,c,d){this.options=a.extend(e,d),this.$element=b,this.last_colliders=[],this.last_colliders_coords=[],typeof c=="string"||c instanceof jQuery?this.$colliders=a(c,this.options.colliders_context).not(this.$element):this.colliders=a(c),this.init()}var e={colliders_context:c.body},g=f.prototype;g.init=function(){this.find_collisions()},g.overlaps=function(a,b){var c=!1,d=!1;if(b.x1>=a.x1&&b.x1<=a.x2||b.x2>=a.x1&&b.x2<=a.x2||a.x1>=b.x1&&a.x2<=b.x2)c=!0;if(b.y1>=a.y1&&b.y1<=a.y2||b.y2>=a.y1&&b.y2<=a.y2||a.y1>=b.y1&&a.y2<=b.y2)d=!0;return c&&d},g.detect_overlapping_region=function(a,b){var c="",d="";return a.y1>b.cy&&a.y1b.y1&&a.y2b.cx&&a.x1b.x1&&a.x2this.player_max_left?e=this.player_max_left:e=g&&(b=c+30,b0&&(f.scrollTop(b),this.scrollOffset=this.scrollOffset-30))},j.calculate_positions=function(a){this.window_height=f.height()},j.drag_handler=function(b){var c=b.target.nodeName;if(b.which!==1&&!g)return;if(c==="INPUT"||c==="TEXTAREA"||c==="SELECT"||c==="BUTTON")return;var d=this,e=!0;return this.$player=a(b.currentTarget),this.el_init_pos=this.get_actual_pos(this.$player),this.mouse_init_pos=this.get_mouse_pos(b),this.offsetY=this.mouse_init_pos.top-this.el_init_pos.top,this.$body.on(h.move,function(a){var b=d.get_mouse_pos(a),c=Math.abs(b.left-d.mouse_init_pos.left),f=Math.abs(b.top-d.mouse_init_pos.top);return c>d.options.distance||f>d.options.distance?e?(e=!1,d.on_dragstart.call(d,a),!1):(d.is_dragging==!0&&d.on_dragmove.call(d,a),!1):!1}),!1},j.on_dragstart=function(b){b.preventDefault(),this.drag_start=!0,this.is_dragging=!0;var d=this.$container.offset();return this.baseX=Math.round(d.left),this.baseY=Math.round(d.top),this.doc_height=a(c).height(),this.options.helper==="clone"?(this.$helper=this.$player.clone().appendTo(this.$container).addClass("helper"),this.helper=!0):this.helper=!1,this.scrollOffset=0,this.el_init_offset=this.$player.offset(),this.player_width=this.$player.width(),this.player_height=this.$player.height(),this.player_max_left=this.$container.width()-this.player_width+this.options.offset_left,this.options.start&&this.options.start.call(this.$player,b,{helper:this.helper?this.$helper:this.$player}),!1},j.on_dragmove=function(a){var b=this.get_offset(a);this.options.autoscroll&&this.manage_scroll(b),(this.helper?this.$helper:this.$player).css({position:"absolute",left:b.left,top:b.top});var c={position:{left:b.left,top:b.top}};return this.options.drag&&this.options.drag.call(this.$player,a,c),!1},j.on_dragstop=function(a){var b=this.get_offset(a);this.drag_start=!1;var c={position:{left:b.left,top:b.top}};return this.options.stop&&this.options.stop.call(this.$player,a,c),this.helper&&this.$helper.remove(),!1},j.on_select_start=function(a){return!1},j.enable=function(){this.$container.on("selectstart",this.on_select_start),this.$container.on(h.start,this.options.items,a.proxy(this.drag_handler,this)),this.$body.on(h.end,a.proxy(function(a){this.is_dragging=!1,this.$body.off(h.move),this.drag_start&&this.on_dragstop(a)},this))},j.disable=function(){this.$container.off(h.start),this.$body.off(h.end),this.$container.off("selectstart",this.on_select_start)},j.destroy=function(){this.disable(),a.removeData(this.$container,"drag")},a.fn.drag=function(b){return this.each(function(){a.data(this,"drag")||a.data(this,"drag",new i(this,b))})}}(jQuery,window,document),function(a,b,c,d){function f(b,c){this.options=a.extend(!0,e,c),this.$el=a(b),this.$wrapper=this.$el.parent(),this.$widgets=a(this.options.widget_selector,this.$el).addClass("gs_w"),this.widgets=[],this.$changed=a([]),this.wrapper_width=this.$wrapper.width(),this.min_widget_width=this.options.widget_margins[0]*2+this.options.widget_base_dimensions[0],this.min_widget_height=this.options.widget_margins[1]*2+this.options.widget_base_dimensions[1],this.init()}var e={widget_selector:"> li",widget_margins:[10,10],widget_base_dimensions:[400,225],extra_rows:0,extra_cols:0,min_cols:1,min_rows:15,max_size_x:6,max_size_y:6,autogenerate_stylesheet:!0,avoid_overlapped_widgets:!0,serialize_params:function(a,b){return{col:b.col,row:b.row}},collision:{},draggable:{distance:4}};f.generated_stylesheets=[];var g=f.prototype;g.init=function(){this.generate_grid_and_stylesheet(),this.get_widgets_from_DOM(),this.set_dom_grid_height(),this.$wrapper.addClass("ready"),this.draggable(),a(b).bind("resize",throttle(a.proxy(this.recalculate_faux_grid,this),200))},g.disable=function(){return this.$wrapper.find(".player-revert").removeClass("player-revert"),this.drag_api.disable(),this},g.enable=function(){return this.drag_api.enable(),this},g.add_widget=function(b,c,d){var e=this.next_position(c,d),f=a(b).attr({"data-col":e.col,"data-row":e.row,"data-sizex":e.size_x,"data-sizey":e.size_y}).addClass("gs_w").appendTo(this.$el).hide();return this.$widgets=this.$widgets.add(f),this.register_widget(f),this.set_dom_grid_height(),f.fadeIn()},g.next_position=function(a,b){a||(a=1),b||(b=1);var c=this.gridmap,d=c.length,e=[];for(var f=1;f",{"class":"preview-holder","data-row":this.$player.attr("data-row"),"data-col":this.$player.attr("data-col"),css:{width:e.width,height:e.height}}).appendTo(this.$el),this.options.draggable.start&&this.options.draggable.start.call(this,b,c)},g.on_drag=function(a,b){if(this.$player===null)return!1;var c={left:b.position.left+this.baseX,top:b.position.top+this.baseY};this.colliders_data=this.collision_api.get_closest_colliders(c),this.on_overlapped_column_change(this.on_start_overlapping_column,this.on_stop_overlapping_column),this.on_overlapped_row_change(this.on_start_overlapping_row,this.on_stop_overlapping_row),this.helper&&this.$player&&this.$player.css({left:b.position.left,top:b.position.top}),this.options.draggable.drag&&this.options.draggable.drag.call(this,a,b)},g.on_stop_drag=function(a,b){this.$helper.add(this.$player).add(this.$wrapper).removeClass("dragging"),b.position.left=b.position.left+this.baseX,b.position.top=b.position.top+this.baseY,this.colliders_data=this.collision_api.get_closest_colliders(b.position),this.on_overlapped_column_change(this.on_start_overlapping_column,this.on_stop_overlapping_column),this.on_overlapped_row_change(this.on_start_overlapping_row,this.on_stop_overlapping_row),this.$player.addClass("player-revert").removeClass("player").attr({"data-col":this.placeholder_grid_data.col,"data-row":this.placeholder_grid_data.row}).css({left:"",top:""}),this.$changed=this.$changed.add(this.$player),this.cells_occupied_by_player=this.get_cells_occupied(this.placeholder_grid_data),this.set_cells_player_occupies(this.placeholder_grid_data.col,this.placeholder_grid_data.row),this.$player.coords().grid.row=this.placeholder_grid_data.row,this.$player.coords().grid.col=this.placeholder_grid_data.col,this.options.draggable.stop&&this.options.draggable.stop.call(this,a,b),this.$preview_holder.remove(),this.$player=null,this.set_dom_grid_height()},g.on_overlapped_column_change=function(b,c){if(!this.colliders_data.length)return;var d=this.get_targeted_columns(this.colliders_data[0].el.data.col),e=this.last_cols.length,f=d.length,g;for(g=0;gb.row?1:-1}),a},g.sort_by_row_and_col_asc=function(a){return a=a.sort(function(a,b){return a.row>b.row||a.row==b.row&&a.col>b.col?1:-1}),a},g.sort_by_col_asc=function(a){return a=a.sort(function(a,b){return a.col>b.col?1:-1}),a},g.sort_by_row_desc=function(a){return a=a.sort(function(a,b){return a.row+a.size_y=0&&a.inArray(c,d.rows)>=0},g.is_placeholder_in=function(b,c){var d=this.cells_occupied_by_placeholder||{};return this.is_placeholder_in_col(b)&&a.inArray(c,d.rows)>=0},g.is_placeholder_in_col=function(b){var c=this.cells_occupied_by_placeholder||[];return a.inArray(b,c.cols)>=0},g.is_empty=function(a,b){return typeof this.gridmap[a]!="undefined"&&typeof this.gridmap[a][b]!="undefined"&&this.gridmap[a][b]===!1?!0:!1},g.is_occupied=function(a,b){return this.gridmap[a]?this.gridmap[a][b]?!0:!1:!1},g.is_widget=function(a,b){var c=this.gridmap[a];return c?(c=c[b],c?c:!1):!1},g.is_widget_under_player=function(a,b){return this.is_widget(a,b)?this.is_player_in(a,b):!1},g.get_widgets_under_player=function(){var b=this.cells_occupied_by_player,c=a([]);return a.each(b.cols,a.proxy(function(d,e){a.each(b.rows,a.proxy(function(a,b){this.is_widget(e,b)&&(c=c.add(this.gridmap[e][b]))},this))},this)),c},g.set_placeholder=function(b,c){var d=a.extend({},this.placeholder_grid_data),e=this.widgets_below({col:d.col,row:d.row,size_y:d.size_y,size_x:d.size_x}),f=b+d.size_x-1;f>this.cols&&(b=b-(f-b));var g=this.placeholder_grid_data.row0)if(this.is_empty(a,h)||this.is_player(a,h)||this.is_widget(a,h)&&g[h].is(f))d[a].push(h),e=hthis.player_grid_data.col+this.player_grid_data.size_y-1?!1:(this.for_each_column_occupied(a,function(f){var g=this.gridmap[f];d[f]=[];var h=b+1;while(--h>0){if(this.is_widget(f,h)&&!this.is_player_in(f,h)&&!g[h].is(a.el))break;!this.is_player(f,h)&&!this.is_placeholder_in(f,h)&&!this.is_player_in(f,h)&&d[f].push(h),h=b?a[d[0]]:!1},g.get_widgets_overlapped=function(){var b,c=a([]),d=[],e=this.cells_occupied_by_player.rows.slice(0);return e.reverse(),a.each(this.cells_occupied_by_player.cols,a.proxy(function(b,f){a.each(e,a.proxy(function(b,e){if(!this.gridmap[f])return!0;var g=this.gridmap[f][e];this.is_occupied(f,e)&&!this.is_player(g)&&a.inArray(g,d)===-1&&(c=c.add(g),d.push(g))},this))},this)),c},g.on_start_overlapping_column=function(a){this.set_player(a,!1)},g.on_start_overlapping_row=function(a){this.set_player(!1,a)},g.on_stop_overlapping_column=function(a){this.set_player(a,!1);var b=this;this.for_each_widget_below(a,this.cells_occupied_by_player.rows[0],function(a,c){b.move_widget_up(this,b.player_grid_data.size_y)})},g.on_stop_overlapping_row=function(a){this.set_player(!1,a);var b=this,c=this.cells_occupied_by_player.cols;for(var d=0,e=c.length;d0&&this.move_widget_down(d,f)},this)),h.row=i,this.update_widget_position(h,b),b.attr("data-row",h.row),this.$changed=this.$changed.add(b),f.push(b)}},g.can_go_up_to_row=function(b,c,d){var e=this.gridmap,f=!0,g=[],h=b.row,i;this.for_each_column_occupied(b,function(a){var b=e[a];g[a]=[],i=h;while(i--)if(this.is_empty(a,i)&&!this.is_placeholder_in(a,i))g[a].push(i);else break;if(!g[a].length)return f=!1,!0});if(!f)return!1;i=d;for(i=1;i0?c:0},g.widgets_below=function(b){var c=a.isPlainObject(b)?b:b.coords().grid,d=this,e=this.gridmap,f=c.row+c.size_y-1,g=a([]);return this.for_each_column_occupied(c,function(b){d.for_each_widget_below(b,f,function(b,c){if(!d.is_player(this)&&a.inArray(this,g)===-1)return g=g.add(this),!0})}),this.sort_by_row_asc(g)},g.set_cells_player_occupies=function(a,b){return this.remove_from_gridmap(this.placeholder_grid_data),this.placeholder_grid_data.col=a,this.placeholder_grid_data.row=b,this.add_to_gridmap(this.placeholder_grid_data,this.$player),this},g.empty_cells_player_occupies=function(){return this.remove_from_gridmap(this.placeholder_grid_data),this},g.can_go_up=function(a){var b=a.coords().grid,c=b.row,d=c-1,e=this.gridmap,f=[],g=!0;return c===1?!1:(this.for_each_column_occupied(b,function(a){var b=this.is_widget(a,d);if(this.is_occupied(a,d)||this.is_player(a,d)||this.is_placeholder_in(a,d)||this.is_player_in(a,d))return g=!1,!0}),g)},g.can_move_to=function(a,b,c){var d=this.gridmap,e=a.el,f={size_y:a.size_y,size_x:a.size_x,col:b,row:c},g=!0,h=b+a.size_x-1;return h>this.cols?!1:(this.for_each_cell_occupied(f,function(b,c){var d=this.is_widget(b,c);d&&(!a.el||d.is(e))&&(g=!1)}),g)},g.get_targeted_columns=function(a){var b=(a||this.player_grid_data.col)+(this.player_grid_data.size_x-1),c=[];for(var d=a;d<=b;d++)c.push(d);return c},g.get_targeted_rows=function(a){var b=(a||this.player_grid_data.row)+(this.player_grid_data.size_y-1),c=[];for(var d=a;d<=b;d++)c.push(d);return c},g.get_cells_occupied=function(a){var b={cols:[],rows:[]},c;arguments[1]instanceof jQuery&&(a=arguments[1].coords().grid);for(c=0;c0&&this.is_widget(d,m)&&a.inArray(g[d][m],l)===-1){h=f.call(g[d][m],d,m),l.push(g[d][m]);if(h)break}},"for_each/below":function(){for(m=e+1,i=g[d].length;m=1;e--)for(a=b[e].length-1;a>=1;a--)if(this.is_widget(e,a)){c.push(a),d[a]=e;break}var f=Math.max.apply(Math,c);return this.highest_occupied_cell={col:d[f],row:f},this.highest_occupied_cell},g.get_widgets_from=function(b,c){var d=this.gridmap,e=a();return b&&(e=e.add(this.$widgets.filter(function(){var c=a(this).attr("data-col");return c===b||c>b}))),c&&(e=e.add(this.$widgets.filter(function(){var b=a(this).attr("data-row");return b===c||b>c}))),e},g.set_dom_grid_height=function(){var a=this.get_highest_occupied_cell().row;return this.$el.css("height",a*this.min_widget_height),this},g.generate_stylesheet=function(b){var c="",d=10,e=this.options.max_size_y,g=this.options.max_size_x,h,i;b||(b={}),b.cols||(b.cols=this.cols),b.rows||(b.rows=this.rows),b.namespace||(b.namespace=""),b.widget_base_dimensions||(b.widget_base_dimensions=this.options.widget_base_dimensions),b.widget_margins||(b.widget_margins=this.options.widget_margins),b.min_widget_width=b.widget_margins[0]*2+b.widget_base_dimensions[0],b.min_widget_height=b.widget_margins[1]*2+b.widget_base_dimensions[1];var j=a.param(b);if(a.inArray(j,f.generated_stylesheets)>=0)return!1;f.generated_stylesheets.push(j);for(h=b.cols+d;h>=0;h--)c+=b.namespace+' [data-col="'+(h+1)+'"] { left:'+(h*b.widget_base_dimensions[0]+h*b.widget_margins[0]+(h+1)*b.widget_margins[0])+"px;} ";for(h=b.rows+d;h>=0;h--)c+=b.namespace+' [data-row="'+(h+1)+'"] { top:'+(h*b.widget_base_dimensions[1]+h*b.widget_margins[1]+(h+1)*b.widget_margins[1])+"px;} ";for(var k=1;k<=e;k++)c+=b.namespace+' [data-sizey="'+k+'"] { height:'+(k*b.widget_base_dimensions[1]+(k-1)*b.widget_margins[1]*2)+"px;}";for(var l=1;l<=g;l++)c+=b.namespace+' [data-sizex="'+l+'"] { width:'+(l*b.widget_base_dimensions[0]+(l-1)*b.widget_margins[0]*2)+"px;}";return this.add_style_tag(c)},g.add_style_tag=function(a){var b=c,d=b.createElement("style");return b.getElementsByTagName("head")[0].appendChild(d),d.setAttribute("type","text/css"),d.styleSheet?d.styleSheet.cssText=a:d.appendChild(c.createTextNode(a)),this},g.generate_faux_grid=function(b,c){this.faux_grid=[],this.gridmap=[];var d,e;for(d=c;d>0;d--){this.gridmap[d]=[];for(e=b;e>0;e--){var f=a({left:this.baseX+(d-1)*this.min_widget_width,top:this.baseY+(e-1)*this.min_widget_height,width:this.min_widget_width,height:this.min_widget_height,col:d,row:e,original_col:d,original_row:e}).coords();this.gridmap[d][e]=!1,this.faux_grid.push(f)}}return this},g.recalculate_faux_grid=function(){var c=this.$wrapper.width();return this.baseX=(a(b).width()-c)/2,this.baseY=this.$wrapper.offset().top,a.each(this.faux_grid,a.proxy(function(a,b){this.faux_grid[a]=b.update({left:this.baseX+(b.data.col-1)*this.min_widget_width,top:this.baseY+(b.data.row-1)*this.min_widget_height})},this)),this},g.get_widgets_from_DOM=function(){return this.$widgets.each(a.proxy(function(b,c){this.register_widget(a(c))},this)),this},g.generate_grid_and_stylesheet=function(){var c=this.$wrapper.width(),d=this.$wrapper.height(),e=Math.floor(c/this.min_widget_width)+this.options.extra_cols,f=Math.floor(d/this.min_widget_height)+this.options.extra_rows,g=this.$widgets.map(function(){return a(this).attr("data-col")});g=Array.prototype.slice.call(g,0),g.length||(g=[0]);var h=this.$widgets.map(function(){return a(this).attr("data-row")});h=Array.prototype.slice.call(h,0),h.length||(h=[0]);var i=Math.max.apply(Math,g),j=Math.max.apply(Math,h);return this.cols=Math.max(i,e,this.options.min_cols),this.rows=Math.max(j,f,this.options.min_rows),this.baseX=(a(b).width()-c)/2,this.baseY=this.$wrapper.offset().top,this.options.autogenerate_stylesheet&&this.generate_stylesheet(),this.generate_faux_grid(this.rows,this.cols)},a.fn.gridster=function(b){return this.each(function(){a(this).data("gridster")||a(this).data("gridster",new f(this,b))})}}(jQuery,window,document);
\ No newline at end of file
+/*! gridster.js - v0.5.6 - 2014-09-25 - * http://gridster.net/ - Copyright (c) 2014 ducksboard; Licensed MIT */ (function(t,i){"function"==typeof define&&define.amd?define("gridster-coords",["jquery"],i):t.GridsterCoords=i(t.$||t.jQuery)})(this,function(t){function i(i){return i[0]&&t.isPlainObject(i[0])?this.data=i[0]:this.el=i,this.isCoords=!0,this.coords={},this.init(),this}var e=i.prototype;return e.init=function(){this.set(),this.original_coords=this.get()},e.set=function(t,i){var e=this.el;if(e&&!t&&(this.data=e.offset(),this.data.width=e.width(),this.data.height=e.height()),e&&t&&!i){var s=e.offset();this.data.top=s.top,this.data.left=s.left}var r=this.data;return r.left===void 0&&(r.left=r.x1),r.top===void 0&&(r.top=r.y1),this.coords.x1=r.left,this.coords.y1=r.top,this.coords.x2=r.left+r.width,this.coords.y2=r.top+r.height,this.coords.cx=r.left+r.width/2,this.coords.cy=r.top+r.height/2,this.coords.width=r.width,this.coords.height=r.height,this.coords.el=e||!1,this},e.update=function(i){if(!i&&!this.el)return this;if(i){var e=t.extend({},this.data,i);return this.data=e,this.set(!0,!0)}return this.set(!0),this},e.get=function(){return this.coords},e.destroy=function(){this.el.removeData("coords"),delete this.el},t.fn.coords=function(){if(this.data("coords"))return this.data("coords");var t=new i(this,arguments[0]);return this.data("coords",t),t},i}),function(t,i){"function"==typeof define&&define.amd?define("gridster-collision",["jquery","gridster-coords"],i):t.GridsterCollision=i(t.$||t.jQuery,t.GridsterCoords)}(this,function(t){function i(i,s,r){this.options=t.extend(e,r),this.$element=i,this.last_colliders=[],this.last_colliders_coords=[],this.set_colliders(s),this.init()}var e={colliders_context:document.body,overlapping_region:"C"};i.defaults=e;var s=i.prototype;return s.init=function(){this.find_collisions()},s.overlaps=function(t,i){var e=!1,s=!1;return(i.x1>=t.x1&&i.x1<=t.x2||i.x2>=t.x1&&i.x2<=t.x2||t.x1>=i.x1&&t.x2<=i.x2)&&(e=!0),(i.y1>=t.y1&&i.y1<=t.y2||i.y2>=t.y1&&i.y2<=t.y2||t.y1>=i.y1&&t.y2<=i.y2)&&(s=!0),e&&s},s.detect_overlapping_region=function(t,i){var e="",s="";return t.y1>i.cy&&t.y1i.y1&&t.y2i.cx&&t.x1i.x1&&t.x2o;o++)-1===t.inArray(r[o],i)&&e.call(this,r[o]);for(var n=0,h=i.length;h>n;n++)-1===t.inArray(i[n],r)&&s.call(this,i[n])},s.find_collisions=function(i){for(var e=this,s=this.options.overlapping_region,r=[],o=[],a=this.colliders||this.$colliders,n=a.length,h=e.$element.coords().update(i||!1).get();n--;){var _=e.$colliders?t(a[n]):a[n],d=_.isCoords?_:_.coords(),l=d.get(),c=e.overlaps(h,l);if(c){var p=e.detect_overlapping_region(h,l);if(p===s||"all"===s){var g=e.calculate_overlapped_area_coords(h,l),u=e.calculate_overlapped_area(g),f={area:u,area_coords:g,region:p,coords:l,player_coords:h,el:_};e.options.on_overlap&&e.options.on_overlap.call(this,f),r.push(d),o.push(f)}}}return(e.options.on_overlap_stop||e.options.on_overlap_start)&&this.manage_colliders_start_stop(r,e.options.on_overlap_start,e.options.on_overlap_stop),this.last_colliders_coords=r,o},s.get_closest_colliders=function(t){var i=this.find_collisions(t);return i.sort(function(t,i){return"C"===t.region&&"C"===i.region?t.coords.y1this.player_max_left?o=this.player_max_left:this.player_min_left>o&&(o=this.player_min_left)),{position:{left:o,top:a},pointer:{left:e.left,top:e.top,diff_left:s+(t(window).scrollLeft()-this.win_offset_x),diff_top:r+(t(window).scrollTop()-this.win_offset_y)}}},_.get_drag_data=function(t){var i=this.get_offset(t);return i.$player=this.$player,i.$helper=this.helper?this.$helper:this.$player,i},_.set_limits=function(t){return t||(t=this.$container.width()),this.player_max_left=t-this.player_width+-this.options.offset_left,this.options.container_width=t,this},_.scroll_in=function(i,e){var o,n=r[i],h=50,_=30,d="x"===i,l=d?this.window_width:this.window_height,c=d?t(document).width():t(document).height(),p=d?this.$player.width():this.$player.height(),g=s["scroll"+a(n)](),u=g,f=u+l,w=f-h,m=u+h,y=u+e.pointer[n],v=c-l+p;return y>=w&&(o=g+_,v>o&&(s["scroll"+a(n)](o),this["scroll_offset_"+i]+=_)),m>=y&&(o=g-_,o>0&&(s["scroll"+a(n)](o),this["scroll_offset_"+i]-=_)),this},_.manage_scroll=function(t){this.scroll_in("x",t),this.scroll_in("y",t)},_.calculate_dimensions=function(){this.window_height=s.height(),this.window_width=s.width()},_.drag_handler=function(i){if(i.target.nodeName,!this.disabled&&(1===i.which||o)&&!this.ignore_drag(i)){var e=this,s=!0;return this.$player=t(i.currentTarget),this.el_init_pos=this.get_actual_pos(this.$player),this.mouse_init_pos=this.get_mouse_pos(i),this.offsetY=this.mouse_init_pos.top-this.el_init_pos.top,this.$document.on(this.pointer_events.move,function(t){var i=e.get_mouse_pos(t),r=Math.abs(i.left-e.mouse_init_pos.left),o=Math.abs(i.top-e.mouse_init_pos.top);return r>e.options.distance||o>e.options.distance?s?(s=!1,e.on_dragstart.call(e,t),!1):(e.is_dragging===!0&&e.on_dragmove.call(e,t),!1):!1}),o?void 0:!1}},_.on_dragstart=function(i){if(i.preventDefault(),this.is_dragging)return this;this.drag_start=this.is_dragging=!0;var e=this.$container.offset();return this.baseX=Math.round(e.left),this.baseY=Math.round(e.top),this.initial_container_width=this.options.container_width||this.$container.width(),"clone"===this.options.helper?(this.$helper=this.$player.clone().appendTo(this.$container).addClass("helper"),this.helper=!0):this.helper=!1,this.win_offset_y=t(window).scrollTop(),this.win_offset_x=t(window).scrollLeft(),this.scroll_offset_y=0,this.scroll_offset_x=0,this.el_init_offset=this.$player.offset(),this.player_width=this.$player.width(),this.player_height=this.$player.height(),this.set_limits(this.options.container_width),this.options.start&&this.options.start.call(this.$player,i,this.get_drag_data(i)),!1},_.on_dragmove=function(t){var i=this.get_drag_data(t);this.options.autoscroll&&this.manage_scroll(i),this.options.move_element&&(this.helper?this.$helper:this.$player).css({position:"absolute",left:i.position.left,top:i.position.top});var e=this.last_position||i.position;return i.prev_position=e,this.options.drag&&this.options.drag.call(this.$player,t,i),this.last_position=i.position,!1},_.on_dragstop=function(t){var i=this.get_drag_data(t);return this.drag_start=!1,this.options.stop&&this.options.stop.call(this.$player,t,i),this.helper&&this.options.remove_helper&&this.$helper.remove(),!1},_.on_select_start=function(t){return this.disabled||this.ignore_drag(t)?void 0:!1},_.enable=function(){this.disabled=!1},_.disable=function(){this.disabled=!0},_.destroy=function(){this.disable(),this.$container.off(this.ns),this.$document.off(this.ns),t(window).off(this.ns),t.removeData(this.$container,"drag")},_.ignore_drag=function(i){return this.options.handle?!t(i.target).is(this.options.handle):t.isFunction(this.options.ignore_dragging)?this.options.ignore_dragging(i):t(i.target).is(this.options.ignore_dragging.join(", "))},t.fn.drag=function(t){return new i(this,t)},i}),function(t,i){"function"==typeof define&&define.amd?define(["jquery","gridster-draggable","gridster-collision"],i):t.Gridster=i(t.$||t.jQuery,t.GridsterDraggable,t.GridsterCollision)}(this,function(t,i){function e(i,e){this.options=t.extend(!0,{},s,e),this.$el=t(i),this.$wrapper=this.$el.parent(),this.$widgets=this.$el.children(this.options.widget_selector).addClass("gs-w"),this.widgets=[],this.$changed=t([]),this.wrapper_width=this.$wrapper.width(),this.min_widget_width=2*this.options.widget_margins[0]+this.options.widget_base_dimensions[0],this.min_widget_height=2*this.options.widget_margins[1]+this.options.widget_base_dimensions[1],this.generated_stylesheets=[],this.$style_tags=t([]),this.options.auto_init&&this.init()}var s={namespace:"",widget_selector:"li",widget_margins:[10,10],widget_base_dimensions:[400,225],extra_rows:0,extra_cols:0,min_cols:1,max_cols:1/0,min_rows:15,max_size_x:!1,autogrow_cols:!1,autogenerate_stylesheet:!0,avoid_overlapped_widgets:!0,auto_init:!0,serialize_params:function(t,i){return{col:i.col,row:i.row,size_x:i.size_x,size_y:i.size_y}},collision:{},draggable:{items:".gs-w",distance:4,ignore_dragging:i.defaults.ignore_dragging.slice(0)},resize:{enabled:!1,axes:["both"],handle_append_to:"",handle_class:"gs-resize-handle",max_size:[1/0,1/0],min_size:[1,1]}};e.defaults=s,e.generated_stylesheets=[],e.sort_by_row_asc=function(i){return i=i.sort(function(i,e){return i.row||(i=t(i).coords().grid,e=t(e).coords().grid),i.row>e.row?1:-1})},e.sort_by_row_and_col_asc=function(t){return t=t.sort(function(t,i){return t.row>i.row||t.row===i.row&&t.col>i.col?1:-1})},e.sort_by_col_asc=function(t){return t=t.sort(function(t,i){return t.col>i.col?1:-1})},e.sort_by_row_desc=function(t){return t=t.sort(function(t,i){return t.row+t.size_yn&&this.add_faux_rows(Math.max(e-n,0));var d=o+i-1;d>this.cols&&this.add_faux_cols(d-this.cols);var l={col:_,row:r.row,size_x:i,size_y:e};return this.mutate_widget_in_gridmap(t,r,l),this.set_dom_grid_height(),this.set_dom_grid_width(),s&&s.call(this,l.size_x,l.size_y),t},r.mutate_widget_in_gridmap=function(i,e,s){e.size_x;var r=e.size_y,o=this.get_cells_occupied(e),a=this.get_cells_occupied(s),n=[];t.each(o.cols,function(i,e){-1===t.inArray(e,a.cols)&&n.push(e)});var h=[];t.each(a.cols,function(i,e){-1===t.inArray(e,o.cols)&&h.push(e)});var _=[];t.each(o.rows,function(i,e){-1===t.inArray(e,a.rows)&&_.push(e)});var d=[];if(t.each(a.rows,function(i,e){-1===t.inArray(e,o.rows)&&d.push(e)}),this.remove_from_gridmap(e),h.length){var l=[s.col,s.row,s.size_x,Math.min(r,s.size_y),i];this.empty_cells.apply(this,l)}if(d.length){var c=[s.col,s.row,s.size_x,s.size_y,i];this.empty_cells.apply(this,c)}if(e.col=s.col,e.row=s.row,e.size_x=s.size_x,e.size_y=s.size_y,this.add_to_gridmap(s,i),i.removeClass("player-revert"),i.data("coords").update({width:s.size_x*this.options.widget_base_dimensions[0]+2*(s.size_x-1)*this.options.widget_margins[0],height:s.size_y*this.options.widget_base_dimensions[1]+2*(s.size_y-1)*this.options.widget_margins[1]}),i.attr({"data-col":s.col,"data-row":s.row,"data-sizex":s.size_x,"data-sizey":s.size_y}),n.length){var p=[n[0],s.row,n.length,Math.min(r,s.size_y),i];this.remove_empty_cells.apply(this,p)}if(_.length){var g=[s.col,s.row,s.size_x,s.size_y,i];this.remove_empty_cells.apply(this,g)}return this.move_widget_up(i),this},r.empty_cells=function(i,e,s,r,o){var a=this.widgets_below({col:i,row:e-r,size_x:s,size_y:r});return a.not(o).each(t.proxy(function(i,s){var o=t(s).coords().grid;if(e+r-1>=o.row){var a=e+r-o.row;this.move_widget_down(t(s),a)}},this)),this.set_dom_grid_height(),this},r.remove_empty_cells=function(i,e,s,r,o){var a=this.widgets_below({col:i,row:e,size_x:s,size_y:r});return a.not(o).each(t.proxy(function(i,e){this.move_widget_up(t(e),r)},this)),this.set_dom_grid_height(),this},r.next_position=function(t,i){t||(t=1),i||(i=1);for(var s,r=this.gridmap,o=r.length,a=[],n=1;o>n;n++){s=r[n].length;for(var h=1;s>=h;h++){var _=this.can_move_to({size_x:t,size_y:i},n,h);_&&a.push({col:n,row:h,size_y:i,size_x:t})}}return a.length?e.sort_by_row_and_col_asc(a)[0]:!1},r.remove_widget=function(i,e,s){var r=i instanceof t?i:t(i),o=r.coords().grid;t.isFunction(e)&&(s=e,e=!1),this.cells_occupied_by_placeholder={},this.$widgets=this.$widgets.not(r);var a=this.widgets_below(r);return this.remove_from_gridmap(o),r.fadeOut(t.proxy(function(){r.remove(),e||a.each(t.proxy(function(i,e){this.move_widget_up(t(e),o.size_y)},this)),this.set_dom_grid_height(),s&&s.call(this,i)},this)),this},r.remove_all_widgets=function(i){return this.$widgets.each(t.proxy(function(t,e){this.remove_widget(e,!0,i)},this)),this},r.serialize=function(i){return i||(i=this.$widgets),i.map(t.proxy(function(i,e){var s=t(e);return this.options.serialize_params(s,s.coords().grid)},this)).get()},r.serialize_changed=function(){return this.serialize(this.$changed)},r.dom_to_coords=function(t){return{col:parseInt(t.attr("data-col"),10),row:parseInt(t.attr("data-row"),10),size_x:parseInt(t.attr("data-sizex"),10)||1,size_y:parseInt(t.attr("data-sizey"),10)||1,max_size_x:parseInt(t.attr("data-max-sizex"),10)||!1,max_size_y:parseInt(t.attr("data-max-sizey"),10)||!1,min_size_x:parseInt(t.attr("data-min-sizex"),10)||!1,min_size_y:parseInt(t.attr("data-min-sizey"),10)||!1,el:t}},r.register_widget=function(i){var e=i instanceof jQuery,s=e?this.dom_to_coords(i):i,r=!1;e||(i=s.el);var o=this.can_go_widget_up(s);return o&&(s.row=o,i.attr("data-row",o),this.$el.trigger("gridster:positionchanged",[s]),r=!0),this.options.avoid_overlapped_widgets&&!this.can_move_to({size_x:s.size_x,size_y:s.size_y},s.col,s.row)&&(t.extend(s,this.next_position(s.size_x,s.size_y)),i.attr({"data-col":s.col,"data-row":s.row,"data-sizex":s.size_x,"data-sizey":s.size_y}),r=!0),i.data("coords",i.coords()),i.data("coords").grid=s,this.add_to_gridmap(s,i),this.options.resize.enabled&&this.add_resize_handle(i),r},r.update_widget_position=function(t,i){return this.for_each_cell_occupied(t,function(t,e){return this.gridmap[t]?(this.gridmap[t][e]=i,void 0):this}),this},r.remove_from_gridmap=function(t){return this.update_widget_position(t,!1)},r.add_to_gridmap=function(i,e){if(this.update_widget_position(i,e||i.el),i.el){var s=this.widgets_below(i.el);s.each(t.proxy(function(i,e){this.move_widget_up(t(e))},this))}},r.draggable=function(){var i=this,e=t.extend(!0,{},this.options.draggable,{offset_left:this.options.widget_margins[0],offset_top:this.options.widget_margins[1],container_width:this.cols*this.min_widget_width,limit:!0,start:function(e,s){i.$widgets.filter(".player-revert").removeClass("player-revert"),i.$player=t(this),i.$helper=t(s.$helper),i.helper=!i.$helper.is(i.$player),i.on_start_drag.call(i,e,s),i.$el.trigger("gridster:dragstart")},stop:function(t,e){i.on_stop_drag.call(i,t,e),i.$el.trigger("gridster:dragstop")},drag:throttle(function(t,e){i.on_drag.call(i,t,e),i.$el.trigger("gridster:drag")},60)});return this.drag_api=this.$el.drag(e),this},r.resizable=function(){return this.resize_api=this.$el.drag({items:"."+this.options.resize.handle_class,offset_left:this.options.widget_margins[0],container_width:this.container_width,move_element:!1,resize:!0,limit:this.options.autogrow_cols?!1:!0,start:t.proxy(this.on_start_resize,this),stop:t.proxy(function(i,e){delay(t.proxy(function(){this.on_stop_resize(i,e)},this),120)},this),drag:throttle(t.proxy(this.on_resize,this),60)}),this},r.setup_resize=function(){this.resize_handle_class=this.options.resize.handle_class;var i=this.options.resize.axes,e='';return this.resize_handle_tpl=t.map(i,function(t){return e.replace("{type}",t)}).join(""),t.isArray(this.options.draggable.ignore_dragging)&&this.options.draggable.ignore_dragging.push("."+this.resize_handle_class),this},r.on_start_drag=function(i,e){this.$helper.add(this.$player).add(this.$wrapper).addClass("dragging"),this.highest_col=this.get_highest_occupied_cell().col,this.$player.addClass("player"),this.player_grid_data=this.$player.coords().grid,this.placeholder_grid_data=t.extend({},this.player_grid_data),this.set_dom_grid_height(this.$el.height()+this.player_grid_data.size_y*this.min_widget_height),this.set_dom_grid_width(this.cols);var s=this.player_grid_data.size_x,r=this.cols-this.highest_col;this.options.autogrow_cols&&s>=r&&this.add_faux_cols(Math.min(s-r,1));var o=this.faux_grid,a=this.$player.data("coords").coords;this.cells_occupied_by_player=this.get_cells_occupied(this.player_grid_data),this.cells_occupied_by_placeholder=this.get_cells_occupied(this.placeholder_grid_data),this.last_cols=[],this.last_rows=[],this.collision_api=this.$helper.collision(o,this.options.collision),this.$preview_holder=t("<"+this.$player.get(0).tagName+" />",{"class":"preview-holder","data-row":this.$player.attr("data-row"),"data-col":this.$player.attr("data-col"),css:{width:a.width,height:a.height}}).appendTo(this.$el),this.options.draggable.start&&this.options.draggable.start.call(this,i,e)},r.on_drag=function(t,i){if(null===this.$player)return!1;var e={left:i.position.left+this.baseX,top:i.position.top+this.baseY};if(this.options.autogrow_cols){var s=this.placeholder_grid_data.col+this.placeholder_grid_data.size_x-1;s>=this.cols-1&&this.options.max_cols>=this.cols+1&&(this.add_faux_cols(1),this.set_dom_grid_width(this.cols+1),this.drag_api.set_limits(this.container_width)),this.collision_api.set_colliders(this.faux_grid)}this.colliders_data=this.collision_api.get_closest_colliders(e),this.on_overlapped_column_change(this.on_start_overlapping_column,this.on_stop_overlapping_column),this.on_overlapped_row_change(this.on_start_overlapping_row,this.on_stop_overlapping_row),this.helper&&this.$player&&this.$player.css({left:i.position.left,top:i.position.top}),this.options.draggable.drag&&this.options.draggable.drag.call(this,t,i)},r.on_stop_drag=function(t,i){this.$helper.add(this.$player).add(this.$wrapper).removeClass("dragging"),i.position.left=i.position.left+this.baseX,i.position.top=i.position.top+this.baseY,this.colliders_data=this.collision_api.get_closest_colliders(i.position),this.on_overlapped_column_change(this.on_start_overlapping_column,this.on_stop_overlapping_column),this.on_overlapped_row_change(this.on_start_overlapping_row,this.on_stop_overlapping_row),this.$player.addClass("player-revert").removeClass("player").attr({"data-col":this.placeholder_grid_data.col,"data-row":this.placeholder_grid_data.row}).css({left:"",top:""}),this.$changed=this.$changed.add(this.$player),this.cells_occupied_by_player=this.get_cells_occupied(this.placeholder_grid_data),this.set_cells_player_occupies(this.placeholder_grid_data.col,this.placeholder_grid_data.row),this.$player.coords().grid.row=this.placeholder_grid_data.row,this.$player.coords().grid.col=this.placeholder_grid_data.col,this.options.draggable.stop&&this.options.draggable.stop.call(this,t,i),this.$preview_holder.remove(),this.$player=null,this.$helper=null,this.placeholder_grid_data={},this.player_grid_data={},this.cells_occupied_by_placeholder={},this.cells_occupied_by_player={},this.set_dom_grid_height(),this.set_dom_grid_width(),this.options.autogrow_cols&&this.drag_api.set_limits(this.cols*this.min_widget_width)},r.on_start_resize=function(i,e){this.$resized_widget=e.$player.closest(".gs-w"),this.resize_coords=this.$resized_widget.coords(),this.resize_wgd=this.resize_coords.grid,this.resize_initial_width=this.resize_coords.coords.width,this.resize_initial_height=this.resize_coords.coords.height,this.resize_initial_sizex=this.resize_coords.grid.size_x,this.resize_initial_sizey=this.resize_coords.grid.size_y,this.resize_initial_col=this.resize_coords.grid.col,this.resize_last_sizex=this.resize_initial_sizex,this.resize_last_sizey=this.resize_initial_sizey,this.resize_max_size_x=Math.min(this.resize_wgd.max_size_x||this.options.resize.max_size[0],this.options.max_cols-this.resize_initial_col+1),this.resize_max_size_y=this.resize_wgd.max_size_y||this.options.resize.max_size[1],this.resize_min_size_x=this.resize_wgd.min_size_x||this.options.resize.min_size[0]||1,this.resize_min_size_y=this.resize_wgd.min_size_y||this.options.resize.min_size[1]||1,this.resize_initial_last_col=this.get_highest_occupied_cell().col,this.set_dom_grid_width(this.cols),this.resize_dir={right:e.$player.is("."+this.resize_handle_class+"-x"),bottom:e.$player.is("."+this.resize_handle_class+"-y")},this.$resized_widget.css({"min-width":this.options.widget_base_dimensions[0],"min-height":this.options.widget_base_dimensions[1]});var s=this.$resized_widget.get(0).tagName;this.$resize_preview_holder=t("<"+s+" />",{"class":"preview-holder resize-preview-holder","data-row":this.$resized_widget.attr("data-row"),"data-col":this.$resized_widget.attr("data-col"),css:{width:this.resize_initial_width,height:this.resize_initial_height}}).appendTo(this.$el),this.$resized_widget.addClass("resizing"),this.options.resize.start&&this.options.resize.start.call(this,i,e,this.$resized_widget),this.$el.trigger("gridster:resizestart")},r.on_stop_resize=function(i,e){this.$resized_widget.removeClass("resizing").css({width:"",height:""}),delay(t.proxy(function(){this.$resize_preview_holder.remove().css({"min-width":"","min-height":""}),this.options.resize.stop&&this.options.resize.stop.call(this,i,e,this.$resized_widget),this.$el.trigger("gridster:resizestop")},this),300),this.set_dom_grid_width(),this.options.autogrow_cols&&this.drag_api.set_limits(this.cols*this.min_widget_width)},r.on_resize=function(t,i){var e,s=i.pointer.diff_left,r=i.pointer.diff_top,o=this.options.widget_base_dimensions[0],a=this.options.widget_base_dimensions[1],n=this.options.widget_margins[0],h=this.options.widget_margins[1],_=this.resize_max_size_x,d=this.resize_min_size_x,l=this.resize_max_size_y,c=this.resize_min_size_y,p=this.options.autogrow_cols,g=1/0,u=1/0,f=Math.ceil(s/(o+2*n)-.2),w=Math.ceil(r/(a+2*h)-.2),m=Math.max(1,this.resize_initial_sizex+f),y=Math.max(1,this.resize_initial_sizey+w),v=this.container_width/this.min_widget_width-this.resize_initial_col+1,z=v*this.min_widget_width-2*n;if(m=Math.max(Math.min(m,_),d),m=Math.min(v,m),e=_*o+2*(m-1)*n,g=Math.min(e,z),min_width=d*o+2*(m-1)*n,y=Math.max(Math.min(y,l),c),u=l*a+2*(y-1)*h,min_height=c*a+2*(y-1)*h,this.resize_dir.right?y=this.resize_initial_sizey:this.resize_dir.bottom&&(m=this.resize_initial_sizex),p){var x=this.resize_initial_col+m-1;p&&x>=this.resize_initial_last_col&&(this.set_dom_grid_width(Math.max(x+1,this.cols)),x>this.cols&&this.add_faux_cols(x-this.cols))}var $={};!this.resize_dir.bottom&&($.width=Math.max(Math.min(this.resize_initial_width+s,g),min_width)),!this.resize_dir.right&&($.height=Math.max(Math.min(this.resize_initial_height+r,u),min_height)),this.$resized_widget.css($),(m!==this.resize_last_sizex||y!==this.resize_last_sizey)&&(this.resize_widget(this.$resized_widget,m,y),this.set_dom_grid_width(this.cols),this.$resize_preview_holder.css({width:"",height:""}).attr({"data-row":this.$resized_widget.attr("data-row"),"data-sizex":m,"data-sizey":y})),this.options.resize.resize&&this.options.resize.resize.call(this,t,i,this.$resized_widget),this.$el.trigger("gridster:resize"),this.resize_last_sizex=m,this.resize_last_sizey=y},r.on_overlapped_column_change=function(i,e){if(!this.colliders_data.length)return this;var s,r=this.get_targeted_columns(this.colliders_data[0].el.data.col),o=this.last_cols.length,a=r.length;for(s=0;a>s;s++)-1===t.inArray(r[s],this.last_cols)&&(i||t.noop).call(this,r[s]);for(s=0;o>s;s++)-1===t.inArray(this.last_cols[s],r)&&(e||t.noop).call(this,this.last_cols[s]);return this.last_cols=r,this},r.on_overlapped_row_change=function(i,e){if(!this.colliders_data.length)return this;var s,r=this.get_targeted_rows(this.colliders_data[0].el.data.row),o=this.last_rows.length,a=r.length;for(s=0;a>s;s++)-1===t.inArray(r[s],this.last_rows)&&(i||t.noop).call(this,r[s]);for(s=0;o>s;s++)-1===t.inArray(this.last_rows[s],r)&&(e||t.noop).call(this,this.last_rows[s]);this.last_rows=r},r.set_player=function(t,i,e){var s=this;e||this.empty_cells_player_occupies();var r=e?{col:t}:s.colliders_data[0].el.data,o=r.col,a=i||r.row;this.player_grid_data={col:o,row:a,size_y:this.player_grid_data.size_y,size_x:this.player_grid_data.size_x},this.cells_occupied_by_player=this.get_cells_occupied(this.player_grid_data);var n=this.get_widgets_overlapped(this.player_grid_data),h=this.widgets_constraints(n);if(this.manage_movements(h.can_go_up,o,a),this.manage_movements(h.can_not_go_up,o,a),!n.length){var _=this.can_go_player_up(this.player_grid_data);_!==!1&&(a=_),this.set_placeholder(o,a)}return{col:o,row:a}},r.widgets_constraints=function(i){var s,r=t([]),o=[],a=[];return i.each(t.proxy(function(i,e){var s=t(e),n=s.coords().grid;this.can_go_widget_up(n)?(r=r.add(s),o.push(n)):a.push(n)},this)),s=i.not(r),{can_go_up:e.sort_by_row_asc(o),can_not_go_up:e.sort_by_row_desc(a)}},r.manage_movements=function(i,e,s){return t.each(i,t.proxy(function(t,i){var r=i,o=r.el,a=this.can_go_widget_up(r);if(a)this.move_widget_to(o,a),this.set_placeholder(e,a+r.size_y);else{var n=this.can_go_player_up(this.player_grid_data);if(!n){var h=s+this.player_grid_data.size_y-r.row;this.move_widget_down(o,h),this.set_placeholder(e,s)}}},this)),this},r.is_player=function(t,i){if(i&&!this.gridmap[t])return!1;var e=i?this.gridmap[t][i]:t;return e&&(e.is(this.$player)||e.is(this.$helper))},r.is_player_in=function(i,e){var s=this.cells_occupied_by_player||{};return t.inArray(i,s.cols)>=0&&t.inArray(e,s.rows)>=0},r.is_placeholder_in=function(i,e){var s=this.cells_occupied_by_placeholder||{};return this.is_placeholder_in_col(i)&&t.inArray(e,s.rows)>=0},r.is_placeholder_in_col=function(i){var e=this.cells_occupied_by_placeholder||[];return t.inArray(i,e.cols)>=0},r.is_empty=function(t,i){return this.gridmap[t]!==void 0?this.gridmap[t][i]!==void 0&&this.gridmap[t][i]===!1?!0:!1:!0},r.is_occupied=function(t,i){return this.gridmap[t]?this.gridmap[t][i]?!0:!1:!1},r.is_widget=function(t,i){var e=this.gridmap[t];return e?(e=e[i],e?e:!1):!1},r.is_widget_under_player=function(t,i){return this.is_widget(t,i)?this.is_player_in(t,i):!1},r.get_widgets_under_player=function(i){i||(i=this.cells_occupied_by_player||{cols:[],rows:[]});var e=t([]);return t.each(i.cols,t.proxy(function(s,r){t.each(i.rows,t.proxy(function(t,i){this.is_widget(r,i)&&(e=e.add(this.gridmap[r][i]))},this))},this)),e},r.set_placeholder=function(i,e){var s=t.extend({},this.placeholder_grid_data),r=this.widgets_below({col:s.col,row:s.row,size_y:s.size_y,size_x:s.size_x}),o=i+s.size_x-1;o>this.cols&&(i-=o-i);var a=e>this.placeholder_grid_data.row,n=this.placeholder_grid_data.col!==i;this.placeholder_grid_data.col=i,this.placeholder_grid_data.row=e,this.cells_occupied_by_placeholder=this.get_cells_occupied(this.placeholder_grid_data),this.$preview_holder.attr({"data-row":e,"data-col":i}),(a||n)&&r.each(t.proxy(function(e,r){this.move_widget_up(t(r),this.placeholder_grid_data.col-i+s.size_y)},this));var h=this.get_widgets_under_player(this.cells_occupied_by_placeholder);h.length&&h.each(t.proxy(function(i,r){var o=t(r);this.move_widget_down(o,e+s.size_y-o.data("coords").grid.row)},this))},r.can_go_player_up=function(t){var i=t.row+t.size_y-1,e=!0,s=[],r=1e4,o=this.get_widgets_under_player();return this.for_each_column_occupied(t,function(t){var a=this.gridmap[t],n=i+1;for(s[t]=[];--n>0&&(this.is_empty(t,n)||this.is_player(t,n)||this.is_widget(t,n)&&a[n].is(o));)s[t].push(n),r=r>n?n:r;return 0===s[t].length?(e=!1,!0):(s[t].sort(function(t,i){return t-i
+}),void 0)}),e?this.get_valid_rows(t,s,r):!1},r.can_go_widget_up=function(t){var i=t.row+t.size_y-1,e=!0,s=[],r=1e4;return this.for_each_column_occupied(t,function(o){var a=this.gridmap[o];s[o]=[];for(var n=i+1;--n>0&&(!this.is_widget(o,n)||this.is_player_in(o,n)||a[n].is(t.el));)this.is_player(o,n)||this.is_placeholder_in(o,n)||this.is_player_in(o,n)||s[o].push(n),r>n&&(r=n);return 0===s[o].length?(e=!1,!0):(s[o].sort(function(t,i){return t-i}),void 0)}),e?this.get_valid_rows(t,s,r):!1},r.get_valid_rows=function(i,e,s){for(var r=i.row,o=i.row+i.size_y-1,a=i.size_y,n=s-1,h=[];o>=++n;){var _=!0;if(t.each(e,function(i,e){t.isArray(e)&&-1===t.inArray(n,e)&&(_=!1)}),_===!0&&(h.push(n),h.length===a))break}var d=!1;return 1===a?h[0]!==r&&(d=h[0]||!1):h[0]!==r&&(d=this.get_consecutive_numbers_index(h,a)),d},r.get_consecutive_numbers_index=function(t,i){for(var e=t.length,s=[],r=!0,o=-1,a=0;e>a;a++){if(r||t[a]===o+1){if(s.push(a),s.length===i)break;r=!1}else s=[],r=!0;o=t[a]}return s.length>=i?t[s[0]]:!1},r.get_widgets_overlapped=function(){var i=t([]),e=[],s=this.cells_occupied_by_player.rows.slice(0);return s.reverse(),t.each(this.cells_occupied_by_player.cols,t.proxy(function(r,o){t.each(s,t.proxy(function(s,r){if(!this.gridmap[o])return!0;var a=this.gridmap[o][r];this.is_occupied(o,r)&&!this.is_player(a)&&-1===t.inArray(a,e)&&(i=i.add(a),e.push(a))},this))},this)),i},r.on_start_overlapping_column=function(t){this.set_player(t,!1)},r.on_start_overlapping_row=function(t){this.set_player(!1,t)},r.on_stop_overlapping_column=function(t){this.set_player(t,!1);var i=this;this.for_each_widget_below(t,this.cells_occupied_by_player.rows[0],function(){i.move_widget_up(this,i.player_grid_data.size_y)})},r.on_stop_overlapping_row=function(t){this.set_player(!1,t);for(var i=this,e=this.cells_occupied_by_player.cols,s=0,r=e.length;r>s;s++)this.for_each_widget_below(e[s],t,function(){i.move_widget_up(this,i.player_grid_data.size_y)})},r.move_widget_to=function(i,e){var s=this,r=i.coords().grid;e-r.row;var o=this.widgets_below(i),a=this.can_move_to(r,r.col,e,i);return a===!1?!1:(this.remove_from_gridmap(r),r.row=e,this.add_to_gridmap(r),i.attr("data-row",e),this.$changed=this.$changed.add(i),o.each(function(i,e){var r=t(e),o=r.coords().grid,a=s.can_go_widget_up(o);a&&a!==o.row&&s.move_widget_to(r,a)}),this)},r.move_widget_up=function(i,e){var s=i.coords().grid,r=s.row,o=[];return e||(e=1),this.can_go_up(i)?(this.for_each_column_occupied(s,function(s){if(-1===t.inArray(i,o)){var a=i.coords().grid,n=r-e;if(n=this.can_go_up_to_row(a,s,n),!n)return!0;var h=this.widgets_below(i);this.remove_from_gridmap(a),a.row=n,this.add_to_gridmap(a),i.attr("data-row",a.row),this.$changed=this.$changed.add(i),o.push(i),h.each(t.proxy(function(i,s){this.move_widget_up(t(s),e)},this))}}),void 0):!1},r.move_widget_down=function(i,e){var s,r,o,a;if(0>=e)return!1;if(s=i.coords().grid,r=s.row,o=[],a=e,!i)return!1;if(-1===t.inArray(i,o)){var n=i.coords().grid,h=r+e,_=this.widgets_below(i);this.remove_from_gridmap(n),_.each(t.proxy(function(i,e){var s=t(e),r=s.coords().grid,o=this.displacement_diff(r,n,a);o>0&&this.move_widget_down(s,o)},this)),n.row=h,this.update_widget_position(n,i),i.attr("data-row",n.row),this.$changed=this.$changed.add(i),o.push(i)}},r.can_go_up_to_row=function(i,e,s){var r,o=this.gridmap,a=!0,n=[],h=i.row;if(this.for_each_column_occupied(i,function(t){for(o[t],n[t]=[],r=h;r--&&this.is_empty(t,r)&&!this.is_placeholder_in(t,r);)n[t].push(r);return n[t].length?void 0:(a=!1,!0)}),!a)return!1;for(r=s,r=1;h>r;r++){for(var _=!0,d=0,l=n.length;l>d;d++)n[d]&&-1===t.inArray(r,n[d])&&(_=!1);if(_===!0){a=r;break}}return a},r.displacement_diff=function(t,i,e){var s=t.row,r=[],o=i.row+i.size_y;this.for_each_column_occupied(t,function(t){for(var i=0,e=o;s>e;e++)this.is_empty(t,e)&&(i+=1);r.push(i)});var a=Math.max.apply(Math,r);return e-=a,e>0?e:0},r.widgets_below=function(i){var s=t.isPlainObject(i)?i:i.coords().grid,r=this;this.gridmap;var o=s.row+s.size_y-1,a=t([]);return this.for_each_column_occupied(s,function(i){r.for_each_widget_below(i,o,function(){return r.is_player(this)||-1!==t.inArray(this,a)?void 0:(a=a.add(this),!0)})}),e.sort_by_row_asc(a)},r.set_cells_player_occupies=function(t,i){return this.remove_from_gridmap(this.placeholder_grid_data),this.placeholder_grid_data.col=t,this.placeholder_grid_data.row=i,this.add_to_gridmap(this.placeholder_grid_data,this.$player),this},r.empty_cells_player_occupies=function(){return this.remove_from_gridmap(this.placeholder_grid_data),this},r.can_go_up=function(t){var i=t.coords().grid,e=i.row,s=e-1;this.gridmap;var r=!0;return 1===e?!1:(this.for_each_column_occupied(i,function(t){return this.is_widget(t,s),this.is_occupied(t,s)||this.is_player(t,s)||this.is_placeholder_in(t,s)||this.is_player_in(t,s)?(r=!1,!0):void 0}),r)},r.can_move_to=function(t,i,e,s){this.gridmap;var r=t.el,o={size_y:t.size_y,size_x:t.size_x,col:i,row:e},a=!0,n=i+t.size_x-1;return n>this.cols?!1:s&&e+t.size_y-1>s?!1:(this.for_each_cell_occupied(o,function(i,e){var s=this.is_widget(i,e);!s||t.el&&!s.is(r)||(a=!1)}),a)},r.get_targeted_columns=function(t){for(var i=(t||this.player_grid_data.col)+(this.player_grid_data.size_x-1),e=[],s=t;i>=s;s++)e.push(s);return e},r.get_targeted_rows=function(t){for(var i=(t||this.player_grid_data.row)+(this.player_grid_data.size_y-1),e=[],s=t;i>=s;s++)e.push(s);return e},r.get_cells_occupied=function(i){var e,s={cols:[],rows:[]};for(arguments[1]instanceof t&&(i=arguments[1].coords().grid),e=0;i.size_x>e;e++){var r=i.col+e;s.cols.push(r)}for(e=0;i.size_y>e;e++){var o=i.row+e;s.rows.push(o)}return s},r.for_each_cell_occupied=function(t,i){return this.for_each_column_occupied(t,function(e){this.for_each_row_occupied(t,function(t){i.call(this,e,t)})}),this},r.for_each_column_occupied=function(t,i){for(var e=0;t.size_x>e;e++){var s=t.col+e;i.call(this,s,t)}},r.for_each_row_occupied=function(t,i){for(var e=0;t.size_y>e;e++){var s=t.row+e;i.call(this,s,t)}},r._traversing_widgets=function(i,e,s,r,o){var a=this.gridmap;if(a[s]){var n,h,_=i+"/"+e;if(arguments[2]instanceof t){var d=arguments[2].coords().grid;s=d.col,r=d.row,o=arguments[3]}var l=[],c=r,p={"for_each/above":function(){for(;c--&&!(c>0&&this.is_widget(s,c)&&-1===t.inArray(a[s][c],l)&&(n=o.call(a[s][c],s,c),l.push(a[s][c]),n)););},"for_each/below":function(){for(c=r+1,h=a[s].length;h>c&&(!this.is_widget(s,c)||-1!==t.inArray(a[s][c],l)||(n=o.call(a[s][c],s,c),l.push(a[s][c]),!n));c++);}};p[_]&&p[_].call(this)}},r.for_each_widget_above=function(t,i,e){return this._traversing_widgets("for_each","above",t,i,e),this},r.for_each_widget_below=function(t,i,e){return this._traversing_widgets("for_each","below",t,i,e),this},r.get_highest_occupied_cell=function(){for(var t,i=this.gridmap,e=i[1].length,s=[],r=[],o=i.length-1;o>=1;o--)for(t=e-1;t>=1;t--)if(this.is_widget(o,t)){s.push(t),r.push(o);break}return{col:Math.max.apply(Math,r),row:Math.max.apply(Math,s)}},r.get_widgets_from=function(i,e){this.gridmap;var s=t();return i&&(s=s.add(this.$widgets.filter(function(){var e=t(this).attr("data-col");return e===i||e>i}))),e&&(s=s.add(this.$widgets.filter(function(){var i=t(this).attr("data-row");return i===e||i>e}))),s},r.set_dom_grid_height=function(t){if(t===void 0){var i=this.get_highest_occupied_cell().row;t=i*this.min_widget_height}return this.container_height=t,this.$el.css("height",this.container_height),this},r.set_dom_grid_width=function(t){t===void 0&&(t=this.get_highest_occupied_cell().col);var i=this.options.autogrow_cols?this.options.max_cols:this.cols;return t=Math.min(i,Math.max(t,this.options.min_cols)),this.container_width=t*this.min_widget_width,this.$el.css("width",this.container_width),this},r.generate_stylesheet=function(i){var s,r="",o=this.options.max_size_x||this.cols;i||(i={}),i.cols||(i.cols=this.cols),i.rows||(i.rows=this.rows),i.namespace||(i.namespace=this.options.namespace),i.widget_base_dimensions||(i.widget_base_dimensions=this.options.widget_base_dimensions),i.widget_margins||(i.widget_margins=this.options.widget_margins),i.min_widget_width=2*i.widget_margins[0]+i.widget_base_dimensions[0],i.min_widget_height=2*i.widget_margins[1]+i.widget_base_dimensions[1];var a=t.param(i);if(t.inArray(a,e.generated_stylesheets)>=0)return!1;for(this.generated_stylesheets.push(a),e.generated_stylesheets.push(a),s=i.cols;s>=0;s--)r+=i.namespace+' [data-col="'+(s+1)+'"] { left:'+(s*i.widget_base_dimensions[0]+s*i.widget_margins[0]+(s+1)*i.widget_margins[0])+"px; }\n";for(s=i.rows;s>=0;s--)r+=i.namespace+' [data-row="'+(s+1)+'"] { top:'+(s*i.widget_base_dimensions[1]+s*i.widget_margins[1]+(s+1)*i.widget_margins[1])+"px; }\n";for(var n=1;i.rows>=n;n++)r+=i.namespace+' [data-sizey="'+n+'"] { height:'+(n*i.widget_base_dimensions[1]+(n-1)*2*i.widget_margins[1])+"px; }\n";for(var h=1;o>=h;h++)r+=i.namespace+' [data-sizex="'+h+'"] { width:'+(h*i.widget_base_dimensions[0]+(h-1)*2*i.widget_margins[0])+"px; }\n";return this.remove_style_tags(),this.add_style_tag(r)},r.add_style_tag=function(t){var i=document,e=i.createElement("style");return i.getElementsByTagName("head")[0].appendChild(e),e.setAttribute("type","text/css"),e.styleSheet?e.styleSheet.cssText=t:e.appendChild(document.createTextNode(t)),this.$style_tags=this.$style_tags.add(e),this},r.remove_style_tags=function(){var i=e.generated_stylesheets,s=this.generated_stylesheets;this.$style_tags.remove(),e.generated_stylesheets=t.map(i,function(i){return-1===t.inArray(i,s)?i:void 0})},r.generate_faux_grid=function(t,i){this.faux_grid=[],this.gridmap=[];var e,s;for(e=i;e>0;e--)for(this.gridmap[e]=[],s=t;s>0;s--)this.add_faux_cell(s,e);return this},r.add_faux_cell=function(i,e){var s=t({left:this.baseX+(e-1)*this.min_widget_width,top:this.baseY+(i-1)*this.min_widget_height,width:this.min_widget_width,height:this.min_widget_height,col:e,row:i,original_col:e,original_row:i}).coords();return t.isArray(this.gridmap[e])||(this.gridmap[e]=[]),this.gridmap[e][i]=!1,this.faux_grid.push(s),this},r.add_faux_rows=function(t){for(var i=this.rows,e=i+(t||1),s=e;s>i;s--)for(var r=this.cols;r>=1;r--)this.add_faux_cell(s,r);return this.rows=e,this.options.autogenerate_stylesheet&&this.generate_stylesheet(),this},r.add_faux_cols=function(t){var i=this.cols,e=i+(t||1);e=Math.min(e,this.options.max_cols);for(var s=i+1;e>=s;s++)for(var r=this.rows;r>=1;r--)this.add_faux_cell(r,s);return this.cols=e,this.options.autogenerate_stylesheet&&this.generate_stylesheet(),this},r.recalculate_faux_grid=function(){var i=this.$wrapper.width();return this.baseX=(t(window).width()-i)/2,this.baseY=this.$wrapper.offset().top,t.each(this.faux_grid,t.proxy(function(t,i){this.faux_grid[t]=i.update({left:this.baseX+(i.data.col-1)*this.min_widget_width,top:this.baseY+(i.data.row-1)*this.min_widget_height})},this)),this},r.get_widgets_from_DOM=function(){var i=this.$widgets.map(t.proxy(function(i,e){var s=t(e);return this.dom_to_coords(s)},this));i=e.sort_by_row_and_col_asc(i);var s=t(i).map(t.proxy(function(t,i){return this.register_widget(i)||null},this));return s.length&&this.$el.trigger("gridster:positionschanged"),this},r.generate_grid_and_stylesheet=function(){var i=this.$wrapper.width(),e=this.options.max_cols,s=Math.floor(i/this.min_widget_width)+this.options.extra_cols,r=this.$widgets.map(function(){return t(this).attr("data-col")}).get();r.length||(r=[0]);var o=Math.max.apply(Math,r);this.cols=Math.max(o,s,this.options.min_cols),1/0!==e&&e>=o&&this.cols>e&&(this.cols=e);var a=this.options.extra_rows;return this.$widgets.each(function(i,e){a+=+t(e).attr("data-sizey")}),this.rows=Math.max(a,this.options.min_rows),this.baseX=(t(window).width()-i)/2,this.baseY=this.$wrapper.offset().top,this.options.autogenerate_stylesheet&&this.generate_stylesheet(),this.generate_faux_grid(this.rows,this.cols)},r.destroy=function(i){return this.$el.removeData("gridster"),t(window).unbind(".gridster"),this.drag_api&&this.drag_api.destroy(),this.remove_style_tags(),i&&this.$el.remove(),this},t.fn.gridster=function(i){return this.each(function(){t(this).data("gridster")||t(this).data("gridster",new e(this,i))})},e});
\ No newline at end of file
diff --git a/dist/jquery.gridster.with-extras.js b/dist/jquery.gridster.with-extras.js
new file mode 100644
index 00000000..d8e8e1f7
--- /dev/null
+++ b/dist/jquery.gridster.with-extras.js
@@ -0,0 +1,4163 @@
+/*! gridster.js - v0.5.6 - 2014-09-25
+* http://gridster.net/
+* Copyright (c) 2014 ducksboard; Licensed MIT */
+
+;(function(root, factory) {
+
+ if (typeof define === 'function' && define.amd) {
+ define('gridster-coords', ['jquery'], factory);
+ } else {
+ root.GridsterCoords = factory(root.$ || root.jQuery);
+ }
+
+}(this, function($) {
+ /**
+ * Creates objects with coordinates (x1, y1, x2, y2, cx, cy, width, height)
+ * to simulate DOM elements on the screen.
+ * Coords is used by Gridster to create a faux grid with any DOM element can
+ * collide.
+ *
+ * @class Coords
+ * @param {HTMLElement|Object} obj The jQuery HTMLElement or a object with: left,
+ * top, width and height properties.
+ * @return {Object} Coords instance.
+ * @constructor
+ */
+ function Coords(obj) {
+ if (obj[0] && $.isPlainObject(obj[0])) {
+ this.data = obj[0];
+ }else {
+ this.el = obj;
+ }
+
+ this.isCoords = true;
+ this.coords = {};
+ this.init();
+ return this;
+ }
+
+
+ var fn = Coords.prototype;
+
+
+ fn.init = function(){
+ this.set();
+ this.original_coords = this.get();
+ };
+
+
+ fn.set = function(update, not_update_offsets) {
+ var el = this.el;
+
+ if (el && !update) {
+ this.data = el.offset();
+ this.data.width = el.width();
+ this.data.height = el.height();
+ }
+
+ if (el && update && !not_update_offsets) {
+ var offset = el.offset();
+ this.data.top = offset.top;
+ this.data.left = offset.left;
+ }
+
+ var d = this.data;
+
+ typeof d.left === 'undefined' && (d.left = d.x1);
+ typeof d.top === 'undefined' && (d.top = d.y1);
+
+ this.coords.x1 = d.left;
+ this.coords.y1 = d.top;
+ this.coords.x2 = d.left + d.width;
+ this.coords.y2 = d.top + d.height;
+ this.coords.cx = d.left + (d.width / 2);
+ this.coords.cy = d.top + (d.height / 2);
+ this.coords.width = d.width;
+ this.coords.height = d.height;
+ this.coords.el = el || false ;
+
+ return this;
+ };
+
+
+ fn.update = function(data){
+ if (!data && !this.el) {
+ return this;
+ }
+
+ if (data) {
+ var new_data = $.extend({}, this.data, data);
+ this.data = new_data;
+ return this.set(true, true);
+ }
+
+ this.set(true);
+ return this;
+ };
+
+
+ fn.get = function(){
+ return this.coords;
+ };
+
+ fn.destroy = function() {
+ this.el.removeData('coords');
+ delete this.el;
+ };
+
+ //jQuery adapter
+ $.fn.coords = function() {
+ if (this.data('coords') ) {
+ return this.data('coords');
+ }
+
+ var ins = new Coords(this, arguments[0]);
+ this.data('coords', ins);
+ return ins;
+ };
+
+ return Coords;
+
+}));
+
+;(function(root, factory) {
+
+ if (typeof define === 'function' && define.amd) {
+ define('gridster-collision', ['jquery', 'gridster-coords'], factory);
+ } else {
+ root.GridsterCollision = factory(root.$ || root.jQuery,
+ root.GridsterCoords);
+ }
+
+}(this, function($, Coords) {
+
+ var defaults = {
+ colliders_context: document.body,
+ overlapping_region: 'C'
+ // ,on_overlap: function(collider_data){},
+ // on_overlap_start : function(collider_data){},
+ // on_overlap_stop : function(collider_data){}
+ };
+
+
+ /**
+ * Detects collisions between a DOM element against other DOM elements or
+ * Coords objects.
+ *
+ * @class Collision
+ * @uses Coords
+ * @param {HTMLElement} el The jQuery wrapped HTMLElement.
+ * @param {HTMLElement|Array} colliders Can be a jQuery collection
+ * of HTMLElements or an Array of Coords instances.
+ * @param {Object} [options] An Object with all options you want to
+ * overwrite:
+ * @param {String} [options.overlapping_region] Determines when collision
+ * is valid, depending on the overlapped area. Values can be: 'N', 'S',
+ * 'W', 'E', 'C' or 'all'. Default is 'C'.
+ * @param {Function} [options.on_overlap_start] Executes a function the first
+ * time each `collider ` is overlapped.
+ * @param {Function} [options.on_overlap_stop] Executes a function when a
+ * `collider` is no longer collided.
+ * @param {Function} [options.on_overlap] Executes a function when the
+ * mouse is moved during the collision.
+ * @return {Object} Collision instance.
+ * @constructor
+ */
+ function Collision(el, colliders, options) {
+ this.options = $.extend(defaults, options);
+ this.$element = el;
+ this.last_colliders = [];
+ this.last_colliders_coords = [];
+ this.set_colliders(colliders);
+
+ this.init();
+ }
+
+ Collision.defaults = defaults;
+
+ var fn = Collision.prototype;
+
+
+ fn.init = function() {
+ this.find_collisions();
+ };
+
+
+ fn.overlaps = function(a, b) {
+ var x = false;
+ var y = false;
+
+ if ((b.x1 >= a.x1 && b.x1 <= a.x2) ||
+ (b.x2 >= a.x1 && b.x2 <= a.x2) ||
+ (a.x1 >= b.x1 && a.x2 <= b.x2)
+ ) { x = true; }
+
+ if ((b.y1 >= a.y1 && b.y1 <= a.y2) ||
+ (b.y2 >= a.y1 && b.y2 <= a.y2) ||
+ (a.y1 >= b.y1 && a.y2 <= b.y2)
+ ) { y = true; }
+
+ return (x && y);
+ };
+
+
+ fn.detect_overlapping_region = function(a, b){
+ var regionX = '';
+ var regionY = '';
+
+ if (a.y1 > b.cy && a.y1 < b.y2) { regionX = 'N'; }
+ if (a.y2 > b.y1 && a.y2 < b.cy) { regionX = 'S'; }
+ if (a.x1 > b.cx && a.x1 < b.x2) { regionY = 'W'; }
+ if (a.x2 > b.x1 && a.x2 < b.cx) { regionY = 'E'; }
+
+ return (regionX + regionY) || 'C';
+ };
+
+
+ fn.calculate_overlapped_area_coords = function(a, b){
+ var x1 = Math.max(a.x1, b.x1);
+ var y1 = Math.max(a.y1, b.y1);
+ var x2 = Math.min(a.x2, b.x2);
+ var y2 = Math.min(a.y2, b.y2);
+
+ return $({
+ left: x1,
+ top: y1,
+ width : (x2 - x1),
+ height: (y2 - y1)
+ }).coords().get();
+ };
+
+
+ fn.calculate_overlapped_area = function(coords){
+ return (coords.width * coords.height);
+ };
+
+
+ fn.manage_colliders_start_stop = function(new_colliders_coords, start_callback, stop_callback){
+ var last = this.last_colliders_coords;
+
+ for (var i = 0, il = last.length; i < il; i++) {
+ if ($.inArray(last[i], new_colliders_coords) === -1) {
+ start_callback.call(this, last[i]);
+ }
+ }
+
+ for (var j = 0, jl = new_colliders_coords.length; j < jl; j++) {
+ if ($.inArray(new_colliders_coords[j], last) === -1) {
+ stop_callback.call(this, new_colliders_coords[j]);
+ }
+
+ }
+ };
+
+
+ fn.find_collisions = function(player_data_coords){
+ var self = this;
+ var overlapping_region = this.options.overlapping_region;
+ var colliders_coords = [];
+ var colliders_data = [];
+ var $colliders = (this.colliders || this.$colliders);
+ var count = $colliders.length;
+ var player_coords = self.$element.coords()
+ .update(player_data_coords || false).get();
+
+ while(count--){
+ var $collider = self.$colliders ?
+ $($colliders[count]) : $colliders[count];
+ var $collider_coords_ins = ($collider.isCoords) ?
+ $collider : $collider.coords();
+ var collider_coords = $collider_coords_ins.get();
+ var overlaps = self.overlaps(player_coords, collider_coords);
+
+ if (!overlaps) {
+ continue;
+ }
+
+ var region = self.detect_overlapping_region(
+ player_coords, collider_coords);
+
+ //todo: make this an option
+ if (region === overlapping_region || overlapping_region === 'all') {
+
+ var area_coords = self.calculate_overlapped_area_coords(
+ player_coords, collider_coords);
+ var area = self.calculate_overlapped_area(area_coords);
+ var collider_data = {
+ area: area,
+ area_coords : area_coords,
+ region: region,
+ coords: collider_coords,
+ player_coords: player_coords,
+ el: $collider
+ };
+
+ if (self.options.on_overlap) {
+ self.options.on_overlap.call(this, collider_data);
+ }
+ colliders_coords.push($collider_coords_ins);
+ colliders_data.push(collider_data);
+ }
+ }
+
+ if (self.options.on_overlap_stop || self.options.on_overlap_start) {
+ this.manage_colliders_start_stop(colliders_coords,
+ self.options.on_overlap_start, self.options.on_overlap_stop);
+ }
+
+ this.last_colliders_coords = colliders_coords;
+
+ return colliders_data;
+ };
+
+
+ fn.get_closest_colliders = function(player_data_coords){
+ var colliders = this.find_collisions(player_data_coords);
+
+ colliders.sort(function(a, b) {
+ /* if colliders are being overlapped by the "C" (center) region,
+ * we have to set a lower index in the array to which they are placed
+ * above in the grid. */
+ if (a.region === 'C' && b.region === 'C') {
+ if (a.coords.y1 < b.coords.y1 || a.coords.x1 < b.coords.x1) {
+ return - 1;
+ }else{
+ return 1;
+ }
+ }
+
+ if (a.area < b.area) {
+ return 1;
+ }
+
+ return 1;
+ });
+ return colliders;
+ };
+
+
+ fn.set_colliders = function(colliders) {
+ if (typeof colliders === 'string' || colliders instanceof $) {
+ this.$colliders = $(colliders,
+ this.options.colliders_context).not(this.$element);
+ }else{
+ this.colliders = $(colliders);
+ }
+ };
+
+
+ //jQuery adapter
+ $.fn.collision = function(collider, options) {
+ return new Collision( this, collider, options );
+ };
+
+ return Collision;
+
+}));
+
+;(function(window, undefined) {
+
+ /* Delay, debounce and throttle functions taken from underscore.js
+ *
+ * Copyright (c) 2009-2013 Jeremy Ashkenas, DocumentCloud and
+ * Investigative Reporters & Editors
+ *
+ * Permission is hereby granted, free of charge, to any person
+ * obtaining a copy of this software and associated documentation
+ * files (the "Software"), to deal in the Software without
+ * restriction, including without limitation the rights to use,
+ * copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following
+ * conditions:
+ *
+ * The above copyright notice and this permission notice shall be
+ * included in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
+ * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+ * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
+ * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+ * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+ * OTHER DEALINGS IN THE SOFTWARE.
+ */
+
+ window.delay = function(func, wait) {
+ var args = Array.prototype.slice.call(arguments, 2);
+ return setTimeout(function(){ return func.apply(null, args); }, wait);
+ };
+
+ window.debounce = function(func, wait, immediate) {
+ var timeout;
+ return function() {
+ var context = this, args = arguments;
+ var later = function() {
+ timeout = null;
+ if (!immediate) func.apply(context, args);
+ };
+ if (immediate && !timeout) func.apply(context, args);
+ clearTimeout(timeout);
+ timeout = setTimeout(later, wait);
+ };
+ };
+
+ window.throttle = function(func, wait) {
+ var context, args, timeout, throttling, more, result;
+ var whenDone = debounce(
+ function(){ more = throttling = false; }, wait);
+ return function() {
+ context = this; args = arguments;
+ var later = function() {
+ timeout = null;
+ if (more) func.apply(context, args);
+ whenDone();
+ };
+ if (!timeout) timeout = setTimeout(later, wait);
+ if (throttling) {
+ more = true;
+ } else {
+ result = func.apply(context, args);
+ }
+ whenDone();
+ throttling = true;
+ return result;
+ };
+ };
+
+})(window);
+
+;(function(root, factory) {
+
+ if (typeof define === 'function' && define.amd) {
+ define('gridster-draggable', ['jquery'], factory);
+ } else {
+ root.GridsterDraggable = factory(root.$ || root.jQuery);
+ }
+
+}(this, function($) {
+
+ var defaults = {
+ items: 'li',
+ distance: 1,
+ limit: true,
+ offset_left: 0,
+ autoscroll: true,
+ ignore_dragging: ['INPUT', 'TEXTAREA', 'SELECT', 'BUTTON'], // or function
+ handle: null,
+ container_width: 0, // 0 == auto
+ move_element: true,
+ helper: false, // or 'clone'
+ remove_helper: true
+ // drag: function(e) {},
+ // start : function(e, ui) {},
+ // stop : function(e) {}
+ };
+
+ var $window = $(window);
+ var dir_map = { x : 'left', y : 'top' };
+ var isTouch = !!('ontouchstart' in window);
+
+ var capitalize = function(str) {
+ return str.charAt(0).toUpperCase() + str.slice(1);
+ };
+
+ var idCounter = 0;
+ var uniqId = function() {
+ return ++idCounter + '';
+ }
+
+ /**
+ * Basic drag implementation for DOM elements inside a container.
+ * Provide start/stop/drag callbacks.
+ *
+ * @class Draggable
+ * @param {HTMLElement} el The HTMLelement that contains all the widgets
+ * to be dragged.
+ * @param {Object} [options] An Object with all options you want to
+ * overwrite:
+ * @param {HTMLElement|String} [options.items] Define who will
+ * be the draggable items. Can be a CSS Selector String or a
+ * collection of HTMLElements.
+ * @param {Number} [options.distance] Distance in pixels after mousedown
+ * the mouse must move before dragging should start.
+ * @param {Boolean} [options.limit] Constrains dragging to the width of
+ * the container
+ * @param {Object|Function} [options.ignore_dragging] Array of node names
+ * that sould not trigger dragging, by default is `['INPUT', 'TEXTAREA',
+ * 'SELECT', 'BUTTON']`. If a function is used return true to ignore dragging.
+ * @param {offset_left} [options.offset_left] Offset added to the item
+ * that is being dragged.
+ * @param {Number} [options.drag] Executes a callback when the mouse is
+ * moved during the dragging.
+ * @param {Number} [options.start] Executes a callback when the drag
+ * starts.
+ * @param {Number} [options.stop] Executes a callback when the drag stops.
+ * @return {Object} Returns `el`.
+ * @constructor
+ */
+ function Draggable(el, options) {
+ this.options = $.extend({}, defaults, options);
+ this.$document = $(document);
+ this.$container = $(el);
+ this.$dragitems = $(this.options.items, this.$container);
+ this.is_dragging = false;
+ this.player_min_left = 0 + this.options.offset_left;
+ this.id = uniqId();
+ this.ns = '.gridster-draggable-' + this.id;
+ this.init();
+ }
+
+ Draggable.defaults = defaults;
+
+ var fn = Draggable.prototype;
+
+ fn.init = function() {
+ var pos = this.$container.css('position');
+ this.calculate_dimensions();
+ this.$container.css('position', pos === 'static' ? 'relative' : pos);
+ this.disabled = false;
+ this.events();
+
+ $(window).bind(this.nsEvent('resize'),
+ throttle($.proxy(this.calculate_dimensions, this), 200));
+ };
+
+ fn.nsEvent = function(ev) {
+ return (ev || '') + this.ns;
+ };
+
+ fn.events = function() {
+ this.pointer_events = {
+ start: this.nsEvent('touchstart') + ' ' + this.nsEvent('mousedown'),
+ move: this.nsEvent('touchmove') + ' ' + this.nsEvent('mousemove'),
+ end: this.nsEvent('touchend') + ' ' + this.nsEvent('mouseup'),
+ };
+
+ this.$container.on(this.nsEvent('selectstart'),
+ $.proxy(this.on_select_start, this));
+
+ this.$container.on(this.pointer_events.start, this.options.items,
+ $.proxy(this.drag_handler, this));
+
+ this.$document.on(this.pointer_events.end, $.proxy(function(e) {
+ this.is_dragging = false;
+ if (this.disabled) { return; }
+ this.$document.off(this.pointer_events.move);
+ if (this.drag_start) {
+ this.on_dragstop(e);
+ }
+ }, this));
+ };
+
+ fn.get_actual_pos = function($el) {
+ var pos = $el.position();
+ return pos;
+ };
+
+
+ fn.get_mouse_pos = function(e) {
+ if (e.originalEvent && e.originalEvent.touches) {
+ var oe = e.originalEvent;
+ e = oe.touches.length ? oe.touches[0] : oe.changedTouches[0];
+ }
+
+ return {
+ left: e.clientX,
+ top: e.clientY
+ };
+ };
+
+
+ fn.get_offset = function(e) {
+ e.preventDefault();
+ var mouse_actual_pos = this.get_mouse_pos(e);
+ var diff_x = Math.round(
+ mouse_actual_pos.left - this.mouse_init_pos.left);
+ var diff_y = Math.round(mouse_actual_pos.top - this.mouse_init_pos.top);
+
+ var left = Math.round(this.el_init_offset.left +
+ diff_x - this.baseX + $(window).scrollLeft() - this.win_offset_x);
+ var top = Math.round(this.el_init_offset.top +
+ diff_y - this.baseY + $(window).scrollTop() - this.win_offset_y);
+
+ if (this.options.limit) {
+ if (left > this.player_max_left) {
+ left = this.player_max_left;
+ } else if(left < this.player_min_left) {
+ left = this.player_min_left;
+ }
+ }
+
+ return {
+ position: {
+ left: left,
+ top: top
+ },
+ pointer: {
+ left: mouse_actual_pos.left,
+ top: mouse_actual_pos.top,
+ diff_left: diff_x + ($(window).scrollLeft() - this.win_offset_x),
+ diff_top: diff_y + ($(window).scrollTop() - this.win_offset_y)
+ }
+ };
+ };
+
+
+ fn.get_drag_data = function(e) {
+ var offset = this.get_offset(e);
+ offset.$player = this.$player;
+ offset.$helper = this.helper ? this.$helper : this.$player;
+
+ return offset;
+ };
+
+
+ fn.set_limits = function(container_width) {
+ container_width || (container_width = this.$container.width());
+ this.player_max_left = (container_width - this.player_width +
+ - this.options.offset_left);
+
+ this.options.container_width = container_width;
+
+ return this;
+ };
+
+
+ fn.scroll_in = function(axis, data) {
+ var dir_prop = dir_map[axis];
+
+ var area_size = 50;
+ var scroll_inc = 30;
+
+ var is_x = axis === 'x';
+ var window_size = is_x ? this.window_width : this.window_height;
+ var doc_size = is_x ? $(document).width() : $(document).height();
+ var player_size = is_x ? this.$player.width() : this.$player.height();
+
+ var next_scroll;
+ var scroll_offset = $window['scroll' + capitalize(dir_prop)]();
+ var min_window_pos = scroll_offset;
+ var max_window_pos = min_window_pos + window_size;
+
+ var mouse_next_zone = max_window_pos - area_size; // down/right
+ var mouse_prev_zone = min_window_pos + area_size; // up/left
+
+ var abs_mouse_pos = min_window_pos + data.pointer[dir_prop];
+
+ var max_player_pos = (doc_size - window_size + player_size);
+
+ if (abs_mouse_pos >= mouse_next_zone) {
+ next_scroll = scroll_offset + scroll_inc;
+ if (next_scroll < max_player_pos) {
+ $window['scroll' + capitalize(dir_prop)](next_scroll);
+ this['scroll_offset_' + axis] += scroll_inc;
+ }
+ }
+
+ if (abs_mouse_pos <= mouse_prev_zone) {
+ next_scroll = scroll_offset - scroll_inc;
+ if (next_scroll > 0) {
+ $window['scroll' + capitalize(dir_prop)](next_scroll);
+ this['scroll_offset_' + axis] -= scroll_inc;
+ }
+ }
+
+ return this;
+ };
+
+
+ fn.manage_scroll = function(data) {
+ this.scroll_in('x', data);
+ this.scroll_in('y', data);
+ };
+
+
+ fn.calculate_dimensions = function(e) {
+ this.window_height = $window.height();
+ this.window_width = $window.width();
+ };
+
+
+ fn.drag_handler = function(e) {
+ var node = e.target.nodeName;
+ // skip if drag is disabled, or click was not done with the mouse primary button
+ if (this.disabled || e.which !== 1 && !isTouch) {
+ return;
+ }
+
+ if (this.ignore_drag(e)) {
+ return;
+ }
+
+ var self = this;
+ var first = true;
+ this.$player = $(e.currentTarget);
+
+ this.el_init_pos = this.get_actual_pos(this.$player);
+ this.mouse_init_pos = this.get_mouse_pos(e);
+ this.offsetY = this.mouse_init_pos.top - this.el_init_pos.top;
+
+ this.$document.on(this.pointer_events.move, function(mme) {
+ var mouse_actual_pos = self.get_mouse_pos(mme);
+ var diff_x = Math.abs(
+ mouse_actual_pos.left - self.mouse_init_pos.left);
+ var diff_y = Math.abs(
+ mouse_actual_pos.top - self.mouse_init_pos.top);
+ if (!(diff_x > self.options.distance ||
+ diff_y > self.options.distance)
+ ) {
+ return false;
+ }
+
+ if (first) {
+ first = false;
+ self.on_dragstart.call(self, mme);
+ return false;
+ }
+
+ if (self.is_dragging === true) {
+ self.on_dragmove.call(self, mme);
+ }
+
+ return false;
+ });
+
+ if (!isTouch) { return false; }
+ };
+
+
+ fn.on_dragstart = function(e) {
+ e.preventDefault();
+
+ if (this.is_dragging) { return this; }
+
+ this.drag_start = this.is_dragging = true;
+ var offset = this.$container.offset();
+ this.baseX = Math.round(offset.left);
+ this.baseY = Math.round(offset.top);
+ this.initial_container_width = this.options.container_width || this.$container.width();
+
+ if (this.options.helper === 'clone') {
+ this.$helper = this.$player.clone()
+ .appendTo(this.$container).addClass('helper');
+ this.helper = true;
+ } else {
+ this.helper = false;
+ }
+
+ this.win_offset_y = $(window).scrollTop();
+ this.win_offset_x = $(window).scrollLeft();
+ this.scroll_offset_y = 0;
+ this.scroll_offset_x = 0;
+ this.el_init_offset = this.$player.offset();
+ this.player_width = this.$player.width();
+ this.player_height = this.$player.height();
+
+ this.set_limits(this.options.container_width);
+
+ if (this.options.start) {
+ this.options.start.call(this.$player, e, this.get_drag_data(e));
+ }
+ return false;
+ };
+
+
+ fn.on_dragmove = function(e) {
+ var data = this.get_drag_data(e);
+
+ this.options.autoscroll && this.manage_scroll(data);
+
+ if (this.options.move_element) {
+ (this.helper ? this.$helper : this.$player).css({
+ 'position': 'absolute',
+ 'left' : data.position.left,
+ 'top' : data.position.top
+ });
+ }
+
+ var last_position = this.last_position || data.position;
+ data.prev_position = last_position;
+
+ if (this.options.drag) {
+ this.options.drag.call(this.$player, e, data);
+ }
+
+ this.last_position = data.position;
+ return false;
+ };
+
+
+ fn.on_dragstop = function(e) {
+ var data = this.get_drag_data(e);
+ this.drag_start = false;
+
+ if (this.options.stop) {
+ this.options.stop.call(this.$player, e, data);
+ }
+
+ if (this.helper && this.options.remove_helper) {
+ this.$helper.remove();
+ }
+
+ return false;
+ };
+
+ fn.on_select_start = function(e) {
+ if (this.disabled) { return; }
+
+ if (this.ignore_drag(e)) {
+ return;
+ }
+
+ return false;
+ };
+
+ fn.enable = function() {
+ this.disabled = false;
+ };
+
+ fn.disable = function() {
+ this.disabled = true;
+ };
+
+ fn.destroy = function() {
+ this.disable();
+
+ this.$container.off(this.ns);
+ this.$document.off(this.ns);
+ $(window).off(this.ns);
+
+ $.removeData(this.$container, 'drag');
+ };
+
+ fn.ignore_drag = function(event) {
+ if (this.options.handle) {
+ return !$(event.target).is(this.options.handle);
+ }
+
+ if ($.isFunction(this.options.ignore_dragging)) {
+ return this.options.ignore_dragging(event);
+ }
+
+ return $(event.target).is(this.options.ignore_dragging.join(', '));
+ };
+
+ //jQuery adapter
+ $.fn.drag = function ( options ) {
+ return new Draggable(this, options);
+ };
+
+ return Draggable;
+
+}));
+
+;(function(root, factory) {
+
+ if (typeof define === 'function' && define.amd) {
+ define(['jquery', 'gridster-draggable', 'gridster-collision'], factory);
+ } else {
+ root.Gridster = factory(root.$ || root.jQuery, root.GridsterDraggable,
+ root.GridsterCollision);
+ }
+
+ }(this, function($, Draggable, Collision) {
+
+ var defaults = {
+ namespace: '',
+ widget_selector: 'li',
+ widget_margins: [10, 10],
+ widget_base_dimensions: [400, 225],
+ extra_rows: 0,
+ extra_cols: 0,
+ min_cols: 1,
+ max_cols: Infinity,
+ min_rows: 15,
+ max_size_x: false,
+ autogrow_cols: false,
+ autogenerate_stylesheet: true,
+ avoid_overlapped_widgets: true,
+ auto_init: true,
+ serialize_params: function($w, wgd) {
+ return {
+ col: wgd.col,
+ row: wgd.row,
+ size_x: wgd.size_x,
+ size_y: wgd.size_y
+ };
+ },
+ collision: {},
+ draggable: {
+ items: '.gs-w',
+ distance: 4,
+ ignore_dragging: Draggable.defaults.ignore_dragging.slice(0)
+ },
+ resize: {
+ enabled: false,
+ axes: ['both'],
+ handle_append_to: '',
+ handle_class: 'gs-resize-handle',
+ max_size: [Infinity, Infinity],
+ min_size: [1, 1]
+ }
+ };
+
+ /**
+ * @class Gridster
+ * @uses Draggable
+ * @uses Collision
+ * @param {HTMLElement} el The HTMLelement that contains all the widgets.
+ * @param {Object} [options] An Object with all options you want to
+ * overwrite:
+ * @param {HTMLElement|String} [options.widget_selector] Define who will
+ * be the draggable widgets. Can be a CSS Selector String or a
+ * collection of HTMLElements
+ * @param {Array} [options.widget_margins] Margin between widgets.
+ * The first index for the horizontal margin (left, right) and
+ * the second for the vertical margin (top, bottom).
+ * @param {Array} [options.widget_base_dimensions] Base widget dimensions
+ * in pixels. The first index for the width and the second for the
+ * height.
+ * @param {Number} [options.extra_cols] Add more columns in addition to
+ * those that have been calculated.
+ * @param {Number} [options.extra_rows] Add more rows in addition to
+ * those that have been calculated.
+ * @param {Number} [options.min_cols] The minimum required columns.
+ * @param {Number} [options.max_cols] The maximum columns possible (set to null
+ * for no maximum).
+ * @param {Number} [options.min_rows] The minimum required rows.
+ * @param {Number} [options.max_size_x] The maximum number of columns
+ * that a widget can span.
+ * @param {Boolean} [options.autogenerate_stylesheet] If true, all the
+ * CSS required to position all widgets in their respective columns
+ * and rows will be generated automatically and injected to the
+ * `` of the document. You can set this to false, and write
+ * your own CSS targeting rows and cols via data-attributes like so:
+ * `[data-col="1"] { left: 10px; }`
+ * @param {Boolean} [options.avoid_overlapped_widgets] Avoid that widgets loaded
+ * from the DOM can be overlapped. It is helpful if the positions were
+ * bad stored in the database or if there was any conflict.
+ * @param {Boolean} [options.auto_init] Automatically call gridster init
+ * method or not when the plugin is instantiated.
+ * @param {Function} [options.serialize_params] Return the data you want
+ * for each widget in the serialization. Two arguments are passed:
+ * `$w`: the jQuery wrapped HTMLElement, and `wgd`: the grid
+ * coords object (`col`, `row`, `size_x`, `size_y`).
+ * @param {Object} [options.collision] An Object with all options for
+ * Collision class you want to overwrite. See Collision docs for
+ * more info.
+ * @param {Object} [options.draggable] An Object with all options for
+ * Draggable class you want to overwrite. See Draggable docs for more
+ * info.
+ * @param {Object|Function} [options.draggable.ignore_dragging] Note that
+ * if you use a Function, and resize is enabled, you should ignore the
+ * resize handlers manually (options.resize.handle_class).
+ * @param {Object} [options.resize] An Object with resize config options.
+ * @param {Boolean} [options.resize.enabled] Set to true to enable
+ * resizing.
+ * @param {Array} [options.resize.axes] Axes in which widgets can be
+ * resized. Possible values: ['x', 'y', 'both'].
+ * @param {String} [options.resize.handle_append_to] Set a valid CSS
+ * selector to append resize handles to.
+ * @param {String} [options.resize.handle_class] CSS class name used
+ * by resize handles.
+ * @param {Array} [options.resize.max_size] Limit widget dimensions
+ * when resizing. Array values should be integers:
+ * `[max_cols_occupied, max_rows_occupied]`
+ * @param {Array} [options.resize.min_size] Limit widget dimensions
+ * when resizing. Array values should be integers:
+ * `[min_cols_occupied, min_rows_occupied]`
+ * @param {Function} [options.resize.start] Function executed
+ * when resizing starts.
+ * @param {Function} [otions.resize.resize] Function executed
+ * during the resizing.
+ * @param {Function} [options.resize.stop] Function executed
+ * when resizing stops.
+ *
+ * @constructor
+ */
+ function Gridster(el, options) {
+ this.options = $.extend(true, {}, defaults, options);
+ this.$el = $(el);
+ this.$wrapper = this.$el.parent();
+ this.$widgets = this.$el.children(
+ this.options.widget_selector).addClass('gs-w');
+ this.widgets = [];
+ this.$changed = $([]);
+ this.wrapper_width = this.$wrapper.width();
+ this.min_widget_width = (this.options.widget_margins[0] * 2) +
+ this.options.widget_base_dimensions[0];
+ this.min_widget_height = (this.options.widget_margins[1] * 2) +
+ this.options.widget_base_dimensions[1];
+
+ this.generated_stylesheets = [];
+ this.$style_tags = $([]);
+
+ this.options.auto_init && this.init();
+ }
+
+ Gridster.defaults = defaults;
+ Gridster.generated_stylesheets = [];
+
+
+ /**
+ * Sorts an Array of grid coords objects (representing the grid coords of
+ * each widget) in ascending way.
+ *
+ * @method sort_by_row_asc
+ * @param {Array} widgets Array of grid coords objects
+ * @return {Array} Returns the array sorted.
+ */
+ Gridster.sort_by_row_asc = function(widgets) {
+ widgets = widgets.sort(function(a, b) {
+ if (!a.row) {
+ a = $(a).coords().grid;
+ b = $(b).coords().grid;
+ }
+
+ if (a.row > b.row) {
+ return 1;
+ }
+ return -1;
+ });
+
+ return widgets;
+ };
+
+
+ /**
+ * Sorts an Array of grid coords objects (representing the grid coords of
+ * each widget) placing first the empty cells upper left.
+ *
+ * @method sort_by_row_and_col_asc
+ * @param {Array} widgets Array of grid coords objects
+ * @return {Array} Returns the array sorted.
+ */
+ Gridster.sort_by_row_and_col_asc = function(widgets) {
+ widgets = widgets.sort(function(a, b) {
+ if (a.row > b.row || a.row === b.row && a.col > b.col) {
+ return 1;
+ }
+ return -1;
+ });
+
+ return widgets;
+ };
+
+
+ /**
+ * Sorts an Array of grid coords objects by column (representing the grid
+ * coords of each widget) in ascending way.
+ *
+ * @method sort_by_col_asc
+ * @param {Array} widgets Array of grid coords objects
+ * @return {Array} Returns the array sorted.
+ */
+ Gridster.sort_by_col_asc = function(widgets) {
+ widgets = widgets.sort(function(a, b) {
+ if (a.col > b.col) {
+ return 1;
+ }
+ return -1;
+ });
+
+ return widgets;
+ };
+
+
+ /**
+ * Sorts an Array of grid coords objects (representing the grid coords of
+ * each widget) in descending way.
+ *
+ * @method sort_by_row_desc
+ * @param {Array} widgets Array of grid coords objects
+ * @return {Array} Returns the array sorted.
+ */
+ Gridster.sort_by_row_desc = function(widgets) {
+ widgets = widgets.sort(function(a, b) {
+ if (a.row + a.size_y < b.row + b.size_y) {
+ return 1;
+ }
+ return -1;
+ });
+ return widgets;
+ };
+
+
+
+ /** Instance Methods **/
+
+ var fn = Gridster.prototype;
+
+ fn.init = function() {
+ this.options.resize.enabled && this.setup_resize();
+ this.generate_grid_and_stylesheet();
+ this.get_widgets_from_DOM();
+ this.set_dom_grid_height();
+ this.set_dom_grid_width();
+ this.$wrapper.addClass('ready');
+ this.draggable();
+ this.options.resize.enabled && this.resizable();
+
+ $(window).bind('resize.gridster', throttle(
+ $.proxy(this.recalculate_faux_grid, this), 200));
+ };
+
+
+ /**
+ * Disables dragging.
+ *
+ * @method disable
+ * @return {Class} Returns the instance of the Gridster Class.
+ */
+ fn.disable = function() {
+ this.$wrapper.find('.player-revert').removeClass('player-revert');
+ this.drag_api.disable();
+ return this;
+ };
+
+
+ /**
+ * Enables dragging.
+ *
+ * @method enable
+ * @return {Class} Returns the instance of the Gridster Class.
+ */
+ fn.enable = function() {
+ this.drag_api.enable();
+ return this;
+ };
+
+
+
+ /**
+ * Disables drag-and-drop widget resizing.
+ *
+ * @method disable
+ * @return {Class} Returns instance of gridster Class.
+ */
+ fn.disable_resize = function() {
+ this.$el.addClass('gs-resize-disabled');
+ this.resize_api.disable();
+ return this;
+ };
+
+
+ /**
+ * Enables drag-and-drop widget resizing.
+ *
+ * @method enable
+ * @return {Class} Returns instance of gridster Class.
+ */
+ fn.enable_resize = function() {
+ this.$el.removeClass('gs-resize-disabled');
+ this.resize_api.enable();
+ return this;
+ };
+
+
+ /**
+ * Add a new widget to the grid.
+ *
+ * @method add_widget
+ * @param {String|HTMLElement} html The string representing the HTML of the widget
+ * or the HTMLElement.
+ * @param {Number} [size_x] The nº of rows the widget occupies horizontally.
+ * @param {Number} [size_y] The nº of columns the widget occupies vertically.
+ * @param {Number} [col] The column the widget should start in.
+ * @param {Number} [row] The row the widget should start in.
+ * @param {Array} [max_size] max_size Maximun size (in units) for width and height.
+ * @param {Array} [min_size] min_size Minimum size (in units) for width and height.
+ * @return {HTMLElement} Returns the jQuery wrapped HTMLElement representing.
+ * the widget that was just created.
+ */
+ fn.add_widget = function(html, size_x, size_y, col, row, max_size, min_size) {
+ var pos;
+ size_x || (size_x = 1);
+ size_y || (size_y = 1);
+
+ if (!col & !row) {
+ pos = this.next_position(size_x, size_y);
+ } else {
+ pos = {
+ col: col,
+ row: row,
+ size_x: size_x,
+ size_y: size_y
+ };
+
+ this.empty_cells(col, row, size_x, size_y);
+ }
+
+ var $w = $(html).attr({
+ 'data-col': pos.col,
+ 'data-row': pos.row,
+ 'data-sizex' : size_x,
+ 'data-sizey' : size_y
+ }).addClass('gs-w').appendTo(this.$el).hide();
+
+ this.$widgets = this.$widgets.add($w);
+
+ this.register_widget($w);
+
+ this.add_faux_rows(pos.size_y);
+ //this.add_faux_cols(pos.size_x);
+
+ if (max_size) {
+ this.set_widget_max_size($w, max_size);
+ }
+
+ if (min_size) {
+ this.set_widget_min_size($w, min_size);
+ }
+
+ this.set_dom_grid_width();
+ this.set_dom_grid_height();
+
+ this.drag_api.set_limits(this.cols * this.min_widget_width);
+
+ return $w.fadeIn();
+ };
+
+
+ /**
+ * Change widget size limits.
+ *
+ * @method set_widget_min_size
+ * @param {HTMLElement|Number} $widget The jQuery wrapped HTMLElement
+ * representing the widget or an index representing the desired widget.
+ * @param {Array} min_size Minimum size (in units) for width and height.
+ * @return {HTMLElement} Returns instance of gridster Class.
+ */
+ fn.set_widget_min_size = function($widget, min_size) {
+ $widget = typeof $widget === 'number' ?
+ this.$widgets.eq($widget) : $widget;
+
+ if (!$widget.length) { return this; }
+
+ var wgd = $widget.data('coords').grid;
+ wgd.min_size_x = min_size[0];
+ wgd.min_size_y = min_size[1];
+
+ return this;
+ };
+
+
+ /**
+ * Change widget size limits.
+ *
+ * @method set_widget_max_size
+ * @param {HTMLElement|Number} $widget The jQuery wrapped HTMLElement
+ * representing the widget or an index representing the desired widget.
+ * @param {Array} max_size Maximun size (in units) for width and height.
+ * @return {HTMLElement} Returns instance of gridster Class.
+ */
+ fn.set_widget_max_size = function($widget, max_size) {
+ $widget = typeof $widget === 'number' ?
+ this.$widgets.eq($widget) : $widget;
+
+ if (!$widget.length) { return this; }
+
+ var wgd = $widget.data('coords').grid;
+ wgd.max_size_x = max_size[0];
+ wgd.max_size_y = max_size[1];
+
+ return this;
+ };
+
+
+ /**
+ * Append the resize handle into a widget.
+ *
+ * @method add_resize_handle
+ * @param {HTMLElement} $widget The jQuery wrapped HTMLElement
+ * representing the widget.
+ * @return {HTMLElement} Returns instance of gridster Class.
+ */
+ fn.add_resize_handle = function($w) {
+ var append_to = this.options.resize.handle_append_to;
+ $(this.resize_handle_tpl).appendTo( append_to ? $(append_to, $w) : $w);
+
+ return this;
+ };
+
+
+ /**
+ * Change the size of a widget. Width is limited to the current grid width.
+ *
+ * @method resize_widget
+ * @param {HTMLElement} $widget The jQuery wrapped HTMLElement
+ * representing the widget.
+ * @param {Number} size_x The number of columns that will occupy the widget.
+ * By default size_x is limited to the space available from
+ * the column where the widget begins, until the last column to the right.
+ * @param {Number} size_y The number of rows that will occupy the widget.
+ * @param {Function} [callback] Function executed when the widget is removed.
+ * @return {HTMLElement} Returns $widget.
+ */
+ fn.resize_widget = function($widget, size_x, size_y, callback) {
+ var wgd = $widget.coords().grid;
+ var col = wgd.col;
+ var max_cols = this.options.max_cols;
+ var old_size_y = wgd.size_y;
+ var old_col = wgd.col;
+ var new_col = old_col;
+
+ size_x || (size_x = wgd.size_x);
+ size_y || (size_y = wgd.size_y);
+
+ if (max_cols !== Infinity) {
+ size_x = Math.min(size_x, max_cols - col + 1);
+ }
+
+ if (size_y > old_size_y) {
+ this.add_faux_rows(Math.max(size_y - old_size_y, 0));
+ }
+
+ var player_rcol = (col + size_x - 1);
+ if (player_rcol > this.cols) {
+ this.add_faux_cols(player_rcol - this.cols);
+ }
+
+ var new_grid_data = {
+ col: new_col,
+ row: wgd.row,
+ size_x: size_x,
+ size_y: size_y
+ };
+
+ this.mutate_widget_in_gridmap($widget, wgd, new_grid_data);
+
+ this.set_dom_grid_height();
+ this.set_dom_grid_width();
+
+ if (callback) {
+ callback.call(this, new_grid_data.size_x, new_grid_data.size_y);
+ }
+
+ return $widget;
+ };
+
+
+ /**
+ * Mutate widget dimensions and position in the grid map.
+ *
+ * @method mutate_widget_in_gridmap
+ * @param {HTMLElement} $widget The jQuery wrapped HTMLElement
+ * representing the widget to mutate.
+ * @param {Object} wgd Current widget grid data (col, row, size_x, size_y).
+ * @param {Object} new_wgd New widget grid data.
+ * @return {HTMLElement} Returns instance of gridster Class.
+ */
+ fn.mutate_widget_in_gridmap = function($widget, wgd, new_wgd) {
+ var old_size_x = wgd.size_x;
+ var old_size_y = wgd.size_y;
+
+ var old_cells_occupied = this.get_cells_occupied(wgd);
+ var new_cells_occupied = this.get_cells_occupied(new_wgd);
+
+ var empty_cols = [];
+ $.each(old_cells_occupied.cols, function(i, col) {
+ if ($.inArray(col, new_cells_occupied.cols) === -1) {
+ empty_cols.push(col);
+ }
+ });
+
+ var occupied_cols = [];
+ $.each(new_cells_occupied.cols, function(i, col) {
+ if ($.inArray(col, old_cells_occupied.cols) === -1) {
+ occupied_cols.push(col);
+ }
+ });
+
+ var empty_rows = [];
+ $.each(old_cells_occupied.rows, function(i, row) {
+ if ($.inArray(row, new_cells_occupied.rows) === -1) {
+ empty_rows.push(row);
+ }
+ });
+
+ var occupied_rows = [];
+ $.each(new_cells_occupied.rows, function(i, row) {
+ if ($.inArray(row, old_cells_occupied.rows) === -1) {
+ occupied_rows.push(row);
+ }
+ });
+
+ this.remove_from_gridmap(wgd);
+
+ if (occupied_cols.length) {
+ var cols_to_empty = [
+ new_wgd.col, new_wgd.row, new_wgd.size_x, Math.min(old_size_y, new_wgd.size_y), $widget
+ ];
+ this.empty_cells.apply(this, cols_to_empty);
+ }
+
+ if (occupied_rows.length) {
+ var rows_to_empty = [new_wgd.col, new_wgd.row, new_wgd.size_x, new_wgd.size_y, $widget];
+ this.empty_cells.apply(this, rows_to_empty);
+ }
+
+ // not the same that wgd = new_wgd;
+ wgd.col = new_wgd.col;
+ wgd.row = new_wgd.row;
+ wgd.size_x = new_wgd.size_x;
+ wgd.size_y = new_wgd.size_y;
+
+ this.add_to_gridmap(new_wgd, $widget);
+
+ $widget.removeClass('player-revert');
+
+ //update coords instance attributes
+ $widget.data('coords').update({
+ width: (new_wgd.size_x * this.options.widget_base_dimensions[0] +
+ ((new_wgd.size_x - 1) * this.options.widget_margins[0]) * 2),
+ height: (new_wgd.size_y * this.options.widget_base_dimensions[1] +
+ ((new_wgd.size_y - 1) * this.options.widget_margins[1]) * 2)
+ });
+
+ $widget.attr({
+ 'data-col': new_wgd.col,
+ 'data-row': new_wgd.row,
+ 'data-sizex': new_wgd.size_x,
+ 'data-sizey': new_wgd.size_y
+ });
+
+ if (empty_cols.length) {
+ var cols_to_remove_holes = [
+ empty_cols[0], new_wgd.row,
+ empty_cols.length,
+ Math.min(old_size_y, new_wgd.size_y),
+ $widget
+ ];
+
+ this.remove_empty_cells.apply(this, cols_to_remove_holes);
+ }
+
+ if (empty_rows.length) {
+ var rows_to_remove_holes = [
+ new_wgd.col, new_wgd.row, new_wgd.size_x, new_wgd.size_y, $widget
+ ];
+ this.remove_empty_cells.apply(this, rows_to_remove_holes);
+ }
+
+ this.move_widget_up($widget);
+
+ return this;
+ };
+
+
+ /**
+ * Move down widgets in cells represented by the arguments col, row, size_x,
+ * size_y
+ *
+ * @method empty_cells
+ * @param {Number} col The column where the group of cells begin.
+ * @param {Number} row The row where the group of cells begin.
+ * @param {Number} size_x The number of columns that the group of cells
+ * occupy.
+ * @param {Number} size_y The number of rows that the group of cells
+ * occupy.
+ * @param {HTMLElement} $exclude Exclude widgets from being moved.
+ * @return {Class} Returns the instance of the Gridster Class.
+ */
+ fn.empty_cells = function(col, row, size_x, size_y, $exclude) {
+ var $nexts = this.widgets_below({
+ col: col,
+ row: row - size_y,
+ size_x: size_x,
+ size_y: size_y
+ });
+
+ $nexts.not($exclude).each($.proxy(function(i, w) {
+ var wgd = $(w).coords().grid;
+ if ( !(wgd.row <= (row + size_y - 1))) { return; }
+ var diff = (row + size_y) - wgd.row;
+ this.move_widget_down($(w), diff);
+ }, this));
+
+ this.set_dom_grid_height();
+
+ return this;
+ };
+
+
+ /**
+ * Move up widgets below cells represented by the arguments col, row, size_x,
+ * size_y.
+ *
+ * @method remove_empty_cells
+ * @param {Number} col The column where the group of cells begin.
+ * @param {Number} row The row where the group of cells begin.
+ * @param {Number} size_x The number of columns that the group of cells
+ * occupy.
+ * @param {Number} size_y The number of rows that the group of cells
+ * occupy.
+ * @param {HTMLElement} exclude Exclude widgets from being moved.
+ * @return {Class} Returns the instance of the Gridster Class.
+ */
+ fn.remove_empty_cells = function(col, row, size_x, size_y, exclude) {
+ var $nexts = this.widgets_below({
+ col: col,
+ row: row,
+ size_x: size_x,
+ size_y: size_y
+ });
+
+ $nexts.not(exclude).each($.proxy(function(i, widget) {
+ this.move_widget_up( $(widget), size_y );
+ }, this));
+
+ this.set_dom_grid_height();
+
+ return this;
+ };
+
+
+ /**
+ * Get the most left column below to add a new widget.
+ *
+ * @method next_position
+ * @param {Number} size_x The nº of rows the widget occupies horizontally.
+ * @param {Number} size_y The nº of columns the widget occupies vertically.
+ * @return {Object} Returns a grid coords object representing the future
+ * widget coords.
+ */
+ fn.next_position = function(size_x, size_y) {
+ size_x || (size_x = 1);
+ size_y || (size_y = 1);
+ var ga = this.gridmap;
+ var cols_l = ga.length;
+ var valid_pos = [];
+ var rows_l;
+
+ for (var c = 1; c < cols_l; c++) {
+ rows_l = ga[c].length;
+ for (var r = 1; r <= rows_l; r++) {
+ var can_move_to = this.can_move_to({
+ size_x: size_x,
+ size_y: size_y
+ }, c, r);
+
+ if (can_move_to) {
+ valid_pos.push({
+ col: c,
+ row: r,
+ size_y: size_y,
+ size_x: size_x
+ });
+ }
+ }
+ }
+
+ if (valid_pos.length) {
+ return Gridster.sort_by_row_and_col_asc(valid_pos)[0];
+ }
+ return false;
+ };
+
+
+ /**
+ * Remove a widget from the grid.
+ *
+ * @method remove_widget
+ * @param {HTMLElement} el The jQuery wrapped HTMLElement you want to remove.
+ * @param {Boolean|Function} silent If true, widgets below the removed one
+ * will not move up. If a Function is passed it will be used as callback.
+ * @param {Function} callback Function executed when the widget is removed.
+ * @return {Class} Returns the instance of the Gridster Class.
+ */
+ fn.remove_widget = function(el, silent, callback) {
+ var $el = el instanceof $ ? el : $(el);
+ var wgd = $el.coords().grid;
+
+ // if silent is a function assume it's a callback
+ if ($.isFunction(silent)) {
+ callback = silent;
+ silent = false;
+ }
+
+ this.cells_occupied_by_placeholder = {};
+ this.$widgets = this.$widgets.not($el);
+
+ var $nexts = this.widgets_below($el);
+
+ this.remove_from_gridmap(wgd);
+
+ $el.fadeOut($.proxy(function() {
+ $el.remove();
+
+ if (!silent) {
+ $nexts.each($.proxy(function(i, widget) {
+ this.move_widget_up( $(widget), wgd.size_y );
+ }, this));
+ }
+
+ this.set_dom_grid_height();
+
+ if (callback) {
+ callback.call(this, el);
+ }
+ }, this));
+
+ return this;
+ };
+
+
+ /**
+ * Remove all widgets from the grid.
+ *
+ * @method remove_all_widgets
+ * @param {Function} callback Function executed for each widget removed.
+ * @return {Class} Returns the instance of the Gridster Class.
+ */
+ fn.remove_all_widgets = function(callback) {
+ this.$widgets.each($.proxy(function(i, el){
+ this.remove_widget(el, true, callback);
+ }, this));
+
+ return this;
+ };
+
+
+ /**
+ * Returns a serialized array of the widgets in the grid.
+ *
+ * @method serialize
+ * @param {HTMLElement} [$widgets] The collection of jQuery wrapped
+ * HTMLElements you want to serialize. If no argument is passed all widgets
+ * will be serialized.
+ * @return {Array} Returns an Array of Objects with the data specified in
+ * the serialize_params option.
+ */
+ fn.serialize = function($widgets) {
+ $widgets || ($widgets = this.$widgets);
+
+ return $widgets.map($.proxy(function(i, widget) {
+ var $w = $(widget);
+ return this.options.serialize_params($w, $w.coords().grid);
+ }, this)).get();
+ };
+
+
+ /**
+ * Returns a serialized array of the widgets that have changed their
+ * position.
+ *
+ * @method serialize_changed
+ * @return {Array} Returns an Array of Objects with the data specified in
+ * the serialize_params option.
+ */
+ fn.serialize_changed = function() {
+ return this.serialize(this.$changed);
+ };
+
+
+ /**
+ * Convert widgets from DOM elements to "widget grid data" Objects.
+ *
+ * @method dom_to_coords
+ * @param {HTMLElement} $widget The widget to be converted.
+ */
+ fn.dom_to_coords = function($widget) {
+ return {
+ 'col': parseInt($widget.attr('data-col'), 10),
+ 'row': parseInt($widget.attr('data-row'), 10),
+ 'size_x': parseInt($widget.attr('data-sizex'), 10) || 1,
+ 'size_y': parseInt($widget.attr('data-sizey'), 10) || 1,
+ 'max_size_x': parseInt($widget.attr('data-max-sizex'), 10) || false,
+ 'max_size_y': parseInt($widget.attr('data-max-sizey'), 10) || false,
+ 'min_size_x': parseInt($widget.attr('data-min-sizex'), 10) || false,
+ 'min_size_y': parseInt($widget.attr('data-min-sizey'), 10) || false,
+ 'el': $widget
+ };
+ };
+
+
+ /**
+ * Creates the grid coords object representing the widget an add it to the
+ * mapped array of positions.
+ *
+ * @method register_widget
+ * @param {HTMLElement|Object} $el jQuery wrapped HTMLElement representing
+ * the widget, or an "widget grid data" Object with (col, row, el ...).
+ * @return {Boolean} Returns true if the widget final position is different
+ * than the original.
+ */
+ fn.register_widget = function($el) {
+ var isDOM = $el instanceof jQuery;
+ var wgd = isDOM ? this.dom_to_coords($el) : $el;
+ var posChanged = false;
+ isDOM || ($el = wgd.el);
+
+ var empty_upper_row = this.can_go_widget_up(wgd);
+ if (empty_upper_row) {
+ wgd.row = empty_upper_row;
+ $el.attr('data-row', empty_upper_row);
+ this.$el.trigger('gridster:positionchanged', [wgd]);
+ posChanged = true;
+ }
+
+ if (this.options.avoid_overlapped_widgets &&
+ !this.can_move_to(
+ {size_x: wgd.size_x, size_y: wgd.size_y}, wgd.col, wgd.row)
+ ) {
+ $.extend(wgd, this.next_position(wgd.size_x, wgd.size_y));
+ $el.attr({
+ 'data-col': wgd.col,
+ 'data-row': wgd.row,
+ 'data-sizex': wgd.size_x,
+ 'data-sizey': wgd.size_y
+ });
+ posChanged = true;
+ }
+
+ // attach Coord object to player data-coord attribute
+ $el.data('coords', $el.coords());
+ // Extend Coord object with grid position info
+ $el.data('coords').grid = wgd;
+
+ this.add_to_gridmap(wgd, $el);
+
+ this.options.resize.enabled && this.add_resize_handle($el);
+
+ return posChanged;
+ };
+
+
+ /**
+ * Update in the mapped array of positions the value of cells represented by
+ * the grid coords object passed in the `grid_data` param.
+ *
+ * @param {Object} grid_data The grid coords object representing the cells
+ * to update in the mapped array.
+ * @param {HTMLElement|Boolean} value Pass `false` or the jQuery wrapped
+ * HTMLElement, depends if you want to delete an existing position or add
+ * a new one.
+ * @method update_widget_position
+ * @return {Class} Returns the instance of the Gridster Class.
+ */
+ fn.update_widget_position = function(grid_data, value) {
+ this.for_each_cell_occupied(grid_data, function(col, row) {
+ if (!this.gridmap[col]) { return this; }
+ this.gridmap[col][row] = value;
+ });
+ return this;
+ };
+
+
+ /**
+ * Remove a widget from the mapped array of positions.
+ *
+ * @method remove_from_gridmap
+ * @param {Object} grid_data The grid coords object representing the cells
+ * to update in the mapped array.
+ * @return {Class} Returns the instance of the Gridster Class.
+ */
+ fn.remove_from_gridmap = function(grid_data) {
+ return this.update_widget_position(grid_data, false);
+ };
+
+
+ /**
+ * Add a widget to the mapped array of positions.
+ *
+ * @method add_to_gridmap
+ * @param {Object} grid_data The grid coords object representing the cells
+ * to update in the mapped array.
+ * @param {HTMLElement|Boolean} value The value to set in the specified
+ * position .
+ * @return {Class} Returns the instance of the Gridster Class.
+ */
+ fn.add_to_gridmap = function(grid_data, value) {
+ this.update_widget_position(grid_data, value || grid_data.el);
+
+ if (grid_data.el) {
+ var $widgets = this.widgets_below(grid_data.el);
+ $widgets.each($.proxy(function(i, widget) {
+ this.move_widget_up( $(widget));
+ }, this));
+ }
+ };
+
+
+ /**
+ * Make widgets draggable.
+ *
+ * @uses Draggable
+ * @method draggable
+ * @return {Class} Returns the instance of the Gridster Class.
+ */
+ fn.draggable = function() {
+ var self = this;
+ var draggable_options = $.extend(true, {}, this.options.draggable, {
+ offset_left: this.options.widget_margins[0],
+ offset_top: this.options.widget_margins[1],
+ container_width: this.cols * this.min_widget_width,
+ limit: true,
+ start: function(event, ui) {
+ self.$widgets.filter('.player-revert')
+ .removeClass('player-revert');
+
+ self.$player = $(this);
+ self.$helper = $(ui.$helper);
+
+ self.helper = !self.$helper.is(self.$player);
+
+ self.on_start_drag.call(self, event, ui);
+ self.$el.trigger('gridster:dragstart');
+ },
+ stop: function(event, ui) {
+ self.on_stop_drag.call(self, event, ui);
+ self.$el.trigger('gridster:dragstop');
+ },
+ drag: throttle(function(event, ui) {
+ self.on_drag.call(self, event, ui);
+ self.$el.trigger('gridster:drag');
+ }, 60)
+ });
+
+ this.drag_api = this.$el.drag(draggable_options);
+ return this;
+ };
+
+
+ /**
+ * Bind resize events to get resize working.
+ *
+ * @method resizable
+ * @return {Class} Returns instance of gridster Class.
+ */
+ fn.resizable = function() {
+ this.resize_api = this.$el.drag({
+ items: '.' + this.options.resize.handle_class,
+ offset_left: this.options.widget_margins[0],
+ container_width: this.container_width,
+ move_element: false,
+ resize: true,
+ limit: this.options.autogrow_cols ? false : true,
+ start: $.proxy(this.on_start_resize, this),
+ stop: $.proxy(function(event, ui) {
+ delay($.proxy(function() {
+ this.on_stop_resize(event, ui);
+ }, this), 120);
+ }, this),
+ drag: throttle($.proxy(this.on_resize, this), 60)
+ });
+
+ return this;
+ };
+
+
+ /**
+ * Setup things required for resizing. Like build templates for drag handles.
+ *
+ * @method setup_resize
+ * @return {Class} Returns instance of gridster Class.
+ */
+ fn.setup_resize = function() {
+ this.resize_handle_class = this.options.resize.handle_class;
+ var axes = this.options.resize.axes;
+ var handle_tpl = '';
+
+ this.resize_handle_tpl = $.map(axes, function(type) {
+ return handle_tpl.replace('{type}', type);
+ }).join('');
+
+ if ($.isArray(this.options.draggable.ignore_dragging)) {
+ this.options.draggable.ignore_dragging.push(
+ '.' + this.resize_handle_class);
+ }
+
+ return this;
+ };
+
+
+ /**
+ * This function is executed when the player begins to be dragged.
+ *
+ * @method on_start_drag
+ * @param {Event} event The original browser event
+ * @param {Object} ui A prepared ui object with useful drag-related data
+ */
+ fn.on_start_drag = function(event, ui) {
+ this.$helper.add(this.$player).add(this.$wrapper).addClass('dragging');
+
+ this.highest_col = this.get_highest_occupied_cell().col;
+
+ this.$player.addClass('player');
+ this.player_grid_data = this.$player.coords().grid;
+ this.placeholder_grid_data = $.extend({}, this.player_grid_data);
+
+ this.set_dom_grid_height(this.$el.height() +
+ (this.player_grid_data.size_y * this.min_widget_height));
+
+ this.set_dom_grid_width(this.cols);
+
+ var pgd_sizex = this.player_grid_data.size_x;
+ var cols_diff = this.cols - this.highest_col;
+
+ if (this.options.autogrow_cols && cols_diff <= pgd_sizex) {
+ this.add_faux_cols(Math.min(pgd_sizex - cols_diff, 1));
+ }
+
+ var colliders = this.faux_grid;
+ var coords = this.$player.data('coords').coords;
+
+ this.cells_occupied_by_player = this.get_cells_occupied(
+ this.player_grid_data);
+ this.cells_occupied_by_placeholder = this.get_cells_occupied(
+ this.placeholder_grid_data);
+
+ this.last_cols = [];
+ this.last_rows = [];
+
+ // see jquery.collision.js
+ this.collision_api = this.$helper.collision(
+ colliders, this.options.collision);
+
+ this.$preview_holder = $('<' + this.$player.get(0).tagName + ' />', {
+ 'class': 'preview-holder',
+ 'data-row': this.$player.attr('data-row'),
+ 'data-col': this.$player.attr('data-col'),
+ css: {
+ width: coords.width,
+ height: coords.height
+ }
+ }).appendTo(this.$el);
+
+ if (this.options.draggable.start) {
+ this.options.draggable.start.call(this, event, ui);
+ }
+ };
+
+
+ /**
+ * This function is executed when the player is being dragged.
+ *
+ * @method on_drag
+ * @param {Event} event The original browser event
+ * @param {Object} ui A prepared ui object with useful drag-related data
+ */
+ fn.on_drag = function(event, ui) {
+ //break if dragstop has been fired
+ if (this.$player === null) {
+ return false;
+ }
+
+ var abs_offset = {
+ left: ui.position.left + this.baseX,
+ top: ui.position.top + this.baseY
+ };
+
+ // auto grow cols
+ if (this.options.autogrow_cols) {
+ var prcol = this.placeholder_grid_data.col +
+ this.placeholder_grid_data.size_x - 1;
+
+ // "- 1" due to adding at least 1 column in on_start_drag
+ if (prcol >= this.cols - 1 && this.options.max_cols >= this.cols + 1) {
+ this.add_faux_cols(1);
+ this.set_dom_grid_width(this.cols + 1);
+ this.drag_api.set_limits(this.container_width);
+ }
+
+ this.collision_api.set_colliders(this.faux_grid);
+ }
+
+ this.colliders_data = this.collision_api.get_closest_colliders(
+ abs_offset);
+
+ this.on_overlapped_column_change(
+ this.on_start_overlapping_column, this.on_stop_overlapping_column);
+
+ this.on_overlapped_row_change(
+ this.on_start_overlapping_row, this.on_stop_overlapping_row);
+
+
+ if (this.helper && this.$player) {
+ this.$player.css({
+ 'left': ui.position.left,
+ 'top': ui.position.top
+ });
+ }
+
+ if (this.options.draggable.drag) {
+ this.options.draggable.drag.call(this, event, ui);
+ }
+ };
+
+
+ /**
+ * This function is executed when the player stops being dragged.
+ *
+ * @method on_stop_drag
+ * @param {Event} event The original browser event
+ * @param {Object} ui A prepared ui object with useful drag-related data
+ */
+ fn.on_stop_drag = function(event, ui) {
+ this.$helper.add(this.$player).add(this.$wrapper)
+ .removeClass('dragging');
+
+ ui.position.left = ui.position.left + this.baseX;
+ ui.position.top = ui.position.top + this.baseY;
+ this.colliders_data = this.collision_api.get_closest_colliders(
+ ui.position);
+
+ this.on_overlapped_column_change(
+ this.on_start_overlapping_column,
+ this.on_stop_overlapping_column
+ );
+
+ this.on_overlapped_row_change(
+ this.on_start_overlapping_row,
+ this.on_stop_overlapping_row
+ );
+
+ this.$player.addClass('player-revert').removeClass('player')
+ .attr({
+ 'data-col': this.placeholder_grid_data.col,
+ 'data-row': this.placeholder_grid_data.row
+ }).css({
+ 'left': '',
+ 'top': ''
+ });
+
+ this.$changed = this.$changed.add(this.$player);
+
+ this.cells_occupied_by_player = this.get_cells_occupied(
+ this.placeholder_grid_data);
+ this.set_cells_player_occupies(
+ this.placeholder_grid_data.col, this.placeholder_grid_data.row);
+
+ this.$player.coords().grid.row = this.placeholder_grid_data.row;
+ this.$player.coords().grid.col = this.placeholder_grid_data.col;
+
+ if (this.options.draggable.stop) {
+ this.options.draggable.stop.call(this, event, ui);
+ }
+
+ this.$preview_holder.remove();
+
+ this.$player = null;
+ this.$helper = null;
+ this.placeholder_grid_data = {};
+ this.player_grid_data = {};
+ this.cells_occupied_by_placeholder = {};
+ this.cells_occupied_by_player = {};
+
+ this.set_dom_grid_height();
+ this.set_dom_grid_width();
+
+ if (this.options.autogrow_cols) {
+ this.drag_api.set_limits(this.cols * this.min_widget_width);
+ }
+ };
+
+
+ /**
+ * This function is executed every time a widget starts to be resized.
+ *
+ * @method on_start_resize
+ * @param {Event} event The original browser event
+ * @param {Object} ui A prepared ui object with useful drag-related data
+ */
+ fn.on_start_resize = function(event, ui) {
+ this.$resized_widget = ui.$player.closest('.gs-w');
+ this.resize_coords = this.$resized_widget.coords();
+ this.resize_wgd = this.resize_coords.grid;
+ this.resize_initial_width = this.resize_coords.coords.width;
+ this.resize_initial_height = this.resize_coords.coords.height;
+ this.resize_initial_sizex = this.resize_coords.grid.size_x;
+ this.resize_initial_sizey = this.resize_coords.grid.size_y;
+ this.resize_initial_col = this.resize_coords.grid.col;
+ this.resize_last_sizex = this.resize_initial_sizex;
+ this.resize_last_sizey = this.resize_initial_sizey;
+
+ this.resize_max_size_x = Math.min(this.resize_wgd.max_size_x ||
+ this.options.resize.max_size[0],
+ this.options.max_cols - this.resize_initial_col + 1);
+ this.resize_max_size_y = this.resize_wgd.max_size_y ||
+ this.options.resize.max_size[1];
+
+ this.resize_min_size_x = (this.resize_wgd.min_size_x ||
+ this.options.resize.min_size[0] || 1);
+ this.resize_min_size_y = (this.resize_wgd.min_size_y ||
+ this.options.resize.min_size[1] || 1);
+
+ this.resize_initial_last_col = this.get_highest_occupied_cell().col;
+
+ this.set_dom_grid_width(this.cols);
+
+ this.resize_dir = {
+ right: ui.$player.is('.' + this.resize_handle_class + '-x'),
+ bottom: ui.$player.is('.' + this.resize_handle_class + '-y')
+ };
+
+ this.$resized_widget.css({
+ 'min-width': this.options.widget_base_dimensions[0],
+ 'min-height': this.options.widget_base_dimensions[1]
+ });
+
+ var nodeName = this.$resized_widget.get(0).tagName;
+ this.$resize_preview_holder = $('<' + nodeName + ' />', {
+ 'class': 'preview-holder resize-preview-holder',
+ 'data-row': this.$resized_widget.attr('data-row'),
+ 'data-col': this.$resized_widget.attr('data-col'),
+ 'css': {
+ 'width': this.resize_initial_width,
+ 'height': this.resize_initial_height
+ }
+ }).appendTo(this.$el);
+
+ this.$resized_widget.addClass('resizing');
+
+ if (this.options.resize.start) {
+ this.options.resize.start.call(this, event, ui, this.$resized_widget);
+ }
+
+ this.$el.trigger('gridster:resizestart');
+ };
+
+
+ /**
+ * This function is executed every time a widget stops being resized.
+ *
+ * @method on_stop_resize
+ * @param {Event} event The original browser event
+ * @param {Object} ui A prepared ui object with useful drag-related data
+ */
+ fn.on_stop_resize = function(event, ui) {
+ this.$resized_widget
+ .removeClass('resizing')
+ .css({
+ 'width': '',
+ 'height': ''
+ });
+
+ delay($.proxy(function() {
+ this.$resize_preview_holder
+ .remove()
+ .css({
+ 'min-width': '',
+ 'min-height': ''
+ });
+
+ if (this.options.resize.stop) {
+ this.options.resize.stop.call(this, event, ui, this.$resized_widget);
+ }
+
+ this.$el.trigger('gridster:resizestop');
+ }, this), 300);
+
+ this.set_dom_grid_width();
+
+ if (this.options.autogrow_cols) {
+ this.drag_api.set_limits(this.cols * this.min_widget_width);
+ }
+ };
+
+
+ /**
+ * This function is executed when a widget is being resized.
+ *
+ * @method on_resize
+ * @param {Event} event The original browser event
+ * @param {Object} ui A prepared ui object with useful drag-related data
+ */
+ fn.on_resize = function(event, ui) {
+ var rel_x = (ui.pointer.diff_left);
+ var rel_y = (ui.pointer.diff_top);
+ var wbd_x = this.options.widget_base_dimensions[0];
+ var wbd_y = this.options.widget_base_dimensions[1];
+ var margin_x = this.options.widget_margins[0];
+ var margin_y = this.options.widget_margins[1];
+ var max_size_x = this.resize_max_size_x;
+ var min_size_x = this.resize_min_size_x;
+ var max_size_y = this.resize_max_size_y;
+ var min_size_y = this.resize_min_size_y;
+ var autogrow = this.options.autogrow_cols;
+ var width;
+ var max_width = Infinity;
+ var max_height = Infinity;
+
+ var inc_units_x = Math.ceil((rel_x / (wbd_x + margin_x * 2)) - 0.2);
+ var inc_units_y = Math.ceil((rel_y / (wbd_y + margin_y * 2)) - 0.2);
+
+ var size_x = Math.max(1, this.resize_initial_sizex + inc_units_x);
+ var size_y = Math.max(1, this.resize_initial_sizey + inc_units_y);
+
+ var max_cols = (this.container_width / this.min_widget_width) -
+ this.resize_initial_col + 1;
+ var limit_width = ((max_cols * this.min_widget_width) - margin_x * 2);
+
+ size_x = Math.max(Math.min(size_x, max_size_x), min_size_x);
+ size_x = Math.min(max_cols, size_x);
+ width = (max_size_x * wbd_x) + ((size_x - 1) * margin_x * 2);
+ max_width = Math.min(width, limit_width);
+ min_width = (min_size_x * wbd_x) + ((size_x - 1) * margin_x * 2);
+
+ size_y = Math.max(Math.min(size_y, max_size_y), min_size_y);
+ max_height = (max_size_y * wbd_y) + ((size_y - 1) * margin_y * 2);
+ min_height = (min_size_y * wbd_y) + ((size_y - 1) * margin_y * 2);
+
+ if (this.resize_dir.right) {
+ size_y = this.resize_initial_sizey;
+ } else if (this.resize_dir.bottom) {
+ size_x = this.resize_initial_sizex;
+ }
+
+ if (autogrow) {
+ var last_widget_col = this.resize_initial_col + size_x - 1;
+ if (autogrow && this.resize_initial_last_col <= last_widget_col) {
+ this.set_dom_grid_width(Math.max(last_widget_col + 1, this.cols));
+
+ if (this.cols < last_widget_col) {
+ this.add_faux_cols(last_widget_col - this.cols);
+ }
+ }
+ }
+
+ var css_props = {};
+ !this.resize_dir.bottom && (css_props.width = Math.max(Math.min(
+ this.resize_initial_width + rel_x, max_width), min_width));
+ !this.resize_dir.right && (css_props.height = Math.max(Math.min(
+ this.resize_initial_height + rel_y, max_height), min_height));
+
+ this.$resized_widget.css(css_props);
+
+ if (size_x !== this.resize_last_sizex ||
+ size_y !== this.resize_last_sizey) {
+
+ this.resize_widget(this.$resized_widget, size_x, size_y);
+ this.set_dom_grid_width(this.cols);
+
+ this.$resize_preview_holder.css({
+ 'width': '',
+ 'height': ''
+ }).attr({
+ 'data-row': this.$resized_widget.attr('data-row'),
+ 'data-sizex': size_x,
+ 'data-sizey': size_y
+ });
+ }
+
+ if (this.options.resize.resize) {
+ this.options.resize.resize.call(this, event, ui, this.$resized_widget);
+ }
+
+ this.$el.trigger('gridster:resize');
+
+ this.resize_last_sizex = size_x;
+ this.resize_last_sizey = size_y;
+ };
+
+
+ /**
+ * Executes the callbacks passed as arguments when a column begins to be
+ * overlapped or stops being overlapped.
+ *
+ * @param {Function} start_callback Function executed when a new column
+ * begins to be overlapped. The column is passed as first argument.
+ * @param {Function} stop_callback Function executed when a column stops
+ * being overlapped. The column is passed as first argument.
+ * @method on_overlapped_column_change
+ * @return {Class} Returns the instance of the Gridster Class.
+ */
+ fn.on_overlapped_column_change = function(start_callback, stop_callback) {
+ if (!this.colliders_data.length) {
+ return this;
+ }
+ var cols = this.get_targeted_columns(
+ this.colliders_data[0].el.data.col);
+
+ var last_n_cols = this.last_cols.length;
+ var n_cols = cols.length;
+ var i;
+
+ for (i = 0; i < n_cols; i++) {
+ if ($.inArray(cols[i], this.last_cols) === -1) {
+ (start_callback || $.noop).call(this, cols[i]);
+ }
+ }
+
+ for (i = 0; i< last_n_cols; i++) {
+ if ($.inArray(this.last_cols[i], cols) === -1) {
+ (stop_callback || $.noop).call(this, this.last_cols[i]);
+ }
+ }
+
+ this.last_cols = cols;
+
+ return this;
+ };
+
+
+ /**
+ * Executes the callbacks passed as arguments when a row starts to be
+ * overlapped or stops being overlapped.
+ *
+ * @param {Function} start_callback Function executed when a new row begins
+ * to be overlapped. The row is passed as first argument.
+ * @param {Function} end_callback Function executed when a row stops being
+ * overlapped. The row is passed as first argument.
+ * @method on_overlapped_row_change
+ * @return {Class} Returns the instance of the Gridster Class.
+ */
+ fn.on_overlapped_row_change = function(start_callback, end_callback) {
+ if (!this.colliders_data.length) {
+ return this;
+ }
+ var rows = this.get_targeted_rows(this.colliders_data[0].el.data.row);
+ var last_n_rows = this.last_rows.length;
+ var n_rows = rows.length;
+ var i;
+
+ for (i = 0; i < n_rows; i++) {
+ if ($.inArray(rows[i], this.last_rows) === -1) {
+ (start_callback || $.noop).call(this, rows[i]);
+ }
+ }
+
+ for (i = 0; i < last_n_rows; i++) {
+ if ($.inArray(this.last_rows[i], rows) === -1) {
+ (end_callback || $.noop).call(this, this.last_rows[i]);
+ }
+ }
+
+ this.last_rows = rows;
+ };
+
+
+ /**
+ * Sets the current position of the player
+ *
+ * @param {Number} col
+ * @param {Number} row
+ * @param {Boolean} no_player
+ * @method set_player
+ * @return {object}
+ */
+ fn.set_player = function(col, row, no_player) {
+ var self = this;
+ if (!no_player) {
+ this.empty_cells_player_occupies();
+ }
+ var cell = !no_player ? self.colliders_data[0].el.data : {col: col};
+ var to_col = cell.col;
+ var to_row = row || cell.row;
+
+ this.player_grid_data = {
+ col: to_col,
+ row: to_row,
+ size_y : this.player_grid_data.size_y,
+ size_x : this.player_grid_data.size_x
+ };
+
+ this.cells_occupied_by_player = this.get_cells_occupied(
+ this.player_grid_data);
+
+ var $overlapped_widgets = this.get_widgets_overlapped(
+ this.player_grid_data);
+
+ var constraints = this.widgets_constraints($overlapped_widgets);
+
+ this.manage_movements(constraints.can_go_up, to_col, to_row);
+ this.manage_movements(constraints.can_not_go_up, to_col, to_row);
+
+ /* if there is not widgets overlapping in the new player position,
+ * update the new placeholder position. */
+ if (!$overlapped_widgets.length) {
+ var pp = this.can_go_player_up(this.player_grid_data);
+ if (pp !== false) {
+ to_row = pp;
+ }
+ this.set_placeholder(to_col, to_row);
+ }
+
+ return {
+ col: to_col,
+ row: to_row
+ };
+ };
+
+
+ /**
+ * See which of the widgets in the $widgets param collection can go to
+ * a upper row and which not.
+ *
+ * @method widgets_contraints
+ * @param {jQuery} $widgets A jQuery wrapped collection of
+ * HTMLElements.
+ * @return {object} Returns a literal Object with two keys: `can_go_up` &
+ * `can_not_go_up`. Each contains a set of HTMLElements.
+ */
+ fn.widgets_constraints = function($widgets) {
+ var $widgets_can_go_up = $([]);
+ var $widgets_can_not_go_up;
+ var wgd_can_go_up = [];
+ var wgd_can_not_go_up = [];
+
+ $widgets.each($.proxy(function(i, w) {
+ var $w = $(w);
+ var wgd = $w.coords().grid;
+ if (this.can_go_widget_up(wgd)) {
+ $widgets_can_go_up = $widgets_can_go_up.add($w);
+ wgd_can_go_up.push(wgd);
+ } else {
+ wgd_can_not_go_up.push(wgd);
+ }
+ }, this));
+
+ $widgets_can_not_go_up = $widgets.not($widgets_can_go_up);
+
+ return {
+ can_go_up: Gridster.sort_by_row_asc(wgd_can_go_up),
+ can_not_go_up: Gridster.sort_by_row_desc(wgd_can_not_go_up)
+ };
+ };
+
+
+ /**
+ * Sorts an Array of grid coords objects (representing the grid coords of
+ * each widget) in descending way.
+ *
+ * @method manage_movements
+ * @param {jQuery} $widgets A jQuery collection of HTMLElements
+ * representing the widgets you want to move.
+ * @param {Number} to_col The column to which we want to move the widgets.
+ * @param {Number} to_row The row to which we want to move the widgets.
+ * @return {Class} Returns the instance of the Gridster Class.
+ */
+ fn.manage_movements = function($widgets, to_col, to_row) {
+ $.each($widgets, $.proxy(function(i, w) {
+ var wgd = w;
+ var $w = wgd.el;
+
+ var can_go_widget_up = this.can_go_widget_up(wgd);
+
+ if (can_go_widget_up) {
+ //target CAN go up
+ //so move widget up
+ this.move_widget_to($w, can_go_widget_up);
+ this.set_placeholder(to_col, can_go_widget_up + wgd.size_y);
+
+ } else {
+ //target can't go up
+ var can_go_player_up = this.can_go_player_up(
+ this.player_grid_data);
+
+ if (!can_go_player_up) {
+ // target can't go up
+ // player cant't go up
+ // so we need to move widget down to a position that dont
+ // overlaps player
+ var y = (to_row + this.player_grid_data.size_y) - wgd.row;
+
+ this.move_widget_down($w, y);
+ this.set_placeholder(to_col, to_row);
+ }
+ }
+ }, this));
+
+ return this;
+ };
+
+ /**
+ * Determines if there is a widget in the row and col given. Or if the
+ * HTMLElement passed as first argument is the player.
+ *
+ * @method is_player
+ * @param {Number|HTMLElement} col_or_el A jQuery wrapped collection of
+ * HTMLElements.
+ * @param {Number} [row] The column to which we want to move the widgets.
+ * @return {Boolean} Returns true or false.
+ */
+ fn.is_player = function(col_or_el, row) {
+ if (row && !this.gridmap[col_or_el]) { return false; }
+ var $w = row ? this.gridmap[col_or_el][row] : col_or_el;
+ return $w && ($w.is(this.$player) || $w.is(this.$helper));
+ };
+
+
+ /**
+ * Determines if the widget that is being dragged is currently over the row
+ * and col given.
+ *
+ * @method is_player_in
+ * @param {Number} col The column to check.
+ * @param {Number} row The row to check.
+ * @return {Boolean} Returns true or false.
+ */
+ fn.is_player_in = function(col, row) {
+ var c = this.cells_occupied_by_player || {};
+ return $.inArray(col, c.cols) >= 0 && $.inArray(row, c.rows) >= 0;
+ };
+
+
+ /**
+ * Determines if the placeholder is currently over the row and col given.
+ *
+ * @method is_placeholder_in
+ * @param {Number} col The column to check.
+ * @param {Number} row The row to check.
+ * @return {Boolean} Returns true or false.
+ */
+ fn.is_placeholder_in = function(col, row) {
+ var c = this.cells_occupied_by_placeholder || {};
+ return this.is_placeholder_in_col(col) && $.inArray(row, c.rows) >= 0;
+ };
+
+
+ /**
+ * Determines if the placeholder is currently over the column given.
+ *
+ * @method is_placeholder_in_col
+ * @param {Number} col The column to check.
+ * @return {Boolean} Returns true or false.
+ */
+ fn.is_placeholder_in_col = function(col) {
+ var c = this.cells_occupied_by_placeholder || [];
+ return $.inArray(col, c.cols) >= 0;
+ };
+
+
+ /**
+ * Determines if the cell represented by col and row params is empty.
+ *
+ * @method is_empty
+ * @param {Number} col The column to check.
+ * @param {Number} row The row to check.
+ * @return {Boolean} Returns true or false.
+ */
+ fn.is_empty = function(col, row) {
+ if (typeof this.gridmap[col] !== 'undefined') {
+ if(typeof this.gridmap[col][row] !== 'undefined' &&
+ this.gridmap[col][row] === false
+ ) {
+ return true;
+ }
+ return false;
+ }
+ return true;
+ };
+
+
+ /**
+ * Determines if the cell represented by col and row params is occupied.
+ *
+ * @method is_occupied
+ * @param {Number} col The column to check.
+ * @param {Number} row The row to check.
+ * @return {Boolean} Returns true or false.
+ */
+ fn.is_occupied = function(col, row) {
+ if (!this.gridmap[col]) {
+ return false;
+ }
+
+ if (this.gridmap[col][row]) {
+ return true;
+ }
+ return false;
+ };
+
+
+ /**
+ * Determines if there is a widget in the cell represented by col/row params.
+ *
+ * @method is_widget
+ * @param {Number} col The column to check.
+ * @param {Number} row The row to check.
+ * @return {Boolean|HTMLElement} Returns false if there is no widget,
+ * else returns the jQuery HTMLElement
+ */
+ fn.is_widget = function(col, row) {
+ var cell = this.gridmap[col];
+ if (!cell) {
+ return false;
+ }
+
+ cell = cell[row];
+
+ if (cell) {
+ return cell;
+ }
+
+ return false;
+ };
+
+
+ /**
+ * Determines if there is a widget in the cell represented by col/row
+ * params and if this is under the widget that is being dragged.
+ *
+ * @method is_widget_under_player
+ * @param {Number} col The column to check.
+ * @param {Number} row The row to check.
+ * @return {Boolean} Returns true or false.
+ */
+ fn.is_widget_under_player = function(col, row) {
+ if (this.is_widget(col, row)) {
+ return this.is_player_in(col, row);
+ }
+ return false;
+ };
+
+
+ /**
+ * Get widgets overlapping with the player or with the object passed
+ * representing the grid cells.
+ *
+ * @method get_widgets_under_player
+ * @return {HTMLElement} Returns a jQuery collection of HTMLElements
+ */
+ fn.get_widgets_under_player = function(cells) {
+ cells || (cells = this.cells_occupied_by_player || {cols: [], rows: []});
+ var $widgets = $([]);
+
+ $.each(cells.cols, $.proxy(function(i, col) {
+ $.each(cells.rows, $.proxy(function(i, row) {
+ if(this.is_widget(col, row)) {
+ $widgets = $widgets.add(this.gridmap[col][row]);
+ }
+ }, this));
+ }, this));
+
+ return $widgets;
+ };
+
+
+ /**
+ * Put placeholder at the row and column specified.
+ *
+ * @method set_placeholder
+ * @param {Number} col The column to which we want to move the
+ * placeholder.
+ * @param {Number} row The row to which we want to move the
+ * placeholder.
+ * @return {Class} Returns the instance of the Gridster Class.
+ */
+ fn.set_placeholder = function(col, row) {
+ var phgd = $.extend({}, this.placeholder_grid_data);
+ var $nexts = this.widgets_below({
+ col: phgd.col,
+ row: phgd.row,
+ size_y: phgd.size_y,
+ size_x: phgd.size_x
+ });
+
+ // Prevents widgets go out of the grid
+ var right_col = (col + phgd.size_x - 1);
+ if (right_col > this.cols) {
+ col = col - (right_col - col);
+ }
+
+ var moved_down = this.placeholder_grid_data.row < row;
+ var changed_column = this.placeholder_grid_data.col !== col;
+
+ this.placeholder_grid_data.col = col;
+ this.placeholder_grid_data.row = row;
+
+ this.cells_occupied_by_placeholder = this.get_cells_occupied(
+ this.placeholder_grid_data);
+
+ this.$preview_holder.attr({
+ 'data-row' : row,
+ 'data-col' : col
+ });
+
+ if (moved_down || changed_column) {
+ $nexts.each($.proxy(function(i, widget) {
+ this.move_widget_up(
+ $(widget), this.placeholder_grid_data.col - col + phgd.size_y);
+ }, this));
+ }
+
+ var $widgets_under_ph = this.get_widgets_under_player(
+ this.cells_occupied_by_placeholder);
+
+ if ($widgets_under_ph.length) {
+ $widgets_under_ph.each($.proxy(function(i, widget) {
+ var $w = $(widget);
+ this.move_widget_down(
+ $w, row + phgd.size_y - $w.data('coords').grid.row);
+ }, this));
+ }
+
+ };
+
+
+ /**
+ * Determines whether the player can move to a position above.
+ *
+ * @method can_go_player_up
+ * @param {Object} widget_grid_data The actual grid coords object of the
+ * player.
+ * @return {Number|Boolean} If the player can be moved to an upper row
+ * returns the row number, else returns false.
+ */
+ fn.can_go_player_up = function(widget_grid_data) {
+ var p_bottom_row = widget_grid_data.row + widget_grid_data.size_y - 1;
+ var result = true;
+ var upper_rows = [];
+ var min_row = 10000;
+ var $widgets_under_player = this.get_widgets_under_player();
+
+ /* generate an array with columns as index and array with upper rows
+ * empty as value */
+ this.for_each_column_occupied(widget_grid_data, function(tcol) {
+ var grid_col = this.gridmap[tcol];
+ var r = p_bottom_row + 1;
+ upper_rows[tcol] = [];
+
+ while (--r > 0) {
+ if (this.is_empty(tcol, r) || this.is_player(tcol, r) ||
+ this.is_widget(tcol, r) &&
+ grid_col[r].is($widgets_under_player)
+ ) {
+ upper_rows[tcol].push(r);
+ min_row = r < min_row ? r : min_row;
+ } else {
+ break;
+ }
+ }
+
+ if (upper_rows[tcol].length === 0) {
+ result = false;
+ return true; //break
+ }
+
+ upper_rows[tcol].sort(function(a, b) {
+ return a - b;
+ });
+ });
+
+ if (!result) { return false; }
+
+ return this.get_valid_rows(widget_grid_data, upper_rows, min_row);
+ };
+
+
+ /**
+ * Determines whether a widget can move to a position above.
+ *
+ * @method can_go_widget_up
+ * @param {Object} widget_grid_data The actual grid coords object of the
+ * widget we want to check.
+ * @return {Number|Boolean} If the widget can be moved to an upper row
+ * returns the row number, else returns false.
+ */
+ fn.can_go_widget_up = function(widget_grid_data) {
+ var p_bottom_row = widget_grid_data.row + widget_grid_data.size_y - 1;
+ var result = true;
+ var upper_rows = [];
+ var min_row = 10000;
+
+ /* generate an array with columns as index and array with topmost rows
+ * empty as value */
+ this.for_each_column_occupied(widget_grid_data, function(tcol) {
+ var grid_col = this.gridmap[tcol];
+ upper_rows[tcol] = [];
+
+ var r = p_bottom_row + 1;
+ // iterate over each row
+ while (--r > 0) {
+ if (this.is_widget(tcol, r) && !this.is_player_in(tcol, r)) {
+ if (!grid_col[r].is(widget_grid_data.el)) {
+ break;
+ }
+ }
+
+ if (!this.is_player(tcol, r) &&
+ !this.is_placeholder_in(tcol, r) &&
+ !this.is_player_in(tcol, r)) {
+ upper_rows[tcol].push(r);
+ }
+
+ if (r < min_row) {
+ min_row = r;
+ }
+ }
+
+ if (upper_rows[tcol].length === 0) {
+ result = false;
+ return true; //break
+ }
+
+ upper_rows[tcol].sort(function(a, b) {
+ return a - b;
+ });
+ });
+
+ if (!result) { return false; }
+
+ return this.get_valid_rows(widget_grid_data, upper_rows, min_row);
+ };
+
+
+ /**
+ * Search a valid row for the widget represented by `widget_grid_data' in
+ * the `upper_rows` array. Iteration starts from row specified in `min_row`.
+ *
+ * @method get_valid_rows
+ * @param {Object} widget_grid_data The actual grid coords object of the
+ * player.
+ * @param {Array} upper_rows An array with columns as index and arrays
+ * of valid rows as values.
+ * @param {Number} min_row The upper row from which the iteration will start.
+ * @return {Number|Boolean} Returns the upper row valid from the `upper_rows`
+ * for the widget in question.
+ */
+ fn.get_valid_rows = function(widget_grid_data, upper_rows, min_row) {
+ var p_top_row = widget_grid_data.row;
+ var p_bottom_row = widget_grid_data.row + widget_grid_data.size_y - 1;
+ var size_y = widget_grid_data.size_y;
+ var r = min_row - 1;
+ var valid_rows = [];
+
+ while (++r <= p_bottom_row ) {
+ var common = true;
+ $.each(upper_rows, function(col, rows) {
+ if ($.isArray(rows) && $.inArray(r, rows) === -1) {
+ common = false;
+ }
+ });
+
+ if (common === true) {
+ valid_rows.push(r);
+ if (valid_rows.length === size_y) {
+ break;
+ }
+ }
+ }
+
+ var new_row = false;
+ if (size_y === 1) {
+ if (valid_rows[0] !== p_top_row) {
+ new_row = valid_rows[0] || false;
+ }
+ } else {
+ if (valid_rows[0] !== p_top_row) {
+ new_row = this.get_consecutive_numbers_index(
+ valid_rows, size_y);
+ }
+ }
+
+ return new_row;
+ };
+
+
+ fn.get_consecutive_numbers_index = function(arr, size_y) {
+ var max = arr.length;
+ var result = [];
+ var first = true;
+ var prev = -1; // or null?
+
+ for (var i=0; i < max; i++) {
+ if (first || arr[i] === prev + 1) {
+ result.push(i);
+ if (result.length === size_y) {
+ break;
+ }
+ first = false;
+ } else {
+ result = [];
+ first = true;
+ }
+
+ prev = arr[i];
+ }
+
+ return result.length >= size_y ? arr[result[0]] : false;
+ };
+
+
+ /**
+ * Get widgets overlapping with the player.
+ *
+ * @method get_widgets_overlapped
+ * @return {jQuery} Returns a jQuery collection of HTMLElements.
+ */
+ fn.get_widgets_overlapped = function() {
+ var $w;
+ var $widgets = $([]);
+ var used = [];
+ var rows_from_bottom = this.cells_occupied_by_player.rows.slice(0);
+ rows_from_bottom.reverse();
+
+ $.each(this.cells_occupied_by_player.cols, $.proxy(function(i, col) {
+ $.each(rows_from_bottom, $.proxy(function(i, row) {
+ // if there is a widget in the player position
+ if (!this.gridmap[col]) { return true; } //next iteration
+ var $w = this.gridmap[col][row];
+ if (this.is_occupied(col, row) && !this.is_player($w) &&
+ $.inArray($w, used) === -1
+ ) {
+ $widgets = $widgets.add($w);
+ used.push($w);
+ }
+
+ }, this));
+ }, this));
+
+ return $widgets;
+ };
+
+
+ /**
+ * This callback is executed when the player begins to collide with a column.
+ *
+ * @method on_start_overlapping_column
+ * @param {Number} col The collided column.
+ * @return {jQuery} Returns a jQuery collection of HTMLElements.
+ */
+ fn.on_start_overlapping_column = function(col) {
+ this.set_player(col, false);
+ };
+
+
+ /**
+ * A callback executed when the player begins to collide with a row.
+ *
+ * @method on_start_overlapping_row
+ * @param {Number} row The collided row.
+ * @return {jQuery} Returns a jQuery collection of HTMLElements.
+ */
+ fn.on_start_overlapping_row = function(row) {
+ this.set_player(false, row);
+ };
+
+
+ /**
+ * A callback executed when the the player ends to collide with a column.
+ *
+ * @method on_stop_overlapping_column
+ * @param {Number} col The collided row.
+ * @return {jQuery} Returns a jQuery collection of HTMLElements.
+ */
+ fn.on_stop_overlapping_column = function(col) {
+ this.set_player(col, false);
+
+ var self = this;
+ this.for_each_widget_below(col, this.cells_occupied_by_player.rows[0],
+ function(tcol, trow) {
+ self.move_widget_up(this, self.player_grid_data.size_y);
+ });
+ };
+
+
+ /**
+ * This callback is executed when the player ends to collide with a row.
+ *
+ * @method on_stop_overlapping_row
+ * @param {Number} row The collided row.
+ * @return {jQuery} Returns a jQuery collection of HTMLElements.
+ */
+ fn.on_stop_overlapping_row = function(row) {
+ this.set_player(false, row);
+
+ var self = this;
+ var cols = this.cells_occupied_by_player.cols;
+ for (var c = 0, cl = cols.length; c < cl; c++) {
+ this.for_each_widget_below(cols[c], row, function(tcol, trow) {
+ self.move_widget_up(this, self.player_grid_data.size_y);
+ });
+ }
+ };
+
+
+ /**
+ * Move a widget to a specific row. The cell or cells must be empty.
+ * If the widget has widgets below, all of these widgets will be moved also
+ * if they can.
+ *
+ * @method move_widget_to
+ * @param {HTMLElement} $widget The jQuery wrapped HTMLElement of the
+ * widget is going to be moved.
+ * @return {Class} Returns the instance of the Gridster Class.
+ */
+ fn.move_widget_to = function($widget, row) {
+ var self = this;
+ var widget_grid_data = $widget.coords().grid;
+ var diff = row - widget_grid_data.row;
+ var $next_widgets = this.widgets_below($widget);
+
+ var can_move_to_new_cell = this.can_move_to(
+ widget_grid_data, widget_grid_data.col, row, $widget);
+
+ if (can_move_to_new_cell === false) {
+ return false;
+ }
+
+ this.remove_from_gridmap(widget_grid_data);
+ widget_grid_data.row = row;
+ this.add_to_gridmap(widget_grid_data);
+ $widget.attr('data-row', row);
+ this.$changed = this.$changed.add($widget);
+
+
+ $next_widgets.each(function(i, widget) {
+ var $w = $(widget);
+ var wgd = $w.coords().grid;
+ var can_go_up = self.can_go_widget_up(wgd);
+ if (can_go_up && can_go_up !== wgd.row) {
+ self.move_widget_to($w, can_go_up);
+ }
+ });
+
+ return this;
+ };
+
+
+ /**
+ * Move up the specified widget and all below it.
+ *
+ * @method move_widget_up
+ * @param {HTMLElement} $widget The widget you want to move.
+ * @param {Number} [y_units] The number of cells that the widget has to move.
+ * @return {Class} Returns the instance of the Gridster Class.
+ */
+ fn.move_widget_up = function($widget, y_units) {
+ var el_grid_data = $widget.coords().grid;
+ var actual_row = el_grid_data.row;
+ var moved = [];
+ var can_go_up = true;
+ y_units || (y_units = 1);
+
+ if (!this.can_go_up($widget)) { return false; } //break;
+
+ this.for_each_column_occupied(el_grid_data, function(col) {
+ // can_go_up
+ if ($.inArray($widget, moved) === -1) {
+ var widget_grid_data = $widget.coords().grid;
+ var next_row = actual_row - y_units;
+ next_row = this.can_go_up_to_row(
+ widget_grid_data, col, next_row);
+
+ if (!next_row) {
+ return true;
+ }
+
+ var $next_widgets = this.widgets_below($widget);
+
+ this.remove_from_gridmap(widget_grid_data);
+ widget_grid_data.row = next_row;
+ this.add_to_gridmap(widget_grid_data);
+ $widget.attr('data-row', widget_grid_data.row);
+ this.$changed = this.$changed.add($widget);
+
+ moved.push($widget);
+
+ $next_widgets.each($.proxy(function(i, widget) {
+ this.move_widget_up($(widget), y_units);
+ }, this));
+ }
+ });
+
+ };
+
+
+ /**
+ * Move down the specified widget and all below it.
+ *
+ * @method move_widget_down
+ * @param {jQuery} $widget The jQuery object representing the widget
+ * you want to move.
+ * @param {Number} y_units The number of cells that the widget has to move.
+ * @return {Class} Returns the instance of the Gridster Class.
+ */
+ fn.move_widget_down = function($widget, y_units) {
+ var el_grid_data, actual_row, moved, y_diff;
+
+ if (y_units <= 0) { return false; }
+
+ el_grid_data = $widget.coords().grid;
+ actual_row = el_grid_data.row;
+ moved = [];
+ y_diff = y_units;
+
+ if (!$widget) { return false; }
+
+ if ($.inArray($widget, moved) === -1) {
+
+ var widget_grid_data = $widget.coords().grid;
+ var next_row = actual_row + y_units;
+ var $next_widgets = this.widgets_below($widget);
+
+ this.remove_from_gridmap(widget_grid_data);
+
+ $next_widgets.each($.proxy(function(i, widget) {
+ var $w = $(widget);
+ var wd = $w.coords().grid;
+ var tmp_y = this.displacement_diff(
+ wd, widget_grid_data, y_diff);
+
+ if (tmp_y > 0) {
+ this.move_widget_down($w, tmp_y);
+ }
+ }, this));
+
+ widget_grid_data.row = next_row;
+ this.update_widget_position(widget_grid_data, $widget);
+ $widget.attr('data-row', widget_grid_data.row);
+ this.$changed = this.$changed.add($widget);
+
+ moved.push($widget);
+ }
+ };
+
+
+ /**
+ * Check if the widget can move to the specified row, else returns the
+ * upper row possible.
+ *
+ * @method can_go_up_to_row
+ * @param {Number} widget_grid_data The current grid coords object of the
+ * widget.
+ * @param {Number} col The target column.
+ * @param {Number} row The target row.
+ * @return {Boolean|Number} Returns the row number if the widget can move
+ * to the target position, else returns false.
+ */
+ fn.can_go_up_to_row = function(widget_grid_data, col, row) {
+ var ga = this.gridmap;
+ var result = true;
+ var urc = []; // upper_rows_in_columns
+ var actual_row = widget_grid_data.row;
+ var r;
+
+ /* generate an array with columns as index and array with
+ * upper rows empty in the column */
+ this.for_each_column_occupied(widget_grid_data, function(tcol) {
+ var grid_col = ga[tcol];
+ urc[tcol] = [];
+
+ r = actual_row;
+ while (r--) {
+ if (this.is_empty(tcol, r) &&
+ !this.is_placeholder_in(tcol, r)
+ ) {
+ urc[tcol].push(r);
+ } else {
+ break;
+ }
+ }
+
+ if (!urc[tcol].length) {
+ result = false;
+ return true;
+ }
+
+ });
+
+ if (!result) { return false; }
+
+ /* get common rows starting from upper position in all the columns
+ * that widget occupies */
+ r = row;
+ for (r = 1; r < actual_row; r++) {
+ var common = true;
+
+ for (var uc = 0, ucl = urc.length; uc < ucl; uc++) {
+ if (urc[uc] && $.inArray(r, urc[uc]) === -1) {
+ common = false;
+ }
+ }
+
+ if (common === true) {
+ result = r;
+ break;
+ }
+ }
+
+ return result;
+ };
+
+
+ fn.displacement_diff = function(widget_grid_data, parent_bgd, y_units) {
+ var actual_row = widget_grid_data.row;
+ var diffs = [];
+ var parent_max_y = parent_bgd.row + parent_bgd.size_y;
+
+ this.for_each_column_occupied(widget_grid_data, function(col) {
+ var temp_y_units = 0;
+
+ for (var r = parent_max_y; r < actual_row; r++) {
+ if (this.is_empty(col, r)) {
+ temp_y_units = temp_y_units + 1;
+ }
+ }
+
+ diffs.push(temp_y_units);
+ });
+
+ var max_diff = Math.max.apply(Math, diffs);
+ y_units = (y_units - max_diff);
+
+ return y_units > 0 ? y_units : 0;
+ };
+
+
+ /**
+ * Get widgets below a widget.
+ *
+ * @method widgets_below
+ * @param {HTMLElement} $el The jQuery wrapped HTMLElement.
+ * @return {jQuery} A jQuery collection of HTMLElements.
+ */
+ fn.widgets_below = function($el) {
+ var el_grid_data = $.isPlainObject($el) ? $el : $el.coords().grid;
+ var self = this;
+ var ga = this.gridmap;
+ var next_row = el_grid_data.row + el_grid_data.size_y - 1;
+ var $nexts = $([]);
+
+ this.for_each_column_occupied(el_grid_data, function(col) {
+ self.for_each_widget_below(col, next_row, function(tcol, trow) {
+ if (!self.is_player(this) && $.inArray(this, $nexts) === -1) {
+ $nexts = $nexts.add(this);
+ return true; // break
+ }
+ });
+ });
+
+ return Gridster.sort_by_row_asc($nexts);
+ };
+
+
+ /**
+ * Update the array of mapped positions with the new player position.
+ *
+ * @method set_cells_player_occupies
+ * @param {Number} col The new player col.
+ * @param {Number} col The new player row.
+ * @return {Class} Returns the instance of the Gridster Class.
+ */
+ fn.set_cells_player_occupies = function(col, row) {
+ this.remove_from_gridmap(this.placeholder_grid_data);
+ this.placeholder_grid_data.col = col;
+ this.placeholder_grid_data.row = row;
+ this.add_to_gridmap(this.placeholder_grid_data, this.$player);
+ return this;
+ };
+
+
+ /**
+ * Remove from the array of mapped positions the reference to the player.
+ *
+ * @method empty_cells_player_occupies
+ * @return {Class} Returns the instance of the Gridster Class.
+ */
+ fn.empty_cells_player_occupies = function() {
+ this.remove_from_gridmap(this.placeholder_grid_data);
+ return this;
+ };
+
+
+ fn.can_go_up = function($el) {
+ var el_grid_data = $el.coords().grid;
+ var initial_row = el_grid_data.row;
+ var prev_row = initial_row - 1;
+ var ga = this.gridmap;
+ var upper_rows_by_column = [];
+
+ var result = true;
+ if (initial_row === 1) { return false; }
+
+ this.for_each_column_occupied(el_grid_data, function(col) {
+ var $w = this.is_widget(col, prev_row);
+
+ if (this.is_occupied(col, prev_row) ||
+ this.is_player(col, prev_row) ||
+ this.is_placeholder_in(col, prev_row) ||
+ this.is_player_in(col, prev_row)
+ ) {
+ result = false;
+ return true; //break
+ }
+ });
+
+ return result;
+ };
+
+
+ /**
+ * Check if it's possible to move a widget to a specific col/row. It takes
+ * into account the dimensions (`size_y` and `size_x` attrs. of the grid
+ * coords object) the widget occupies.
+ *
+ * @method can_move_to
+ * @param {Object} widget_grid_data The grid coords object that represents
+ * the widget.
+ * @param {Object} col The col to check.
+ * @param {Object} row The row to check.
+ * @param {Number} [max_row] The max row allowed.
+ * @return {Boolean} Returns true if all cells are empty, else return false.
+ */
+ fn.can_move_to = function(widget_grid_data, col, row, max_row) {
+ var ga = this.gridmap;
+ var $w = widget_grid_data.el;
+ var future_wd = {
+ size_y: widget_grid_data.size_y,
+ size_x: widget_grid_data.size_x,
+ col: col,
+ row: row
+ };
+ var result = true;
+
+ //Prevents widgets go out of the grid
+ var right_col = col + widget_grid_data.size_x - 1;
+ if (right_col > this.cols) {
+ return false;
+ }
+
+ if (max_row && max_row < row + widget_grid_data.size_y - 1) {
+ return false;
+ }
+
+ this.for_each_cell_occupied(future_wd, function(tcol, trow) {
+ var $tw = this.is_widget(tcol, trow);
+ if ($tw && (!widget_grid_data.el || $tw.is($w))) {
+ result = false;
+ }
+ });
+
+ return result;
+ };
+
+
+ /**
+ * Given the leftmost column returns all columns that are overlapping
+ * with the player.
+ *
+ * @method get_targeted_columns
+ * @param {Number} [from_col] The leftmost column.
+ * @return {Array} Returns an array with column numbers.
+ */
+ fn.get_targeted_columns = function(from_col) {
+ var max = (from_col || this.player_grid_data.col) +
+ (this.player_grid_data.size_x - 1);
+ var cols = [];
+ for (var col = from_col; col <= max; col++) {
+ cols.push(col);
+ }
+ return cols;
+ };
+
+
+ /**
+ * Given the upper row returns all rows that are overlapping with the player.
+ *
+ * @method get_targeted_rows
+ * @param {Number} [from_row] The upper row.
+ * @return {Array} Returns an array with row numbers.
+ */
+ fn.get_targeted_rows = function(from_row) {
+ var max = (from_row || this.player_grid_data.row) +
+ (this.player_grid_data.size_y - 1);
+ var rows = [];
+ for (var row = from_row; row <= max; row++) {
+ rows.push(row);
+ }
+ return rows;
+ };
+
+ /**
+ * Get all columns and rows that a widget occupies.
+ *
+ * @method get_cells_occupied
+ * @param {Object} el_grid_data The grid coords object of the widget.
+ * @return {Object} Returns an object like `{ cols: [], rows: []}`.
+ */
+ fn.get_cells_occupied = function(el_grid_data) {
+ var cells = { cols: [], rows: []};
+ var i;
+ if (arguments[1] instanceof $) {
+ el_grid_data = arguments[1].coords().grid;
+ }
+
+ for (i = 0; i < el_grid_data.size_x; i++) {
+ var col = el_grid_data.col + i;
+ cells.cols.push(col);
+ }
+
+ for (i = 0; i < el_grid_data.size_y; i++) {
+ var row = el_grid_data.row + i;
+ cells.rows.push(row);
+ }
+
+ return cells;
+ };
+
+
+ /**
+ * Iterate over the cells occupied by a widget executing a function for
+ * each one.
+ *
+ * @method for_each_cell_occupied
+ * @param {Object} el_grid_data The grid coords object that represents the
+ * widget.
+ * @param {Function} callback The function to execute on each column
+ * iteration. Column and row are passed as arguments.
+ * @return {Class} Returns the instance of the Gridster Class.
+ */
+ fn.for_each_cell_occupied = function(grid_data, callback) {
+ this.for_each_column_occupied(grid_data, function(col) {
+ this.for_each_row_occupied(grid_data, function(row) {
+ callback.call(this, col, row);
+ });
+ });
+ return this;
+ };
+
+
+ /**
+ * Iterate over the columns occupied by a widget executing a function for
+ * each one.
+ *
+ * @method for_each_column_occupied
+ * @param {Object} el_grid_data The grid coords object that represents
+ * the widget.
+ * @param {Function} callback The function to execute on each column
+ * iteration. The column number is passed as first argument.
+ * @return {Class} Returns the instance of the Gridster Class.
+ */
+ fn.for_each_column_occupied = function(el_grid_data, callback) {
+ for (var i = 0; i < el_grid_data.size_x; i++) {
+ var col = el_grid_data.col + i;
+ callback.call(this, col, el_grid_data);
+ }
+ };
+
+
+ /**
+ * Iterate over the rows occupied by a widget executing a function for
+ * each one.
+ *
+ * @method for_each_row_occupied
+ * @param {Object} el_grid_data The grid coords object that represents
+ * the widget.
+ * @param {Function} callback The function to execute on each column
+ * iteration. The row number is passed as first argument.
+ * @return {Class} Returns the instance of the Gridster Class.
+ */
+ fn.for_each_row_occupied = function(el_grid_data, callback) {
+ for (var i = 0; i < el_grid_data.size_y; i++) {
+ var row = el_grid_data.row + i;
+ callback.call(this, row, el_grid_data);
+ }
+ };
+
+
+
+ fn._traversing_widgets = function(type, direction, col, row, callback) {
+ var ga = this.gridmap;
+ if (!ga[col]) { return; }
+
+ var cr, max;
+ var action = type + '/' + direction;
+ if (arguments[2] instanceof $) {
+ var el_grid_data = arguments[2].coords().grid;
+ col = el_grid_data.col;
+ row = el_grid_data.row;
+ callback = arguments[3];
+ }
+ var matched = [];
+ var trow = row;
+
+
+ var methods = {
+ 'for_each/above': function() {
+ while (trow--) {
+ if (trow > 0 && this.is_widget(col, trow) &&
+ $.inArray(ga[col][trow], matched) === -1
+ ) {
+ cr = callback.call(ga[col][trow], col, trow);
+ matched.push(ga[col][trow]);
+ if (cr) { break; }
+ }
+ }
+ },
+ 'for_each/below': function() {
+ for (trow = row + 1, max = ga[col].length; trow < max; trow++) {
+ if (this.is_widget(col, trow) &&
+ $.inArray(ga[col][trow], matched) === -1
+ ) {
+ cr = callback.call(ga[col][trow], col, trow);
+ matched.push(ga[col][trow]);
+ if (cr) { break; }
+ }
+ }
+ }
+ };
+
+ if (methods[action]) {
+ methods[action].call(this);
+ }
+ };
+
+
+ /**
+ * Iterate over each widget above the column and row specified.
+ *
+ * @method for_each_widget_above
+ * @param {Number} col The column to start iterating.
+ * @param {Number} row The row to start iterating.
+ * @param {Function} callback The function to execute on each widget
+ * iteration. The value of `this` inside the function is the jQuery
+ * wrapped HTMLElement.
+ * @return {Class} Returns the instance of the Gridster Class.
+ */
+ fn.for_each_widget_above = function(col, row, callback) {
+ this._traversing_widgets('for_each', 'above', col, row, callback);
+ return this;
+ };
+
+
+ /**
+ * Iterate over each widget below the column and row specified.
+ *
+ * @method for_each_widget_below
+ * @param {Number} col The column to start iterating.
+ * @param {Number} row The row to start iterating.
+ * @param {Function} callback The function to execute on each widget
+ * iteration. The value of `this` inside the function is the jQuery wrapped
+ * HTMLElement.
+ * @return {Class} Returns the instance of the Gridster Class.
+ */
+ fn.for_each_widget_below = function(col, row, callback) {
+ this._traversing_widgets('for_each', 'below', col, row, callback);
+ return this;
+ };
+
+
+ /**
+ * Returns the highest occupied cell in the grid.
+ *
+ * @method get_highest_occupied_cell
+ * @return {Object} Returns an object with `col` and `row` numbers.
+ */
+ fn.get_highest_occupied_cell = function() {
+ var r;
+ var gm = this.gridmap;
+ var rl = gm[1].length;
+ var rows = [], cols = [];
+ var row_in_col = [];
+ for (var c = gm.length - 1; c >= 1; c--) {
+ for (r = rl - 1; r >= 1; r--) {
+ if (this.is_widget(c, r)) {
+ rows.push(r);
+ cols.push(c);
+ break;
+ }
+ }
+ }
+
+ return {
+ col: Math.max.apply(Math, cols),
+ row: Math.max.apply(Math, rows)
+ };
+ };
+
+
+ fn.get_widgets_from = function(col, row) {
+ var ga = this.gridmap;
+ var $widgets = $();
+
+ if (col) {
+ $widgets = $widgets.add(
+ this.$widgets.filter(function() {
+ var tcol = $(this).attr('data-col');
+ return (tcol === col || tcol > col);
+ })
+ );
+ }
+
+ if (row) {
+ $widgets = $widgets.add(
+ this.$widgets.filter(function() {
+ var trow = $(this).attr('data-row');
+ return (trow === row || trow > row);
+ })
+ );
+ }
+
+ return $widgets;
+ };
+
+
+ /**
+ * Set the current height of the parent grid.
+ *
+ * @method set_dom_grid_height
+ * @return {Object} Returns the instance of the Gridster class.
+ */
+ fn.set_dom_grid_height = function(height) {
+ if (typeof height === 'undefined') {
+ var r = this.get_highest_occupied_cell().row;
+ height = r * this.min_widget_height;
+ }
+
+ this.container_height = height;
+ this.$el.css('height', this.container_height);
+ return this;
+ };
+
+ /**
+ * Set the current width of the parent grid.
+ *
+ * @method set_dom_grid_width
+ * @return {Object} Returns the instance of the Gridster class.
+ */
+ fn.set_dom_grid_width = function(cols) {
+ if (typeof cols === 'undefined') {
+ cols = this.get_highest_occupied_cell().col;
+ }
+
+ var max_cols = (this.options.autogrow_cols ? this.options.max_cols :
+ this.cols);
+
+ cols = Math.min(max_cols, Math.max(cols, this.options.min_cols));
+ this.container_width = cols * this.min_widget_width;
+ this.$el.css('width', this.container_width);
+ return this;
+ };
+
+
+ /**
+ * It generates the neccessary styles to position the widgets.
+ *
+ * @method generate_stylesheet
+ * @param {Number} rows Number of columns.
+ * @param {Number} cols Number of rows.
+ * @return {Object} Returns the instance of the Gridster class.
+ */
+ fn.generate_stylesheet = function(opts) {
+ var styles = '';
+ var max_size_x = this.options.max_size_x || this.cols;
+ var max_rows = 0;
+ var max_cols = 0;
+ var i;
+ var rules;
+
+ opts || (opts = {});
+ opts.cols || (opts.cols = this.cols);
+ opts.rows || (opts.rows = this.rows);
+ opts.namespace || (opts.namespace = this.options.namespace);
+ opts.widget_base_dimensions ||
+ (opts.widget_base_dimensions = this.options.widget_base_dimensions);
+ opts.widget_margins ||
+ (opts.widget_margins = this.options.widget_margins);
+ opts.min_widget_width = (opts.widget_margins[0] * 2) +
+ opts.widget_base_dimensions[0];
+ opts.min_widget_height = (opts.widget_margins[1] * 2) +
+ opts.widget_base_dimensions[1];
+
+ // don't duplicate stylesheets for the same configuration
+ var serialized_opts = $.param(opts);
+ if ($.inArray(serialized_opts, Gridster.generated_stylesheets) >= 0) {
+ return false;
+ }
+
+ this.generated_stylesheets.push(serialized_opts);
+ Gridster.generated_stylesheets.push(serialized_opts);
+
+ /* generate CSS styles for cols */
+ for (i = opts.cols; i >= 0; i--) {
+ styles += (opts.namespace + ' [data-col="'+ (i + 1) + '"] { left:' +
+ ((i * opts.widget_base_dimensions[0]) +
+ (i * opts.widget_margins[0]) +
+ ((i + 1) * opts.widget_margins[0])) + 'px; }\n');
+ }
+
+ /* generate CSS styles for rows */
+ for (i = opts.rows; i >= 0; i--) {
+ styles += (opts.namespace + ' [data-row="' + (i + 1) + '"] { top:' +
+ ((i * opts.widget_base_dimensions[1]) +
+ (i * opts.widget_margins[1]) +
+ ((i + 1) * opts.widget_margins[1]) ) + 'px; }\n');
+ }
+
+ for (var y = 1; y <= opts.rows; y++) {
+ styles += (opts.namespace + ' [data-sizey="' + y + '"] { height:' +
+ (y * opts.widget_base_dimensions[1] +
+ (y - 1) * (opts.widget_margins[1] * 2)) + 'px; }\n');
+ }
+
+ for (var x = 1; x <= max_size_x; x++) {
+ styles += (opts.namespace + ' [data-sizex="' + x + '"] { width:' +
+ (x * opts.widget_base_dimensions[0] +
+ (x - 1) * (opts.widget_margins[0] * 2)) + 'px; }\n');
+ }
+
+ this.remove_style_tags();
+
+ return this.add_style_tag(styles);
+ };
+
+
+ /**
+ * Injects the given CSS as string to the head of the document.
+ *
+ * @method add_style_tag
+ * @param {String} css The styles to apply.
+ * @return {Object} Returns the instance of the Gridster class.
+ */
+ fn.add_style_tag = function(css) {
+ var d = document;
+ var tag = d.createElement('style');
+
+ d.getElementsByTagName('head')[0].appendChild(tag);
+ tag.setAttribute('type', 'text/css');
+
+ if (tag.styleSheet) {
+ tag.styleSheet.cssText = css;
+ } else {
+ tag.appendChild(document.createTextNode(css));
+ }
+
+ this.$style_tags = this.$style_tags.add(tag);
+
+ return this;
+ };
+
+
+ /**
+ * Remove the style tag with the associated id from the head of the document
+ *
+ * @method remove_style_tag
+ * @return {Object} Returns the instance of the Gridster class.
+ */
+ fn.remove_style_tags = function() {
+ var all_styles = Gridster.generated_stylesheets;
+ var ins_styles = this.generated_stylesheets;
+
+ this.$style_tags.remove();
+
+ Gridster.generated_stylesheets = $.map(all_styles, function(s) {
+ if ($.inArray(s, ins_styles) === -1) { return s; }
+ });
+ };
+
+
+ /**
+ * Generates a faux grid to collide with it when a widget is dragged and
+ * detect row or column that we want to go.
+ *
+ * @method generate_faux_grid
+ * @param {Number} rows Number of columns.
+ * @param {Number} cols Number of rows.
+ * @return {Object} Returns the instance of the Gridster class.
+ */
+ fn.generate_faux_grid = function(rows, cols) {
+ this.faux_grid = [];
+ this.gridmap = [];
+ var col;
+ var row;
+ for (col = cols; col > 0; col--) {
+ this.gridmap[col] = [];
+ for (row = rows; row > 0; row--) {
+ this.add_faux_cell(row, col);
+ }
+ }
+ return this;
+ };
+
+
+ /**
+ * Add cell to the faux grid.
+ *
+ * @method add_faux_cell
+ * @param {Number} row The row for the new faux cell.
+ * @param {Number} col The col for the new faux cell.
+ * @return {Object} Returns the instance of the Gridster class.
+ */
+ fn.add_faux_cell = function(row, col) {
+ var coords = $({
+ left: this.baseX + ((col - 1) * this.min_widget_width),
+ top: this.baseY + (row -1) * this.min_widget_height,
+ width: this.min_widget_width,
+ height: this.min_widget_height,
+ col: col,
+ row: row,
+ original_col: col,
+ original_row: row
+ }).coords();
+
+ if (!$.isArray(this.gridmap[col])) {
+ this.gridmap[col] = [];
+ }
+
+ this.gridmap[col][row] = false;
+ this.faux_grid.push(coords);
+
+ return this;
+ };
+
+
+ /**
+ * Add rows to the faux grid.
+ *
+ * @method add_faux_rows
+ * @param {Number} rows The number of rows you want to add to the faux grid.
+ * @return {Object} Returns the instance of the Gridster class.
+ */
+ fn.add_faux_rows = function(rows) {
+ var actual_rows = this.rows;
+ var max_rows = actual_rows + (rows || 1);
+
+ for (var r = max_rows; r > actual_rows; r--) {
+ for (var c = this.cols; c >= 1; c--) {
+ this.add_faux_cell(r, c);
+ }
+ }
+
+ this.rows = max_rows;
+
+ if (this.options.autogenerate_stylesheet) {
+ this.generate_stylesheet();
+ }
+
+ return this;
+ };
+
+ /**
+ * Add cols to the faux grid.
+ *
+ * @method add_faux_cols
+ * @param {Number} cols The number of cols you want to add to the faux grid.
+ * @return {Object} Returns the instance of the Gridster class.
+ */
+ fn.add_faux_cols = function(cols) {
+ var actual_cols = this.cols;
+ var max_cols = actual_cols + (cols || 1);
+ max_cols = Math.min(max_cols, this.options.max_cols);
+
+ for (var c = actual_cols + 1; c <= max_cols; c++) {
+ for (var r = this.rows; r >= 1; r--) {
+ this.add_faux_cell(r, c);
+ }
+ }
+
+ this.cols = max_cols;
+
+ if (this.options.autogenerate_stylesheet) {
+ this.generate_stylesheet();
+ }
+
+ return this;
+ };
+
+
+ /**
+ * Recalculates the offsets for the faux grid. You need to use it when
+ * the browser is resized.
+ *
+ * @method recalculate_faux_grid
+ * @return {Object} Returns the instance of the Gridster class.
+ */
+ fn.recalculate_faux_grid = function() {
+ var aw = this.$wrapper.width();
+ this.baseX = ($(window).width() - aw) / 2;
+ this.baseY = this.$wrapper.offset().top;
+
+ $.each(this.faux_grid, $.proxy(function(i, coords) {
+ this.faux_grid[i] = coords.update({
+ left: this.baseX + (coords.data.col -1) * this.min_widget_width,
+ top: this.baseY + (coords.data.row -1) * this.min_widget_height
+ });
+ }, this));
+
+ return this;
+ };
+
+
+ /**
+ * Get all widgets in the DOM and register them.
+ *
+ * @method get_widgets_from_DOM
+ * @return {Object} Returns the instance of the Gridster class.
+ */
+ fn.get_widgets_from_DOM = function() {
+ var widgets_coords = this.$widgets.map($.proxy(function(i, widget) {
+ var $w = $(widget);
+ return this.dom_to_coords($w);
+ }, this));
+
+ widgets_coords = Gridster.sort_by_row_and_col_asc(widgets_coords);
+
+ var changes = $(widgets_coords).map($.proxy(function(i, wgd) {
+ return this.register_widget(wgd) || null;
+ }, this));
+
+ if (changes.length) {
+ this.$el.trigger('gridster:positionschanged');
+ }
+
+ return this;
+ };
+
+
+ /**
+ * Calculate columns and rows to be set based on the configuration
+ * parameters, grid dimensions, etc ...
+ *
+ * @method generate_grid_and_stylesheet
+ * @return {Object} Returns the instance of the Gridster class.
+ */
+ fn.generate_grid_and_stylesheet = function() {
+ var aw = this.$wrapper.width();
+ var max_cols = this.options.max_cols;
+
+ var cols = Math.floor(aw / this.min_widget_width) +
+ this.options.extra_cols;
+
+ var actual_cols = this.$widgets.map(function() {
+ return $(this).attr('data-col');
+ }).get();
+
+ //needed to pass tests with phantomjs
+ actual_cols.length || (actual_cols = [0]);
+
+ var min_cols = Math.max.apply(Math, actual_cols);
+
+ this.cols = Math.max(min_cols, cols, this.options.min_cols);
+
+ if (max_cols !== Infinity && max_cols >= min_cols && max_cols < this.cols) {
+ this.cols = max_cols;
+ }
+
+ // get all rows that could be occupied by the current widgets
+ var max_rows = this.options.extra_rows;
+ this.$widgets.each(function(i, w) {
+ max_rows += (+$(w).attr('data-sizey'));
+ });
+
+ this.rows = Math.max(max_rows, this.options.min_rows);
+
+ this.baseX = ($(window).width() - aw) / 2;
+ this.baseY = this.$wrapper.offset().top;
+
+ if (this.options.autogenerate_stylesheet) {
+ this.generate_stylesheet();
+ }
+
+ return this.generate_faux_grid(this.rows, this.cols);
+ };
+
+ /**
+ * Destroy this gridster by removing any sign of its presence, making it easy to avoid memory leaks
+ *
+ * @method destroy
+ * @param {Boolean} remove If true, remove gridster from DOM.
+ * @return {Object} Returns the instance of the Gridster class.
+ */
+ fn.destroy = function(remove) {
+ this.$el.removeData('gridster');
+
+ // remove bound callback on window resize
+ $(window).unbind('.gridster');
+
+ if (this.drag_api) {
+ this.drag_api.destroy();
+ }
+
+ this.remove_style_tags();
+
+ remove && this.$el.remove();
+
+ return this;
+ };
+
+
+ //jQuery adapter
+ $.fn.gridster = function(options) {
+ return this.each(function() {
+ if (! $(this).data('gridster')) {
+ $(this).data('gridster', new Gridster( this, options ));
+ }
+ });
+ };
+
+ return Gridster;
+
+}));
+
+;(function(root, factory) {
+
+ if (typeof define === 'function' && define.amd) {
+ define(['jquery', 'gridster'], factory);
+ } else {
+ root.Gridster = factory(root.$ || root.jQuery, root.Gridster);
+ }
+
+}(this, function($, Gridster) {
+
+ var fn = Gridster.prototype;
+
+ fn.widgets_in_col = function(col) {
+ if (!this.gridmap[col]) {
+ return false;
+ }
+
+ for (var i = this.gridmap[col].length - 1; i >= 0; i--) {
+ if (this.is_widget(col, i) !== false) {
+ return true;
+ }
+ }
+
+ return false;
+ };
+
+ fn.widgets_in_row = function(row) {
+ for (var i = this.gridmap.length; i >= 1; i--) {
+ if (this.is_widget(i, row) !== false) {
+ return true;
+ }
+ }
+
+ return false;
+ };
+
+
+ fn.widgets_in_range = function(col1, row1, col2, row2) {
+ var valid_cols = [];
+ var valid_rows = [];
+ var $widgets = $([]);
+ var c, r, $w, wgd;
+
+ for (c = col2; c >= col1; c--) {
+ for (r = row2; r >= row1; r--) {
+ $w = this.is_widget(c, r);
+
+ if ($w !== false) {
+ wgd = $w.data('coords').grid;
+ if (wgd.col >= col1 && wgd.col <= col2 &&
+ wgd.row >= row1 && wgd.row <= row2
+ ) {
+ $widgets = $widgets.add($w);
+ }
+ }
+ }
+ }
+
+ return $widgets;
+ };
+
+
+ fn.get_bottom_most_occupied_cell = function() {
+ var row = 0;
+ var col = 0;
+ this.for_each_cell(function($el, c, r) {
+ if ($el && r > row) {
+ row = r;
+ col = c;
+ }
+ });
+
+ return {col: col, row: row};
+ };
+
+
+ fn.get_right_most_occupied_cell = function() {
+ var row = 0;
+ var col = 0;
+ this.for_each_cell(function($el, c, r) {
+ if ($el) {
+ row = r;
+ col = c;
+ return false;
+ }
+ });
+
+ return {col: col, row: row};
+ };
+
+
+ fn.for_each_cell = function(callback, gridmap) {
+ gridmap || (gridmap = this.gridmap);
+ var cols = gridmap.length;
+ var rows = gridmap[1].length;
+
+ cols_iter:
+ for (var c = cols - 1; c >= 1; c--) {
+ for (var r = rows - 1; r >= 1; r--) {
+ var $el = gridmap[c] && gridmap[c][r];
+ if (callback) {
+ if (callback.call(this, $el, c, r) === false) {
+ break cols_iter;
+ } else { continue; }
+ }
+ }
+ }
+ };
+
+
+ fn.next_position_in_range = function(size_x, size_y, max_rows) {
+ size_x || (size_x = 1);
+ size_y || (size_y = 1);
+ var ga = this.gridmap;
+ var cols_l = ga.length;
+ var valid_pos = [];
+ var rows_l;
+
+ for (var c = 1; c < cols_l; c++) {
+ rows_l = max_rows || ga[c].length;
+ for (var r = 1; r <= rows_l; r++) {
+ var can_move_to = this.can_move_to({
+ size_x: size_x,
+ size_y: size_y
+ }, c, r, max_rows);
+
+ if (can_move_to) {
+ valid_pos.push({
+ col: c,
+ row: r,
+ size_y: size_y,
+ size_x: size_x
+ });
+ }
+ }
+ }
+
+ if (valid_pos.length >= 1) {
+ return Gridster.sort_by_col_asc(valid_pos)[0];
+ }
+
+ return false;
+ };
+
+
+ fn.closest_to_right = function(col, row) {
+ if (!this.gridmap[col]) { return false; }
+ var cols_l = this.gridmap.length - 1;
+
+ for (var c = col; c <= cols_l; c++) {
+ if (this.gridmap[c][row]) {
+ return { col: c, row: row };
+ }
+ }
+
+ return false;
+ };
+
+
+ fn.closest_to_left = function(col, row) {
+ var cols_l = this.gridmap.length - 1;
+ if (!this.gridmap[col]) { return false; }
+
+ for (var c = col; c >= 1; c--) {
+ if (this.gridmap[c][row]) {
+ return { col: c, row: row };
+ }
+ }
+
+ return false;
+ };
+
+ return Gridster;
+
+}));
diff --git a/dist/jquery.gridster.with-extras.min.js b/dist/jquery.gridster.with-extras.min.js
new file mode 100644
index 00000000..1ebb2b25
--- /dev/null
+++ b/dist/jquery.gridster.with-extras.min.js
@@ -0,0 +1,2 @@
+/*! gridster.js - v0.5.6 - 2014-09-25 - * http://gridster.net/ - Copyright (c) 2014 ducksboard; Licensed MIT */ (function(t,i){"function"==typeof define&&define.amd?define("gridster-coords",["jquery"],i):t.GridsterCoords=i(t.$||t.jQuery)})(this,function(t){function i(i){return i[0]&&t.isPlainObject(i[0])?this.data=i[0]:this.el=i,this.isCoords=!0,this.coords={},this.init(),this}var e=i.prototype;return e.init=function(){this.set(),this.original_coords=this.get()},e.set=function(t,i){var e=this.el;if(e&&!t&&(this.data=e.offset(),this.data.width=e.width(),this.data.height=e.height()),e&&t&&!i){var s=e.offset();this.data.top=s.top,this.data.left=s.left}var r=this.data;return r.left===void 0&&(r.left=r.x1),r.top===void 0&&(r.top=r.y1),this.coords.x1=r.left,this.coords.y1=r.top,this.coords.x2=r.left+r.width,this.coords.y2=r.top+r.height,this.coords.cx=r.left+r.width/2,this.coords.cy=r.top+r.height/2,this.coords.width=r.width,this.coords.height=r.height,this.coords.el=e||!1,this},e.update=function(i){if(!i&&!this.el)return this;if(i){var e=t.extend({},this.data,i);return this.data=e,this.set(!0,!0)}return this.set(!0),this},e.get=function(){return this.coords},e.destroy=function(){this.el.removeData("coords"),delete this.el},t.fn.coords=function(){if(this.data("coords"))return this.data("coords");var t=new i(this,arguments[0]);return this.data("coords",t),t},i}),function(t,i){"function"==typeof define&&define.amd?define("gridster-collision",["jquery","gridster-coords"],i):t.GridsterCollision=i(t.$||t.jQuery,t.GridsterCoords)}(this,function(t){function i(i,s,r){this.options=t.extend(e,r),this.$element=i,this.last_colliders=[],this.last_colliders_coords=[],this.set_colliders(s),this.init()}var e={colliders_context:document.body,overlapping_region:"C"};i.defaults=e;var s=i.prototype;return s.init=function(){this.find_collisions()},s.overlaps=function(t,i){var e=!1,s=!1;return(i.x1>=t.x1&&i.x1<=t.x2||i.x2>=t.x1&&i.x2<=t.x2||t.x1>=i.x1&&t.x2<=i.x2)&&(e=!0),(i.y1>=t.y1&&i.y1<=t.y2||i.y2>=t.y1&&i.y2<=t.y2||t.y1>=i.y1&&t.y2<=i.y2)&&(s=!0),e&&s},s.detect_overlapping_region=function(t,i){var e="",s="";return t.y1>i.cy&&t.y1i.y1&&t.y2i.cx&&t.x1i.x1&&t.x2o;o++)-1===t.inArray(r[o],i)&&e.call(this,r[o]);for(var n=0,h=i.length;h>n;n++)-1===t.inArray(i[n],r)&&s.call(this,i[n])},s.find_collisions=function(i){for(var e=this,s=this.options.overlapping_region,r=[],o=[],a=this.colliders||this.$colliders,n=a.length,h=e.$element.coords().update(i||!1).get();n--;){var _=e.$colliders?t(a[n]):a[n],d=_.isCoords?_:_.coords(),l=d.get(),c=e.overlaps(h,l);if(c){var p=e.detect_overlapping_region(h,l);if(p===s||"all"===s){var g=e.calculate_overlapped_area_coords(h,l),u=e.calculate_overlapped_area(g),f={area:u,area_coords:g,region:p,coords:l,player_coords:h,el:_};e.options.on_overlap&&e.options.on_overlap.call(this,f),r.push(d),o.push(f)}}}return(e.options.on_overlap_stop||e.options.on_overlap_start)&&this.manage_colliders_start_stop(r,e.options.on_overlap_start,e.options.on_overlap_stop),this.last_colliders_coords=r,o},s.get_closest_colliders=function(t){var i=this.find_collisions(t);return i.sort(function(t,i){return"C"===t.region&&"C"===i.region?t.coords.y1this.player_max_left?o=this.player_max_left:this.player_min_left>o&&(o=this.player_min_left)),{position:{left:o,top:a},pointer:{left:e.left,top:e.top,diff_left:s+(t(window).scrollLeft()-this.win_offset_x),diff_top:r+(t(window).scrollTop()-this.win_offset_y)}}},_.get_drag_data=function(t){var i=this.get_offset(t);return i.$player=this.$player,i.$helper=this.helper?this.$helper:this.$player,i},_.set_limits=function(t){return t||(t=this.$container.width()),this.player_max_left=t-this.player_width+-this.options.offset_left,this.options.container_width=t,this},_.scroll_in=function(i,e){var o,n=r[i],h=50,_=30,d="x"===i,l=d?this.window_width:this.window_height,c=d?t(document).width():t(document).height(),p=d?this.$player.width():this.$player.height(),g=s["scroll"+a(n)](),u=g,f=u+l,w=f-h,m=u+h,y=u+e.pointer[n],v=c-l+p;return y>=w&&(o=g+_,v>o&&(s["scroll"+a(n)](o),this["scroll_offset_"+i]+=_)),m>=y&&(o=g-_,o>0&&(s["scroll"+a(n)](o),this["scroll_offset_"+i]-=_)),this},_.manage_scroll=function(t){this.scroll_in("x",t),this.scroll_in("y",t)},_.calculate_dimensions=function(){this.window_height=s.height(),this.window_width=s.width()},_.drag_handler=function(i){if(i.target.nodeName,!this.disabled&&(1===i.which||o)&&!this.ignore_drag(i)){var e=this,s=!0;return this.$player=t(i.currentTarget),this.el_init_pos=this.get_actual_pos(this.$player),this.mouse_init_pos=this.get_mouse_pos(i),this.offsetY=this.mouse_init_pos.top-this.el_init_pos.top,this.$document.on(this.pointer_events.move,function(t){var i=e.get_mouse_pos(t),r=Math.abs(i.left-e.mouse_init_pos.left),o=Math.abs(i.top-e.mouse_init_pos.top);return r>e.options.distance||o>e.options.distance?s?(s=!1,e.on_dragstart.call(e,t),!1):(e.is_dragging===!0&&e.on_dragmove.call(e,t),!1):!1}),o?void 0:!1}},_.on_dragstart=function(i){if(i.preventDefault(),this.is_dragging)return this;this.drag_start=this.is_dragging=!0;var e=this.$container.offset();return this.baseX=Math.round(e.left),this.baseY=Math.round(e.top),this.initial_container_width=this.options.container_width||this.$container.width(),"clone"===this.options.helper?(this.$helper=this.$player.clone().appendTo(this.$container).addClass("helper"),this.helper=!0):this.helper=!1,this.win_offset_y=t(window).scrollTop(),this.win_offset_x=t(window).scrollLeft(),this.scroll_offset_y=0,this.scroll_offset_x=0,this.el_init_offset=this.$player.offset(),this.player_width=this.$player.width(),this.player_height=this.$player.height(),this.set_limits(this.options.container_width),this.options.start&&this.options.start.call(this.$player,i,this.get_drag_data(i)),!1},_.on_dragmove=function(t){var i=this.get_drag_data(t);this.options.autoscroll&&this.manage_scroll(i),this.options.move_element&&(this.helper?this.$helper:this.$player).css({position:"absolute",left:i.position.left,top:i.position.top});var e=this.last_position||i.position;return i.prev_position=e,this.options.drag&&this.options.drag.call(this.$player,t,i),this.last_position=i.position,!1},_.on_dragstop=function(t){var i=this.get_drag_data(t);return this.drag_start=!1,this.options.stop&&this.options.stop.call(this.$player,t,i),this.helper&&this.options.remove_helper&&this.$helper.remove(),!1},_.on_select_start=function(t){return this.disabled||this.ignore_drag(t)?void 0:!1},_.enable=function(){this.disabled=!1},_.disable=function(){this.disabled=!0},_.destroy=function(){this.disable(),this.$container.off(this.ns),this.$document.off(this.ns),t(window).off(this.ns),t.removeData(this.$container,"drag")},_.ignore_drag=function(i){return this.options.handle?!t(i.target).is(this.options.handle):t.isFunction(this.options.ignore_dragging)?this.options.ignore_dragging(i):t(i.target).is(this.options.ignore_dragging.join(", "))},t.fn.drag=function(t){return new i(this,t)},i}),function(t,i){"function"==typeof define&&define.amd?define(["jquery","gridster-draggable","gridster-collision"],i):t.Gridster=i(t.$||t.jQuery,t.GridsterDraggable,t.GridsterCollision)}(this,function(t,i){function e(i,e){this.options=t.extend(!0,{},s,e),this.$el=t(i),this.$wrapper=this.$el.parent(),this.$widgets=this.$el.children(this.options.widget_selector).addClass("gs-w"),this.widgets=[],this.$changed=t([]),this.wrapper_width=this.$wrapper.width(),this.min_widget_width=2*this.options.widget_margins[0]+this.options.widget_base_dimensions[0],this.min_widget_height=2*this.options.widget_margins[1]+this.options.widget_base_dimensions[1],this.generated_stylesheets=[],this.$style_tags=t([]),this.options.auto_init&&this.init()}var s={namespace:"",widget_selector:"li",widget_margins:[10,10],widget_base_dimensions:[400,225],extra_rows:0,extra_cols:0,min_cols:1,max_cols:1/0,min_rows:15,max_size_x:!1,autogrow_cols:!1,autogenerate_stylesheet:!0,avoid_overlapped_widgets:!0,auto_init:!0,serialize_params:function(t,i){return{col:i.col,row:i.row,size_x:i.size_x,size_y:i.size_y}},collision:{},draggable:{items:".gs-w",distance:4,ignore_dragging:i.defaults.ignore_dragging.slice(0)},resize:{enabled:!1,axes:["both"],handle_append_to:"",handle_class:"gs-resize-handle",max_size:[1/0,1/0],min_size:[1,1]}};e.defaults=s,e.generated_stylesheets=[],e.sort_by_row_asc=function(i){return i=i.sort(function(i,e){return i.row||(i=t(i).coords().grid,e=t(e).coords().grid),i.row>e.row?1:-1})},e.sort_by_row_and_col_asc=function(t){return t=t.sort(function(t,i){return t.row>i.row||t.row===i.row&&t.col>i.col?1:-1})},e.sort_by_col_asc=function(t){return t=t.sort(function(t,i){return t.col>i.col?1:-1})},e.sort_by_row_desc=function(t){return t=t.sort(function(t,i){return t.row+t.size_yn&&this.add_faux_rows(Math.max(e-n,0));var d=o+i-1;d>this.cols&&this.add_faux_cols(d-this.cols);var l={col:_,row:r.row,size_x:i,size_y:e};return this.mutate_widget_in_gridmap(t,r,l),this.set_dom_grid_height(),this.set_dom_grid_width(),s&&s.call(this,l.size_x,l.size_y),t},r.mutate_widget_in_gridmap=function(i,e,s){e.size_x;var r=e.size_y,o=this.get_cells_occupied(e),a=this.get_cells_occupied(s),n=[];t.each(o.cols,function(i,e){-1===t.inArray(e,a.cols)&&n.push(e)});var h=[];t.each(a.cols,function(i,e){-1===t.inArray(e,o.cols)&&h.push(e)});var _=[];t.each(o.rows,function(i,e){-1===t.inArray(e,a.rows)&&_.push(e)});var d=[];if(t.each(a.rows,function(i,e){-1===t.inArray(e,o.rows)&&d.push(e)}),this.remove_from_gridmap(e),h.length){var l=[s.col,s.row,s.size_x,Math.min(r,s.size_y),i];this.empty_cells.apply(this,l)}if(d.length){var c=[s.col,s.row,s.size_x,s.size_y,i];this.empty_cells.apply(this,c)}if(e.col=s.col,e.row=s.row,e.size_x=s.size_x,e.size_y=s.size_y,this.add_to_gridmap(s,i),i.removeClass("player-revert"),i.data("coords").update({width:s.size_x*this.options.widget_base_dimensions[0]+2*(s.size_x-1)*this.options.widget_margins[0],height:s.size_y*this.options.widget_base_dimensions[1]+2*(s.size_y-1)*this.options.widget_margins[1]}),i.attr({"data-col":s.col,"data-row":s.row,"data-sizex":s.size_x,"data-sizey":s.size_y}),n.length){var p=[n[0],s.row,n.length,Math.min(r,s.size_y),i];this.remove_empty_cells.apply(this,p)}if(_.length){var g=[s.col,s.row,s.size_x,s.size_y,i];this.remove_empty_cells.apply(this,g)}return this.move_widget_up(i),this},r.empty_cells=function(i,e,s,r,o){var a=this.widgets_below({col:i,row:e-r,size_x:s,size_y:r});return a.not(o).each(t.proxy(function(i,s){var o=t(s).coords().grid;if(e+r-1>=o.row){var a=e+r-o.row;this.move_widget_down(t(s),a)}},this)),this.set_dom_grid_height(),this},r.remove_empty_cells=function(i,e,s,r,o){var a=this.widgets_below({col:i,row:e,size_x:s,size_y:r});return a.not(o).each(t.proxy(function(i,e){this.move_widget_up(t(e),r)},this)),this.set_dom_grid_height(),this},r.next_position=function(t,i){t||(t=1),i||(i=1);for(var s,r=this.gridmap,o=r.length,a=[],n=1;o>n;n++){s=r[n].length;for(var h=1;s>=h;h++){var _=this.can_move_to({size_x:t,size_y:i},n,h);_&&a.push({col:n,row:h,size_y:i,size_x:t})}}return a.length?e.sort_by_row_and_col_asc(a)[0]:!1},r.remove_widget=function(i,e,s){var r=i instanceof t?i:t(i),o=r.coords().grid;t.isFunction(e)&&(s=e,e=!1),this.cells_occupied_by_placeholder={},this.$widgets=this.$widgets.not(r);var a=this.widgets_below(r);return this.remove_from_gridmap(o),r.fadeOut(t.proxy(function(){r.remove(),e||a.each(t.proxy(function(i,e){this.move_widget_up(t(e),o.size_y)},this)),this.set_dom_grid_height(),s&&s.call(this,i)},this)),this},r.remove_all_widgets=function(i){return this.$widgets.each(t.proxy(function(t,e){this.remove_widget(e,!0,i)},this)),this},r.serialize=function(i){return i||(i=this.$widgets),i.map(t.proxy(function(i,e){var s=t(e);return this.options.serialize_params(s,s.coords().grid)},this)).get()},r.serialize_changed=function(){return this.serialize(this.$changed)},r.dom_to_coords=function(t){return{col:parseInt(t.attr("data-col"),10),row:parseInt(t.attr("data-row"),10),size_x:parseInt(t.attr("data-sizex"),10)||1,size_y:parseInt(t.attr("data-sizey"),10)||1,max_size_x:parseInt(t.attr("data-max-sizex"),10)||!1,max_size_y:parseInt(t.attr("data-max-sizey"),10)||!1,min_size_x:parseInt(t.attr("data-min-sizex"),10)||!1,min_size_y:parseInt(t.attr("data-min-sizey"),10)||!1,el:t}},r.register_widget=function(i){var e=i instanceof jQuery,s=e?this.dom_to_coords(i):i,r=!1;e||(i=s.el);var o=this.can_go_widget_up(s);return o&&(s.row=o,i.attr("data-row",o),this.$el.trigger("gridster:positionchanged",[s]),r=!0),this.options.avoid_overlapped_widgets&&!this.can_move_to({size_x:s.size_x,size_y:s.size_y},s.col,s.row)&&(t.extend(s,this.next_position(s.size_x,s.size_y)),i.attr({"data-col":s.col,"data-row":s.row,"data-sizex":s.size_x,"data-sizey":s.size_y}),r=!0),i.data("coords",i.coords()),i.data("coords").grid=s,this.add_to_gridmap(s,i),this.options.resize.enabled&&this.add_resize_handle(i),r},r.update_widget_position=function(t,i){return this.for_each_cell_occupied(t,function(t,e){return this.gridmap[t]?(this.gridmap[t][e]=i,void 0):this}),this},r.remove_from_gridmap=function(t){return this.update_widget_position(t,!1)},r.add_to_gridmap=function(i,e){if(this.update_widget_position(i,e||i.el),i.el){var s=this.widgets_below(i.el);s.each(t.proxy(function(i,e){this.move_widget_up(t(e))},this))}},r.draggable=function(){var i=this,e=t.extend(!0,{},this.options.draggable,{offset_left:this.options.widget_margins[0],offset_top:this.options.widget_margins[1],container_width:this.cols*this.min_widget_width,limit:!0,start:function(e,s){i.$widgets.filter(".player-revert").removeClass("player-revert"),i.$player=t(this),i.$helper=t(s.$helper),i.helper=!i.$helper.is(i.$player),i.on_start_drag.call(i,e,s),i.$el.trigger("gridster:dragstart")},stop:function(t,e){i.on_stop_drag.call(i,t,e),i.$el.trigger("gridster:dragstop")},drag:throttle(function(t,e){i.on_drag.call(i,t,e),i.$el.trigger("gridster:drag")},60)});return this.drag_api=this.$el.drag(e),this},r.resizable=function(){return this.resize_api=this.$el.drag({items:"."+this.options.resize.handle_class,offset_left:this.options.widget_margins[0],container_width:this.container_width,move_element:!1,resize:!0,limit:this.options.autogrow_cols?!1:!0,start:t.proxy(this.on_start_resize,this),stop:t.proxy(function(i,e){delay(t.proxy(function(){this.on_stop_resize(i,e)},this),120)},this),drag:throttle(t.proxy(this.on_resize,this),60)}),this},r.setup_resize=function(){this.resize_handle_class=this.options.resize.handle_class;var i=this.options.resize.axes,e='';return this.resize_handle_tpl=t.map(i,function(t){return e.replace("{type}",t)}).join(""),t.isArray(this.options.draggable.ignore_dragging)&&this.options.draggable.ignore_dragging.push("."+this.resize_handle_class),this},r.on_start_drag=function(i,e){this.$helper.add(this.$player).add(this.$wrapper).addClass("dragging"),this.highest_col=this.get_highest_occupied_cell().col,this.$player.addClass("player"),this.player_grid_data=this.$player.coords().grid,this.placeholder_grid_data=t.extend({},this.player_grid_data),this.set_dom_grid_height(this.$el.height()+this.player_grid_data.size_y*this.min_widget_height),this.set_dom_grid_width(this.cols);var s=this.player_grid_data.size_x,r=this.cols-this.highest_col;this.options.autogrow_cols&&s>=r&&this.add_faux_cols(Math.min(s-r,1));var o=this.faux_grid,a=this.$player.data("coords").coords;this.cells_occupied_by_player=this.get_cells_occupied(this.player_grid_data),this.cells_occupied_by_placeholder=this.get_cells_occupied(this.placeholder_grid_data),this.last_cols=[],this.last_rows=[],this.collision_api=this.$helper.collision(o,this.options.collision),this.$preview_holder=t("<"+this.$player.get(0).tagName+" />",{"class":"preview-holder","data-row":this.$player.attr("data-row"),"data-col":this.$player.attr("data-col"),css:{width:a.width,height:a.height}}).appendTo(this.$el),this.options.draggable.start&&this.options.draggable.start.call(this,i,e)},r.on_drag=function(t,i){if(null===this.$player)return!1;var e={left:i.position.left+this.baseX,top:i.position.top+this.baseY};if(this.options.autogrow_cols){var s=this.placeholder_grid_data.col+this.placeholder_grid_data.size_x-1;s>=this.cols-1&&this.options.max_cols>=this.cols+1&&(this.add_faux_cols(1),this.set_dom_grid_width(this.cols+1),this.drag_api.set_limits(this.container_width)),this.collision_api.set_colliders(this.faux_grid)}this.colliders_data=this.collision_api.get_closest_colliders(e),this.on_overlapped_column_change(this.on_start_overlapping_column,this.on_stop_overlapping_column),this.on_overlapped_row_change(this.on_start_overlapping_row,this.on_stop_overlapping_row),this.helper&&this.$player&&this.$player.css({left:i.position.left,top:i.position.top}),this.options.draggable.drag&&this.options.draggable.drag.call(this,t,i)},r.on_stop_drag=function(t,i){this.$helper.add(this.$player).add(this.$wrapper).removeClass("dragging"),i.position.left=i.position.left+this.baseX,i.position.top=i.position.top+this.baseY,this.colliders_data=this.collision_api.get_closest_colliders(i.position),this.on_overlapped_column_change(this.on_start_overlapping_column,this.on_stop_overlapping_column),this.on_overlapped_row_change(this.on_start_overlapping_row,this.on_stop_overlapping_row),this.$player.addClass("player-revert").removeClass("player").attr({"data-col":this.placeholder_grid_data.col,"data-row":this.placeholder_grid_data.row}).css({left:"",top:""}),this.$changed=this.$changed.add(this.$player),this.cells_occupied_by_player=this.get_cells_occupied(this.placeholder_grid_data),this.set_cells_player_occupies(this.placeholder_grid_data.col,this.placeholder_grid_data.row),this.$player.coords().grid.row=this.placeholder_grid_data.row,this.$player.coords().grid.col=this.placeholder_grid_data.col,this.options.draggable.stop&&this.options.draggable.stop.call(this,t,i),this.$preview_holder.remove(),this.$player=null,this.$helper=null,this.placeholder_grid_data={},this.player_grid_data={},this.cells_occupied_by_placeholder={},this.cells_occupied_by_player={},this.set_dom_grid_height(),this.set_dom_grid_width(),this.options.autogrow_cols&&this.drag_api.set_limits(this.cols*this.min_widget_width)},r.on_start_resize=function(i,e){this.$resized_widget=e.$player.closest(".gs-w"),this.resize_coords=this.$resized_widget.coords(),this.resize_wgd=this.resize_coords.grid,this.resize_initial_width=this.resize_coords.coords.width,this.resize_initial_height=this.resize_coords.coords.height,this.resize_initial_sizex=this.resize_coords.grid.size_x,this.resize_initial_sizey=this.resize_coords.grid.size_y,this.resize_initial_col=this.resize_coords.grid.col,this.resize_last_sizex=this.resize_initial_sizex,this.resize_last_sizey=this.resize_initial_sizey,this.resize_max_size_x=Math.min(this.resize_wgd.max_size_x||this.options.resize.max_size[0],this.options.max_cols-this.resize_initial_col+1),this.resize_max_size_y=this.resize_wgd.max_size_y||this.options.resize.max_size[1],this.resize_min_size_x=this.resize_wgd.min_size_x||this.options.resize.min_size[0]||1,this.resize_min_size_y=this.resize_wgd.min_size_y||this.options.resize.min_size[1]||1,this.resize_initial_last_col=this.get_highest_occupied_cell().col,this.set_dom_grid_width(this.cols),this.resize_dir={right:e.$player.is("."+this.resize_handle_class+"-x"),bottom:e.$player.is("."+this.resize_handle_class+"-y")},this.$resized_widget.css({"min-width":this.options.widget_base_dimensions[0],"min-height":this.options.widget_base_dimensions[1]});var s=this.$resized_widget.get(0).tagName;this.$resize_preview_holder=t("<"+s+" />",{"class":"preview-holder resize-preview-holder","data-row":this.$resized_widget.attr("data-row"),"data-col":this.$resized_widget.attr("data-col"),css:{width:this.resize_initial_width,height:this.resize_initial_height}}).appendTo(this.$el),this.$resized_widget.addClass("resizing"),this.options.resize.start&&this.options.resize.start.call(this,i,e,this.$resized_widget),this.$el.trigger("gridster:resizestart")},r.on_stop_resize=function(i,e){this.$resized_widget.removeClass("resizing").css({width:"",height:""}),delay(t.proxy(function(){this.$resize_preview_holder.remove().css({"min-width":"","min-height":""}),this.options.resize.stop&&this.options.resize.stop.call(this,i,e,this.$resized_widget),this.$el.trigger("gridster:resizestop")},this),300),this.set_dom_grid_width(),this.options.autogrow_cols&&this.drag_api.set_limits(this.cols*this.min_widget_width)},r.on_resize=function(t,i){var e,s=i.pointer.diff_left,r=i.pointer.diff_top,o=this.options.widget_base_dimensions[0],a=this.options.widget_base_dimensions[1],n=this.options.widget_margins[0],h=this.options.widget_margins[1],_=this.resize_max_size_x,d=this.resize_min_size_x,l=this.resize_max_size_y,c=this.resize_min_size_y,p=this.options.autogrow_cols,g=1/0,u=1/0,f=Math.ceil(s/(o+2*n)-.2),w=Math.ceil(r/(a+2*h)-.2),m=Math.max(1,this.resize_initial_sizex+f),y=Math.max(1,this.resize_initial_sizey+w),v=this.container_width/this.min_widget_width-this.resize_initial_col+1,z=v*this.min_widget_width-2*n;if(m=Math.max(Math.min(m,_),d),m=Math.min(v,m),e=_*o+2*(m-1)*n,g=Math.min(e,z),min_width=d*o+2*(m-1)*n,y=Math.max(Math.min(y,l),c),u=l*a+2*(y-1)*h,min_height=c*a+2*(y-1)*h,this.resize_dir.right?y=this.resize_initial_sizey:this.resize_dir.bottom&&(m=this.resize_initial_sizex),p){var x=this.resize_initial_col+m-1;p&&x>=this.resize_initial_last_col&&(this.set_dom_grid_width(Math.max(x+1,this.cols)),x>this.cols&&this.add_faux_cols(x-this.cols))}var $={};!this.resize_dir.bottom&&($.width=Math.max(Math.min(this.resize_initial_width+s,g),min_width)),!this.resize_dir.right&&($.height=Math.max(Math.min(this.resize_initial_height+r,u),min_height)),this.$resized_widget.css($),(m!==this.resize_last_sizex||y!==this.resize_last_sizey)&&(this.resize_widget(this.$resized_widget,m,y),this.set_dom_grid_width(this.cols),this.$resize_preview_holder.css({width:"",height:""}).attr({"data-row":this.$resized_widget.attr("data-row"),"data-sizex":m,"data-sizey":y})),this.options.resize.resize&&this.options.resize.resize.call(this,t,i,this.$resized_widget),this.$el.trigger("gridster:resize"),this.resize_last_sizex=m,this.resize_last_sizey=y},r.on_overlapped_column_change=function(i,e){if(!this.colliders_data.length)return this;var s,r=this.get_targeted_columns(this.colliders_data[0].el.data.col),o=this.last_cols.length,a=r.length;for(s=0;a>s;s++)-1===t.inArray(r[s],this.last_cols)&&(i||t.noop).call(this,r[s]);for(s=0;o>s;s++)-1===t.inArray(this.last_cols[s],r)&&(e||t.noop).call(this,this.last_cols[s]);return this.last_cols=r,this},r.on_overlapped_row_change=function(i,e){if(!this.colliders_data.length)return this;var s,r=this.get_targeted_rows(this.colliders_data[0].el.data.row),o=this.last_rows.length,a=r.length;for(s=0;a>s;s++)-1===t.inArray(r[s],this.last_rows)&&(i||t.noop).call(this,r[s]);for(s=0;o>s;s++)-1===t.inArray(this.last_rows[s],r)&&(e||t.noop).call(this,this.last_rows[s]);this.last_rows=r},r.set_player=function(t,i,e){var s=this;e||this.empty_cells_player_occupies();var r=e?{col:t}:s.colliders_data[0].el.data,o=r.col,a=i||r.row;this.player_grid_data={col:o,row:a,size_y:this.player_grid_data.size_y,size_x:this.player_grid_data.size_x},this.cells_occupied_by_player=this.get_cells_occupied(this.player_grid_data);var n=this.get_widgets_overlapped(this.player_grid_data),h=this.widgets_constraints(n);if(this.manage_movements(h.can_go_up,o,a),this.manage_movements(h.can_not_go_up,o,a),!n.length){var _=this.can_go_player_up(this.player_grid_data);_!==!1&&(a=_),this.set_placeholder(o,a)}return{col:o,row:a}},r.widgets_constraints=function(i){var s,r=t([]),o=[],a=[];return i.each(t.proxy(function(i,e){var s=t(e),n=s.coords().grid;this.can_go_widget_up(n)?(r=r.add(s),o.push(n)):a.push(n)},this)),s=i.not(r),{can_go_up:e.sort_by_row_asc(o),can_not_go_up:e.sort_by_row_desc(a)}},r.manage_movements=function(i,e,s){return t.each(i,t.proxy(function(t,i){var r=i,o=r.el,a=this.can_go_widget_up(r);if(a)this.move_widget_to(o,a),this.set_placeholder(e,a+r.size_y);else{var n=this.can_go_player_up(this.player_grid_data);if(!n){var h=s+this.player_grid_data.size_y-r.row;this.move_widget_down(o,h),this.set_placeholder(e,s)}}},this)),this},r.is_player=function(t,i){if(i&&!this.gridmap[t])return!1;var e=i?this.gridmap[t][i]:t;return e&&(e.is(this.$player)||e.is(this.$helper))},r.is_player_in=function(i,e){var s=this.cells_occupied_by_player||{};return t.inArray(i,s.cols)>=0&&t.inArray(e,s.rows)>=0},r.is_placeholder_in=function(i,e){var s=this.cells_occupied_by_placeholder||{};return this.is_placeholder_in_col(i)&&t.inArray(e,s.rows)>=0},r.is_placeholder_in_col=function(i){var e=this.cells_occupied_by_placeholder||[];return t.inArray(i,e.cols)>=0},r.is_empty=function(t,i){return this.gridmap[t]!==void 0?this.gridmap[t][i]!==void 0&&this.gridmap[t][i]===!1?!0:!1:!0},r.is_occupied=function(t,i){return this.gridmap[t]?this.gridmap[t][i]?!0:!1:!1},r.is_widget=function(t,i){var e=this.gridmap[t];return e?(e=e[i],e?e:!1):!1},r.is_widget_under_player=function(t,i){return this.is_widget(t,i)?this.is_player_in(t,i):!1},r.get_widgets_under_player=function(i){i||(i=this.cells_occupied_by_player||{cols:[],rows:[]});var e=t([]);return t.each(i.cols,t.proxy(function(s,r){t.each(i.rows,t.proxy(function(t,i){this.is_widget(r,i)&&(e=e.add(this.gridmap[r][i]))},this))},this)),e},r.set_placeholder=function(i,e){var s=t.extend({},this.placeholder_grid_data),r=this.widgets_below({col:s.col,row:s.row,size_y:s.size_y,size_x:s.size_x}),o=i+s.size_x-1;o>this.cols&&(i-=o-i);var a=e>this.placeholder_grid_data.row,n=this.placeholder_grid_data.col!==i;this.placeholder_grid_data.col=i,this.placeholder_grid_data.row=e,this.cells_occupied_by_placeholder=this.get_cells_occupied(this.placeholder_grid_data),this.$preview_holder.attr({"data-row":e,"data-col":i}),(a||n)&&r.each(t.proxy(function(e,r){this.move_widget_up(t(r),this.placeholder_grid_data.col-i+s.size_y)},this));var h=this.get_widgets_under_player(this.cells_occupied_by_placeholder);h.length&&h.each(t.proxy(function(i,r){var o=t(r);this.move_widget_down(o,e+s.size_y-o.data("coords").grid.row)},this))},r.can_go_player_up=function(t){var i=t.row+t.size_y-1,e=!0,s=[],r=1e4,o=this.get_widgets_under_player();return this.for_each_column_occupied(t,function(t){var a=this.gridmap[t],n=i+1;for(s[t]=[];--n>0&&(this.is_empty(t,n)||this.is_player(t,n)||this.is_widget(t,n)&&a[n].is(o));)s[t].push(n),r=r>n?n:r;return 0===s[t].length?(e=!1,!0):(s[t].sort(function(t,i){return t-i
+}),void 0)}),e?this.get_valid_rows(t,s,r):!1},r.can_go_widget_up=function(t){var i=t.row+t.size_y-1,e=!0,s=[],r=1e4;return this.for_each_column_occupied(t,function(o){var a=this.gridmap[o];s[o]=[];for(var n=i+1;--n>0&&(!this.is_widget(o,n)||this.is_player_in(o,n)||a[n].is(t.el));)this.is_player(o,n)||this.is_placeholder_in(o,n)||this.is_player_in(o,n)||s[o].push(n),r>n&&(r=n);return 0===s[o].length?(e=!1,!0):(s[o].sort(function(t,i){return t-i}),void 0)}),e?this.get_valid_rows(t,s,r):!1},r.get_valid_rows=function(i,e,s){for(var r=i.row,o=i.row+i.size_y-1,a=i.size_y,n=s-1,h=[];o>=++n;){var _=!0;if(t.each(e,function(i,e){t.isArray(e)&&-1===t.inArray(n,e)&&(_=!1)}),_===!0&&(h.push(n),h.length===a))break}var d=!1;return 1===a?h[0]!==r&&(d=h[0]||!1):h[0]!==r&&(d=this.get_consecutive_numbers_index(h,a)),d},r.get_consecutive_numbers_index=function(t,i){for(var e=t.length,s=[],r=!0,o=-1,a=0;e>a;a++){if(r||t[a]===o+1){if(s.push(a),s.length===i)break;r=!1}else s=[],r=!0;o=t[a]}return s.length>=i?t[s[0]]:!1},r.get_widgets_overlapped=function(){var i=t([]),e=[],s=this.cells_occupied_by_player.rows.slice(0);return s.reverse(),t.each(this.cells_occupied_by_player.cols,t.proxy(function(r,o){t.each(s,t.proxy(function(s,r){if(!this.gridmap[o])return!0;var a=this.gridmap[o][r];this.is_occupied(o,r)&&!this.is_player(a)&&-1===t.inArray(a,e)&&(i=i.add(a),e.push(a))},this))},this)),i},r.on_start_overlapping_column=function(t){this.set_player(t,!1)},r.on_start_overlapping_row=function(t){this.set_player(!1,t)},r.on_stop_overlapping_column=function(t){this.set_player(t,!1);var i=this;this.for_each_widget_below(t,this.cells_occupied_by_player.rows[0],function(){i.move_widget_up(this,i.player_grid_data.size_y)})},r.on_stop_overlapping_row=function(t){this.set_player(!1,t);for(var i=this,e=this.cells_occupied_by_player.cols,s=0,r=e.length;r>s;s++)this.for_each_widget_below(e[s],t,function(){i.move_widget_up(this,i.player_grid_data.size_y)})},r.move_widget_to=function(i,e){var s=this,r=i.coords().grid;e-r.row;var o=this.widgets_below(i),a=this.can_move_to(r,r.col,e,i);return a===!1?!1:(this.remove_from_gridmap(r),r.row=e,this.add_to_gridmap(r),i.attr("data-row",e),this.$changed=this.$changed.add(i),o.each(function(i,e){var r=t(e),o=r.coords().grid,a=s.can_go_widget_up(o);a&&a!==o.row&&s.move_widget_to(r,a)}),this)},r.move_widget_up=function(i,e){var s=i.coords().grid,r=s.row,o=[];return e||(e=1),this.can_go_up(i)?(this.for_each_column_occupied(s,function(s){if(-1===t.inArray(i,o)){var a=i.coords().grid,n=r-e;if(n=this.can_go_up_to_row(a,s,n),!n)return!0;var h=this.widgets_below(i);this.remove_from_gridmap(a),a.row=n,this.add_to_gridmap(a),i.attr("data-row",a.row),this.$changed=this.$changed.add(i),o.push(i),h.each(t.proxy(function(i,s){this.move_widget_up(t(s),e)},this))}}),void 0):!1},r.move_widget_down=function(i,e){var s,r,o,a;if(0>=e)return!1;if(s=i.coords().grid,r=s.row,o=[],a=e,!i)return!1;if(-1===t.inArray(i,o)){var n=i.coords().grid,h=r+e,_=this.widgets_below(i);this.remove_from_gridmap(n),_.each(t.proxy(function(i,e){var s=t(e),r=s.coords().grid,o=this.displacement_diff(r,n,a);o>0&&this.move_widget_down(s,o)},this)),n.row=h,this.update_widget_position(n,i),i.attr("data-row",n.row),this.$changed=this.$changed.add(i),o.push(i)}},r.can_go_up_to_row=function(i,e,s){var r,o=this.gridmap,a=!0,n=[],h=i.row;if(this.for_each_column_occupied(i,function(t){for(o[t],n[t]=[],r=h;r--&&this.is_empty(t,r)&&!this.is_placeholder_in(t,r);)n[t].push(r);return n[t].length?void 0:(a=!1,!0)}),!a)return!1;for(r=s,r=1;h>r;r++){for(var _=!0,d=0,l=n.length;l>d;d++)n[d]&&-1===t.inArray(r,n[d])&&(_=!1);if(_===!0){a=r;break}}return a},r.displacement_diff=function(t,i,e){var s=t.row,r=[],o=i.row+i.size_y;this.for_each_column_occupied(t,function(t){for(var i=0,e=o;s>e;e++)this.is_empty(t,e)&&(i+=1);r.push(i)});var a=Math.max.apply(Math,r);return e-=a,e>0?e:0},r.widgets_below=function(i){var s=t.isPlainObject(i)?i:i.coords().grid,r=this;this.gridmap;var o=s.row+s.size_y-1,a=t([]);return this.for_each_column_occupied(s,function(i){r.for_each_widget_below(i,o,function(){return r.is_player(this)||-1!==t.inArray(this,a)?void 0:(a=a.add(this),!0)})}),e.sort_by_row_asc(a)},r.set_cells_player_occupies=function(t,i){return this.remove_from_gridmap(this.placeholder_grid_data),this.placeholder_grid_data.col=t,this.placeholder_grid_data.row=i,this.add_to_gridmap(this.placeholder_grid_data,this.$player),this},r.empty_cells_player_occupies=function(){return this.remove_from_gridmap(this.placeholder_grid_data),this},r.can_go_up=function(t){var i=t.coords().grid,e=i.row,s=e-1;this.gridmap;var r=!0;return 1===e?!1:(this.for_each_column_occupied(i,function(t){return this.is_widget(t,s),this.is_occupied(t,s)||this.is_player(t,s)||this.is_placeholder_in(t,s)||this.is_player_in(t,s)?(r=!1,!0):void 0}),r)},r.can_move_to=function(t,i,e,s){this.gridmap;var r=t.el,o={size_y:t.size_y,size_x:t.size_x,col:i,row:e},a=!0,n=i+t.size_x-1;return n>this.cols?!1:s&&e+t.size_y-1>s?!1:(this.for_each_cell_occupied(o,function(i,e){var s=this.is_widget(i,e);!s||t.el&&!s.is(r)||(a=!1)}),a)},r.get_targeted_columns=function(t){for(var i=(t||this.player_grid_data.col)+(this.player_grid_data.size_x-1),e=[],s=t;i>=s;s++)e.push(s);return e},r.get_targeted_rows=function(t){for(var i=(t||this.player_grid_data.row)+(this.player_grid_data.size_y-1),e=[],s=t;i>=s;s++)e.push(s);return e},r.get_cells_occupied=function(i){var e,s={cols:[],rows:[]};for(arguments[1]instanceof t&&(i=arguments[1].coords().grid),e=0;i.size_x>e;e++){var r=i.col+e;s.cols.push(r)}for(e=0;i.size_y>e;e++){var o=i.row+e;s.rows.push(o)}return s},r.for_each_cell_occupied=function(t,i){return this.for_each_column_occupied(t,function(e){this.for_each_row_occupied(t,function(t){i.call(this,e,t)})}),this},r.for_each_column_occupied=function(t,i){for(var e=0;t.size_x>e;e++){var s=t.col+e;i.call(this,s,t)}},r.for_each_row_occupied=function(t,i){for(var e=0;t.size_y>e;e++){var s=t.row+e;i.call(this,s,t)}},r._traversing_widgets=function(i,e,s,r,o){var a=this.gridmap;if(a[s]){var n,h,_=i+"/"+e;if(arguments[2]instanceof t){var d=arguments[2].coords().grid;s=d.col,r=d.row,o=arguments[3]}var l=[],c=r,p={"for_each/above":function(){for(;c--&&!(c>0&&this.is_widget(s,c)&&-1===t.inArray(a[s][c],l)&&(n=o.call(a[s][c],s,c),l.push(a[s][c]),n)););},"for_each/below":function(){for(c=r+1,h=a[s].length;h>c&&(!this.is_widget(s,c)||-1!==t.inArray(a[s][c],l)||(n=o.call(a[s][c],s,c),l.push(a[s][c]),!n));c++);}};p[_]&&p[_].call(this)}},r.for_each_widget_above=function(t,i,e){return this._traversing_widgets("for_each","above",t,i,e),this},r.for_each_widget_below=function(t,i,e){return this._traversing_widgets("for_each","below",t,i,e),this},r.get_highest_occupied_cell=function(){for(var t,i=this.gridmap,e=i[1].length,s=[],r=[],o=i.length-1;o>=1;o--)for(t=e-1;t>=1;t--)if(this.is_widget(o,t)){s.push(t),r.push(o);break}return{col:Math.max.apply(Math,r),row:Math.max.apply(Math,s)}},r.get_widgets_from=function(i,e){this.gridmap;var s=t();return i&&(s=s.add(this.$widgets.filter(function(){var e=t(this).attr("data-col");return e===i||e>i}))),e&&(s=s.add(this.$widgets.filter(function(){var i=t(this).attr("data-row");return i===e||i>e}))),s},r.set_dom_grid_height=function(t){if(t===void 0){var i=this.get_highest_occupied_cell().row;t=i*this.min_widget_height}return this.container_height=t,this.$el.css("height",this.container_height),this},r.set_dom_grid_width=function(t){t===void 0&&(t=this.get_highest_occupied_cell().col);var i=this.options.autogrow_cols?this.options.max_cols:this.cols;return t=Math.min(i,Math.max(t,this.options.min_cols)),this.container_width=t*this.min_widget_width,this.$el.css("width",this.container_width),this},r.generate_stylesheet=function(i){var s,r="",o=this.options.max_size_x||this.cols;i||(i={}),i.cols||(i.cols=this.cols),i.rows||(i.rows=this.rows),i.namespace||(i.namespace=this.options.namespace),i.widget_base_dimensions||(i.widget_base_dimensions=this.options.widget_base_dimensions),i.widget_margins||(i.widget_margins=this.options.widget_margins),i.min_widget_width=2*i.widget_margins[0]+i.widget_base_dimensions[0],i.min_widget_height=2*i.widget_margins[1]+i.widget_base_dimensions[1];var a=t.param(i);if(t.inArray(a,e.generated_stylesheets)>=0)return!1;for(this.generated_stylesheets.push(a),e.generated_stylesheets.push(a),s=i.cols;s>=0;s--)r+=i.namespace+' [data-col="'+(s+1)+'"] { left:'+(s*i.widget_base_dimensions[0]+s*i.widget_margins[0]+(s+1)*i.widget_margins[0])+"px; }\n";for(s=i.rows;s>=0;s--)r+=i.namespace+' [data-row="'+(s+1)+'"] { top:'+(s*i.widget_base_dimensions[1]+s*i.widget_margins[1]+(s+1)*i.widget_margins[1])+"px; }\n";for(var n=1;i.rows>=n;n++)r+=i.namespace+' [data-sizey="'+n+'"] { height:'+(n*i.widget_base_dimensions[1]+(n-1)*2*i.widget_margins[1])+"px; }\n";for(var h=1;o>=h;h++)r+=i.namespace+' [data-sizex="'+h+'"] { width:'+(h*i.widget_base_dimensions[0]+(h-1)*2*i.widget_margins[0])+"px; }\n";return this.remove_style_tags(),this.add_style_tag(r)},r.add_style_tag=function(t){var i=document,e=i.createElement("style");return i.getElementsByTagName("head")[0].appendChild(e),e.setAttribute("type","text/css"),e.styleSheet?e.styleSheet.cssText=t:e.appendChild(document.createTextNode(t)),this.$style_tags=this.$style_tags.add(e),this},r.remove_style_tags=function(){var i=e.generated_stylesheets,s=this.generated_stylesheets;this.$style_tags.remove(),e.generated_stylesheets=t.map(i,function(i){return-1===t.inArray(i,s)?i:void 0})},r.generate_faux_grid=function(t,i){this.faux_grid=[],this.gridmap=[];var e,s;for(e=i;e>0;e--)for(this.gridmap[e]=[],s=t;s>0;s--)this.add_faux_cell(s,e);return this},r.add_faux_cell=function(i,e){var s=t({left:this.baseX+(e-1)*this.min_widget_width,top:this.baseY+(i-1)*this.min_widget_height,width:this.min_widget_width,height:this.min_widget_height,col:e,row:i,original_col:e,original_row:i}).coords();return t.isArray(this.gridmap[e])||(this.gridmap[e]=[]),this.gridmap[e][i]=!1,this.faux_grid.push(s),this},r.add_faux_rows=function(t){for(var i=this.rows,e=i+(t||1),s=e;s>i;s--)for(var r=this.cols;r>=1;r--)this.add_faux_cell(s,r);return this.rows=e,this.options.autogenerate_stylesheet&&this.generate_stylesheet(),this},r.add_faux_cols=function(t){var i=this.cols,e=i+(t||1);e=Math.min(e,this.options.max_cols);for(var s=i+1;e>=s;s++)for(var r=this.rows;r>=1;r--)this.add_faux_cell(r,s);return this.cols=e,this.options.autogenerate_stylesheet&&this.generate_stylesheet(),this},r.recalculate_faux_grid=function(){var i=this.$wrapper.width();return this.baseX=(t(window).width()-i)/2,this.baseY=this.$wrapper.offset().top,t.each(this.faux_grid,t.proxy(function(t,i){this.faux_grid[t]=i.update({left:this.baseX+(i.data.col-1)*this.min_widget_width,top:this.baseY+(i.data.row-1)*this.min_widget_height})},this)),this},r.get_widgets_from_DOM=function(){var i=this.$widgets.map(t.proxy(function(i,e){var s=t(e);return this.dom_to_coords(s)},this));i=e.sort_by_row_and_col_asc(i);var s=t(i).map(t.proxy(function(t,i){return this.register_widget(i)||null},this));return s.length&&this.$el.trigger("gridster:positionschanged"),this},r.generate_grid_and_stylesheet=function(){var i=this.$wrapper.width(),e=this.options.max_cols,s=Math.floor(i/this.min_widget_width)+this.options.extra_cols,r=this.$widgets.map(function(){return t(this).attr("data-col")}).get();r.length||(r=[0]);var o=Math.max.apply(Math,r);this.cols=Math.max(o,s,this.options.min_cols),1/0!==e&&e>=o&&this.cols>e&&(this.cols=e);var a=this.options.extra_rows;return this.$widgets.each(function(i,e){a+=+t(e).attr("data-sizey")}),this.rows=Math.max(a,this.options.min_rows),this.baseX=(t(window).width()-i)/2,this.baseY=this.$wrapper.offset().top,this.options.autogenerate_stylesheet&&this.generate_stylesheet(),this.generate_faux_grid(this.rows,this.cols)},r.destroy=function(i){return this.$el.removeData("gridster"),t(window).unbind(".gridster"),this.drag_api&&this.drag_api.destroy(),this.remove_style_tags(),i&&this.$el.remove(),this},t.fn.gridster=function(i){return this.each(function(){t(this).data("gridster")||t(this).data("gridster",new e(this,i))})},e}),function(t,i){"function"==typeof define&&define.amd?define(["jquery","gridster"],i):t.Gridster=i(t.$||t.jQuery,t.Gridster)}(this,function(t,i){var e=i.prototype;return e.widgets_in_col=function(t){if(!this.gridmap[t])return!1;for(var i=this.gridmap[t].length-1;i>=0;i--)if(this.is_widget(t,i)!==!1)return!0;return!1},e.widgets_in_row=function(t){for(var i=this.gridmap.length;i>=1;i--)if(this.is_widget(i,t)!==!1)return!0;return!1},e.widgets_in_range=function(i,e,s,r){var o,a,n,h,_=t([]);for(o=s;o>=i;o--)for(a=r;a>=e;a--)n=this.is_widget(o,a),n!==!1&&(h=n.data("coords").grid,h.col>=i&&s>=h.col&&h.row>=e&&r>=h.row&&(_=_.add(n)));return _},e.get_bottom_most_occupied_cell=function(){var t=0,i=0;return this.for_each_cell(function(e,s,r){e&&r>t&&(t=r,i=s)}),{col:i,row:t}},e.get_right_most_occupied_cell=function(){var t=0,i=0;return this.for_each_cell(function(e,s,r){return e?(t=r,i=s,!1):void 0}),{col:i,row:t}},e.for_each_cell=function(t,i){i||(i=this.gridmap);var e=i.length,s=i[1].length;t:for(var r=e-1;r>=1;r--)for(var o=s-1;o>=1;o--){var a=i[r]&&i[r][o];if(t){if(t.call(this,a,r,o)===!1)break t}else;}},e.next_position_in_range=function(t,e,s){t||(t=1),e||(e=1);for(var r,o=this.gridmap,a=o.length,n=[],h=1;a>h;h++){r=s||o[h].length;for(var _=1;r>=_;_++){var d=this.can_move_to({size_x:t,size_y:e},h,_,s);d&&n.push({col:h,row:_,size_y:e,size_x:t})}}return n.length>=1?i.sort_by_col_asc(n)[0]:!1},e.closest_to_right=function(t,i){if(!this.gridmap[t])return!1;for(var e=this.gridmap.length-1,s=t;e>=s;s++)if(this.gridmap[s][i])return{col:s,row:i};return!1},e.closest_to_left=function(t,i){if(this.gridmap.length-1,!this.gridmap[t])return!1;for(var e=t;e>=1;e--)if(this.gridmap[e][i])return{col:e,row:i};return!1},i});
\ No newline at end of file
diff --git a/grunt.js b/grunt.js
deleted file mode 100644
index b2fb2b60..00000000
--- a/grunt.js
+++ /dev/null
@@ -1,101 +0,0 @@
-/*global module:false*/
-module.exports = function(grunt) {
-
- // Project configuration.
- grunt.initConfig({
- pkg: '',
- meta: {
- banner: '/*! <%= pkg.title || pkg.name %> - v<%= pkg.version %> - ' +
- '<%= grunt.template.today("yyyy-mm-dd") %>\n' +
- '<%= pkg.homepage ? "* " + pkg.homepage + "\n" : "" %>' +
- '* Copyright (c) <%= grunt.template.today("yyyy") %> <%= pkg.author.name %>;' +
- ' Licensed <%= _.pluck(pkg.licenses, "type").join(", ") %> */'
- },
- concat: {
- dist_js: {
- src: ['', '', '', 'src/utils.js', '', '.js>'],
- dest: 'dist/<%= pkg.name %>.js'
- },
- dist_css: {
- src: ['', 'src/<%= pkg.name %>.css'],
- dest: 'dist/<%= pkg.name %>.css'
- },
-
- dist_demo_js: {
- src: ['', '', '', 'src/utils.js', '', '.js>'],
- dest: 'gh-pages/dist/<%= pkg.name %>.js'
- },
- dist_demo_css: {
- src: ['', 'src/<%= pkg.name %>.css'],
- dest: 'gh-pages/dist/<%= pkg.name %>.css'
- }
- },
- min: {
- dist: {
- src: ['', ''],
- dest: 'dist/<%= pkg.name %>.min.js'
- },
-
- dist_demo: {
- src: ['', ''],
- dest: 'gh-pages/dist/<%= pkg.name %>.min.js'
- }
- },
- mincss: {
- compress: {
- files: {
- "dist/<%= pkg.name %>.min.css": ["dist/<%= pkg.name %>.css"],
- "gh-pages/dist/<%= pkg.name %>.min.css": ["dist/<%= pkg.name %>.css"]
- }
- }
- },
- qunit: {
- files: ['test/**/*.html']
- },
- lint: {
- files: ['grunt.js', 'src/**/*.js', 'test/**/*.js']
- },
- watch: {
- files: ['', 'src/<%= pkg.name %>.css'],
- tasks: 'min concat'
- },
- jshint: {
- options: {
- curly: true,
- eqeqeq: true,
- immed: true,
- latedef: true,
- newcap: true,
- noarg: true,
- sub: true,
- undef: true,
- boss: true,
- eqnull: true,
- browser: true
- },
- globals: {
- jQuery: true
- }
- },
- uglify: {},
- yuidoc: {
- compile: {
- "name": 'gridster.js',
- "description": 'gridster.js, a drag-and-drop multi-column jQuery grid plugin',
- "version": '0.1.0',
- "url": 'http://gridster.net/',
- "logo": 'http://ducksboard.com/wp-content/themes/blog-theme-ducksboard/images/ducksboard.png',
- options: {
- paths: "src/",
- outdir: "gh-pages/docs/"
- }
- }
- }
- });
-
- grunt.loadNpmTasks('grunt-contrib');
-
- // Default task.
- grunt.registerTask('default', 'lint qunit concat min mincss yuidoc');
-
-};
diff --git a/libs/jquery/jquery.js b/libs/jquery/jquery.js
deleted file mode 100644
index 3774ff98..00000000
--- a/libs/jquery/jquery.js
+++ /dev/null
@@ -1,9404 +0,0 @@
-/*!
- * jQuery JavaScript Library v1.7.2
- * http://jquery.com/
- *
- * Copyright 2011, John Resig
- * Dual licensed under the MIT or GPL Version 2 licenses.
- * http://jquery.org/license
- *
- * Includes Sizzle.js
- * http://sizzlejs.com/
- * Copyright 2011, The Dojo Foundation
- * Released under the MIT, BSD, and GPL Licenses.
- *
- * Date: Wed Mar 21 12:46:34 2012 -0700
- */
-(function( window, undefined ) {
-
-// Use the correct document accordingly with window argument (sandbox)
-var document = window.document,
- navigator = window.navigator,
- location = window.location;
-var jQuery = (function() {
-
-// Define a local copy of jQuery
-var jQuery = function( selector, context ) {
- // The jQuery object is actually just the init constructor 'enhanced'
- return new jQuery.fn.init( selector, context, rootjQuery );
- },
-
- // Map over jQuery in case of overwrite
- _jQuery = window.jQuery,
-
- // Map over the $ in case of overwrite
- _$ = window.$,
-
- // A central reference to the root jQuery(document)
- rootjQuery,
-
- // A simple way to check for HTML strings or ID strings
- // Prioritize #id over to avoid XSS via location.hash (#9521)
- quickExpr = /^(?:[^#<]*(<[\w\W]+>)[^>]*$|#([\w\-]*)$)/,
-
- // Check if a string has a non-whitespace character in it
- rnotwhite = /\S/,
-
- // Used for trimming whitespace
- trimLeft = /^\s+/,
- trimRight = /\s+$/,
-
- // Match a standalone tag
- rsingleTag = /^<(\w+)\s*\/?>(?:<\/\1>)?$/,
-
- // JSON RegExp
- rvalidchars = /^[\],:{}\s]*$/,
- rvalidescape = /\\(?:["\\\/bfnrt]|u[0-9a-fA-F]{4})/g,
- rvalidtokens = /"[^"\\\n\r]*"|true|false|null|-?\d+(?:\.\d*)?(?:[eE][+\-]?\d+)?/g,
- rvalidbraces = /(?:^|:|,)(?:\s*\[)+/g,
-
- // Useragent RegExp
- rwebkit = /(webkit)[ \/]([\w.]+)/,
- ropera = /(opera)(?:.*version)?[ \/]([\w.]+)/,
- rmsie = /(msie) ([\w.]+)/,
- rmozilla = /(mozilla)(?:.*? rv:([\w.]+))?/,
-
- // Matches dashed string for camelizing
- rdashAlpha = /-([a-z]|[0-9])/ig,
- rmsPrefix = /^-ms-/,
-
- // Used by jQuery.camelCase as callback to replace()
- fcamelCase = function( all, letter ) {
- return ( letter + "" ).toUpperCase();
- },
-
- // Keep a UserAgent string for use with jQuery.browser
- userAgent = navigator.userAgent,
-
- // For matching the engine and version of the browser
- browserMatch,
-
- // The deferred used on DOM ready
- readyList,
-
- // The ready event handler
- DOMContentLoaded,
-
- // Save a reference to some core methods
- toString = Object.prototype.toString,
- hasOwn = Object.prototype.hasOwnProperty,
- push = Array.prototype.push,
- slice = Array.prototype.slice,
- trim = String.prototype.trim,
- indexOf = Array.prototype.indexOf,
-
- // [[Class]] -> type pairs
- class2type = {};
-
-jQuery.fn = jQuery.prototype = {
- constructor: jQuery,
- init: function( selector, context, rootjQuery ) {
- var match, elem, ret, doc;
-
- // Handle $(""), $(null), or $(undefined)
- if ( !selector ) {
- return this;
- }
-
- // Handle $(DOMElement)
- if ( selector.nodeType ) {
- this.context = this[0] = selector;
- this.length = 1;
- return this;
- }
-
- // The body element only exists once, optimize finding it
- if ( selector === "body" && !context && document.body ) {
- this.context = document;
- this[0] = document.body;
- this.selector = selector;
- this.length = 1;
- return this;
- }
-
- // Handle HTML strings
- if ( typeof selector === "string" ) {
- // Are we dealing with HTML string or an ID?
- if ( selector.charAt(0) === "<" && selector.charAt( selector.length - 1 ) === ">" && selector.length >= 3 ) {
- // Assume that strings that start and end with <> are HTML and skip the regex check
- match = [ null, selector, null ];
-
- } else {
- match = quickExpr.exec( selector );
- }
-
- // Verify a match, and that no context was specified for #id
- if ( match && (match[1] || !context) ) {
-
- // HANDLE: $(html) -> $(array)
- if ( match[1] ) {
- context = context instanceof jQuery ? context[0] : context;
- doc = ( context ? context.ownerDocument || context : document );
-
- // If a single string is passed in and it's a single tag
- // just do a createElement and skip the rest
- ret = rsingleTag.exec( selector );
-
- if ( ret ) {
- if ( jQuery.isPlainObject( context ) ) {
- selector = [ document.createElement( ret[1] ) ];
- jQuery.fn.attr.call( selector, context, true );
-
- } else {
- selector = [ doc.createElement( ret[1] ) ];
- }
-
- } else {
- ret = jQuery.buildFragment( [ match[1] ], [ doc ] );
- selector = ( ret.cacheable ? jQuery.clone(ret.fragment) : ret.fragment ).childNodes;
- }
-
- return jQuery.merge( this, selector );
-
- // HANDLE: $("#id")
- } else {
- elem = document.getElementById( match[2] );
-
- // Check parentNode to catch when Blackberry 4.6 returns
- // nodes that are no longer in the document #6963
- if ( elem && elem.parentNode ) {
- // Handle the case where IE and Opera return items
- // by name instead of ID
- if ( elem.id !== match[2] ) {
- return rootjQuery.find( selector );
- }
-
- // Otherwise, we inject the element directly into the jQuery object
- this.length = 1;
- this[0] = elem;
- }
-
- this.context = document;
- this.selector = selector;
- return this;
- }
-
- // HANDLE: $(expr, $(...))
- } else if ( !context || context.jquery ) {
- return ( context || rootjQuery ).find( selector );
-
- // HANDLE: $(expr, context)
- // (which is just equivalent to: $(context).find(expr)
- } else {
- return this.constructor( context ).find( selector );
- }
-
- // HANDLE: $(function)
- // Shortcut for document ready
- } else if ( jQuery.isFunction( selector ) ) {
- return rootjQuery.ready( selector );
- }
-
- if ( selector.selector !== undefined ) {
- this.selector = selector.selector;
- this.context = selector.context;
- }
-
- return jQuery.makeArray( selector, this );
- },
-
- // Start with an empty selector
- selector: "",
-
- // The current version of jQuery being used
- jquery: "1.7.2",
-
- // The default length of a jQuery object is 0
- length: 0,
-
- // The number of elements contained in the matched element set
- size: function() {
- return this.length;
- },
-
- toArray: function() {
- return slice.call( this, 0 );
- },
-
- // Get the Nth element in the matched element set OR
- // Get the whole matched element set as a clean array
- get: function( num ) {
- return num == null ?
-
- // Return a 'clean' array
- this.toArray() :
-
- // Return just the object
- ( num < 0 ? this[ this.length + num ] : this[ num ] );
- },
-
- // Take an array of elements and push it onto the stack
- // (returning the new matched element set)
- pushStack: function( elems, name, selector ) {
- // Build a new jQuery matched element set
- var ret = this.constructor();
-
- if ( jQuery.isArray( elems ) ) {
- push.apply( ret, elems );
-
- } else {
- jQuery.merge( ret, elems );
- }
-
- // Add the old object onto the stack (as a reference)
- ret.prevObject = this;
-
- ret.context = this.context;
-
- if ( name === "find" ) {
- ret.selector = this.selector + ( this.selector ? " " : "" ) + selector;
- } else if ( name ) {
- ret.selector = this.selector + "." + name + "(" + selector + ")";
- }
-
- // Return the newly-formed element set
- return ret;
- },
-
- // Execute a callback for every element in the matched set.
- // (You can seed the arguments with an array of args, but this is
- // only used internally.)
- each: function( callback, args ) {
- return jQuery.each( this, callback, args );
- },
-
- ready: function( fn ) {
- // Attach the listeners
- jQuery.bindReady();
-
- // Add the callback
- readyList.add( fn );
-
- return this;
- },
-
- eq: function( i ) {
- i = +i;
- return i === -1 ?
- this.slice( i ) :
- this.slice( i, i + 1 );
- },
-
- first: function() {
- return this.eq( 0 );
- },
-
- last: function() {
- return this.eq( -1 );
- },
-
- slice: function() {
- return this.pushStack( slice.apply( this, arguments ),
- "slice", slice.call(arguments).join(",") );
- },
-
- map: function( callback ) {
- return this.pushStack( jQuery.map(this, function( elem, i ) {
- return callback.call( elem, i, elem );
- }));
- },
-
- end: function() {
- return this.prevObject || this.constructor(null);
- },
-
- // For internal use only.
- // Behaves like an Array's method, not like a jQuery method.
- push: push,
- sort: [].sort,
- splice: [].splice
-};
-
-// Give the init function the jQuery prototype for later instantiation
-jQuery.fn.init.prototype = jQuery.fn;
-
-jQuery.extend = jQuery.fn.extend = function() {
- var options, name, src, copy, copyIsArray, clone,
- target = arguments[0] || {},
- i = 1,
- length = arguments.length,
- deep = false;
-
- // Handle a deep copy situation
- if ( typeof target === "boolean" ) {
- deep = target;
- target = arguments[1] || {};
- // skip the boolean and the target
- i = 2;
- }
-
- // Handle case when target is a string or something (possible in deep copy)
- if ( typeof target !== "object" && !jQuery.isFunction(target) ) {
- target = {};
- }
-
- // extend jQuery itself if only one argument is passed
- if ( length === i ) {
- target = this;
- --i;
- }
-
- for ( ; i < length; i++ ) {
- // Only deal with non-null/undefined values
- if ( (options = arguments[ i ]) != null ) {
- // Extend the base object
- for ( name in options ) {
- src = target[ name ];
- copy = options[ name ];
-
- // Prevent never-ending loop
- if ( target === copy ) {
- continue;
- }
-
- // Recurse if we're merging plain objects or arrays
- if ( deep && copy && ( jQuery.isPlainObject(copy) || (copyIsArray = jQuery.isArray(copy)) ) ) {
- if ( copyIsArray ) {
- copyIsArray = false;
- clone = src && jQuery.isArray(src) ? src : [];
-
- } else {
- clone = src && jQuery.isPlainObject(src) ? src : {};
- }
-
- // Never move original objects, clone them
- target[ name ] = jQuery.extend( deep, clone, copy );
-
- // Don't bring in undefined values
- } else if ( copy !== undefined ) {
- target[ name ] = copy;
- }
- }
- }
- }
-
- // Return the modified object
- return target;
-};
-
-jQuery.extend({
- noConflict: function( deep ) {
- if ( window.$ === jQuery ) {
- window.$ = _$;
- }
-
- if ( deep && window.jQuery === jQuery ) {
- window.jQuery = _jQuery;
- }
-
- return jQuery;
- },
-
- // Is the DOM ready to be used? Set to true once it occurs.
- isReady: false,
-
- // A counter to track how many items to wait for before
- // the ready event fires. See #6781
- readyWait: 1,
-
- // Hold (or release) the ready event
- holdReady: function( hold ) {
- if ( hold ) {
- jQuery.readyWait++;
- } else {
- jQuery.ready( true );
- }
- },
-
- // Handle when the DOM is ready
- ready: function( wait ) {
- // Either a released hold or an DOMready/load event and not yet ready
- if ( (wait === true && !--jQuery.readyWait) || (wait !== true && !jQuery.isReady) ) {
- // Make sure body exists, at least, in case IE gets a little overzealous (ticket #5443).
- if ( !document.body ) {
- return setTimeout( jQuery.ready, 1 );
- }
-
- // Remember that the DOM is ready
- jQuery.isReady = true;
-
- // If a normal DOM Ready event fired, decrement, and wait if need be
- if ( wait !== true && --jQuery.readyWait > 0 ) {
- return;
- }
-
- // If there are functions bound, to execute
- readyList.fireWith( document, [ jQuery ] );
-
- // Trigger any bound ready events
- if ( jQuery.fn.trigger ) {
- jQuery( document ).trigger( "ready" ).off( "ready" );
- }
- }
- },
-
- bindReady: function() {
- if ( readyList ) {
- return;
- }
-
- readyList = jQuery.Callbacks( "once memory" );
-
- // Catch cases where $(document).ready() is called after the
- // browser event has already occurred.
- if ( document.readyState === "complete" ) {
- // Handle it asynchronously to allow scripts the opportunity to delay ready
- return setTimeout( jQuery.ready, 1 );
- }
-
- // Mozilla, Opera and webkit nightlies currently support this event
- if ( document.addEventListener ) {
- // Use the handy event callback
- document.addEventListener( "DOMContentLoaded", DOMContentLoaded, false );
-
- // A fallback to window.onload, that will always work
- window.addEventListener( "load", jQuery.ready, false );
-
- // If IE event model is used
- } else if ( document.attachEvent ) {
- // ensure firing before onload,
- // maybe late but safe also for iframes
- document.attachEvent( "onreadystatechange", DOMContentLoaded );
-
- // A fallback to window.onload, that will always work
- window.attachEvent( "onload", jQuery.ready );
-
- // If IE and not a frame
- // continually check to see if the document is ready
- var toplevel = false;
-
- try {
- toplevel = window.frameElement == null;
- } catch(e) {}
-
- if ( document.documentElement.doScroll && toplevel ) {
- doScrollCheck();
- }
- }
- },
-
- // See test/unit/core.js for details concerning isFunction.
- // Since version 1.3, DOM methods and functions like alert
- // aren't supported. They return false on IE (#2968).
- isFunction: function( obj ) {
- return jQuery.type(obj) === "function";
- },
-
- isArray: Array.isArray || function( obj ) {
- return jQuery.type(obj) === "array";
- },
-
- isWindow: function( obj ) {
- return obj != null && obj == obj.window;
- },
-
- isNumeric: function( obj ) {
- return !isNaN( parseFloat(obj) ) && isFinite( obj );
- },
-
- type: function( obj ) {
- return obj == null ?
- String( obj ) :
- class2type[ toString.call(obj) ] || "object";
- },
-
- isPlainObject: function( obj ) {
- // Must be an Object.
- // Because of IE, we also have to check the presence of the constructor property.
- // Make sure that DOM nodes and window objects don't pass through, as well
- if ( !obj || jQuery.type(obj) !== "object" || obj.nodeType || jQuery.isWindow( obj ) ) {
- return false;
- }
-
- try {
- // Not own constructor property must be Object
- if ( obj.constructor &&
- !hasOwn.call(obj, "constructor") &&
- !hasOwn.call(obj.constructor.prototype, "isPrototypeOf") ) {
- return false;
- }
- } catch ( e ) {
- // IE8,9 Will throw exceptions on certain host objects #9897
- return false;
- }
-
- // Own properties are enumerated firstly, so to speed up,
- // if last one is own, then all properties are own.
-
- var key;
- for ( key in obj ) {}
-
- return key === undefined || hasOwn.call( obj, key );
- },
-
- isEmptyObject: function( obj ) {
- for ( var name in obj ) {
- return false;
- }
- return true;
- },
-
- error: function( msg ) {
- throw new Error( msg );
- },
-
- parseJSON: function( data ) {
- if ( typeof data !== "string" || !data ) {
- return null;
- }
-
- // Make sure leading/trailing whitespace is removed (IE can't handle it)
- data = jQuery.trim( data );
-
- // Attempt to parse using the native JSON parser first
- if ( window.JSON && window.JSON.parse ) {
- return window.JSON.parse( data );
- }
-
- // Make sure the incoming data is actual JSON
- // Logic borrowed from http://json.org/json2.js
- if ( rvalidchars.test( data.replace( rvalidescape, "@" )
- .replace( rvalidtokens, "]" )
- .replace( rvalidbraces, "")) ) {
-
- return ( new Function( "return " + data ) )();
-
- }
- jQuery.error( "Invalid JSON: " + data );
- },
-
- // Cross-browser xml parsing
- parseXML: function( data ) {
- if ( typeof data !== "string" || !data ) {
- return null;
- }
- var xml, tmp;
- try {
- if ( window.DOMParser ) { // Standard
- tmp = new DOMParser();
- xml = tmp.parseFromString( data , "text/xml" );
- } else { // IE
- xml = new ActiveXObject( "Microsoft.XMLDOM" );
- xml.async = "false";
- xml.loadXML( data );
- }
- } catch( e ) {
- xml = undefined;
- }
- if ( !xml || !xml.documentElement || xml.getElementsByTagName( "parsererror" ).length ) {
- jQuery.error( "Invalid XML: " + data );
- }
- return xml;
- },
-
- noop: function() {},
-
- // Evaluates a script in a global context
- // Workarounds based on findings by Jim Driscoll
- // http://weblogs.java.net/blog/driscoll/archive/2009/09/08/eval-javascript-global-context
- globalEval: function( data ) {
- if ( data && rnotwhite.test( data ) ) {
- // We use execScript on Internet Explorer
- // We use an anonymous function so that context is window
- // rather than jQuery in Firefox
- ( window.execScript || function( data ) {
- window[ "eval" ].call( window, data );
- } )( data );
- }
- },
-
- // Convert dashed to camelCase; used by the css and data modules
- // Microsoft forgot to hump their vendor prefix (#9572)
- camelCase: function( string ) {
- return string.replace( rmsPrefix, "ms-" ).replace( rdashAlpha, fcamelCase );
- },
-
- nodeName: function( elem, name ) {
- return elem.nodeName && elem.nodeName.toUpperCase() === name.toUpperCase();
- },
-
- // args is for internal usage only
- each: function( object, callback, args ) {
- var name, i = 0,
- length = object.length,
- isObj = length === undefined || jQuery.isFunction( object );
-
- if ( args ) {
- if ( isObj ) {
- for ( name in object ) {
- if ( callback.apply( object[ name ], args ) === false ) {
- break;
- }
- }
- } else {
- for ( ; i < length; ) {
- if ( callback.apply( object[ i++ ], args ) === false ) {
- break;
- }
- }
- }
-
- // A special, fast, case for the most common use of each
- } else {
- if ( isObj ) {
- for ( name in object ) {
- if ( callback.call( object[ name ], name, object[ name ] ) === false ) {
- break;
- }
- }
- } else {
- for ( ; i < length; ) {
- if ( callback.call( object[ i ], i, object[ i++ ] ) === false ) {
- break;
- }
- }
- }
- }
-
- return object;
- },
-
- // Use native String.trim function wherever possible
- trim: trim ?
- function( text ) {
- return text == null ?
- "" :
- trim.call( text );
- } :
-
- // Otherwise use our own trimming functionality
- function( text ) {
- return text == null ?
- "" :
- text.toString().replace( trimLeft, "" ).replace( trimRight, "" );
- },
-
- // results is for internal usage only
- makeArray: function( array, results ) {
- var ret = results || [];
-
- if ( array != null ) {
- // The window, strings (and functions) also have 'length'
- // Tweaked logic slightly to handle Blackberry 4.7 RegExp issues #6930
- var type = jQuery.type( array );
-
- if ( array.length == null || type === "string" || type === "function" || type === "regexp" || jQuery.isWindow( array ) ) {
- push.call( ret, array );
- } else {
- jQuery.merge( ret, array );
- }
- }
-
- return ret;
- },
-
- inArray: function( elem, array, i ) {
- var len;
-
- if ( array ) {
- if ( indexOf ) {
- return indexOf.call( array, elem, i );
- }
-
- len = array.length;
- i = i ? i < 0 ? Math.max( 0, len + i ) : i : 0;
-
- for ( ; i < len; i++ ) {
- // Skip accessing in sparse arrays
- if ( i in array && array[ i ] === elem ) {
- return i;
- }
- }
- }
-
- return -1;
- },
-
- merge: function( first, second ) {
- var i = first.length,
- j = 0;
-
- if ( typeof second.length === "number" ) {
- for ( var l = second.length; j < l; j++ ) {
- first[ i++ ] = second[ j ];
- }
-
- } else {
- while ( second[j] !== undefined ) {
- first[ i++ ] = second[ j++ ];
- }
- }
-
- first.length = i;
-
- return first;
- },
-
- grep: function( elems, callback, inv ) {
- var ret = [], retVal;
- inv = !!inv;
-
- // Go through the array, only saving the items
- // that pass the validator function
- for ( var i = 0, length = elems.length; i < length; i++ ) {
- retVal = !!callback( elems[ i ], i );
- if ( inv !== retVal ) {
- ret.push( elems[ i ] );
- }
- }
-
- return ret;
- },
-
- // arg is for internal usage only
- map: function( elems, callback, arg ) {
- var value, key, ret = [],
- i = 0,
- length = elems.length,
- // jquery objects are treated as arrays
- isArray = elems instanceof jQuery || length !== undefined && typeof length === "number" && ( ( length > 0 && elems[ 0 ] && elems[ length -1 ] ) || length === 0 || jQuery.isArray( elems ) ) ;
-
- // Go through the array, translating each of the items to their
- if ( isArray ) {
- for ( ; i < length; i++ ) {
- value = callback( elems[ i ], i, arg );
-
- if ( value != null ) {
- ret[ ret.length ] = value;
- }
- }
-
- // Go through every key on the object,
- } else {
- for ( key in elems ) {
- value = callback( elems[ key ], key, arg );
-
- if ( value != null ) {
- ret[ ret.length ] = value;
- }
- }
- }
-
- // Flatten any nested arrays
- return ret.concat.apply( [], ret );
- },
-
- // A global GUID counter for objects
- guid: 1,
-
- // Bind a function to a context, optionally partially applying any
- // arguments.
- proxy: function( fn, context ) {
- if ( typeof context === "string" ) {
- var tmp = fn[ context ];
- context = fn;
- fn = tmp;
- }
-
- // Quick check to determine if target is callable, in the spec
- // this throws a TypeError, but we will just return undefined.
- if ( !jQuery.isFunction( fn ) ) {
- return undefined;
- }
-
- // Simulated bind
- var args = slice.call( arguments, 2 ),
- proxy = function() {
- return fn.apply( context, args.concat( slice.call( arguments ) ) );
- };
-
- // Set the guid of unique handler to the same of original handler, so it can be removed
- proxy.guid = fn.guid = fn.guid || proxy.guid || jQuery.guid++;
-
- return proxy;
- },
-
- // Mutifunctional method to get and set values to a collection
- // The value/s can optionally be executed if it's a function
- access: function( elems, fn, key, value, chainable, emptyGet, pass ) {
- var exec,
- bulk = key == null,
- i = 0,
- length = elems.length;
-
- // Sets many values
- if ( key && typeof key === "object" ) {
- for ( i in key ) {
- jQuery.access( elems, fn, i, key[i], 1, emptyGet, value );
- }
- chainable = 1;
-
- // Sets one value
- } else if ( value !== undefined ) {
- // Optionally, function values get executed if exec is true
- exec = pass === undefined && jQuery.isFunction( value );
-
- if ( bulk ) {
- // Bulk operations only iterate when executing function values
- if ( exec ) {
- exec = fn;
- fn = function( elem, key, value ) {
- return exec.call( jQuery( elem ), value );
- };
-
- // Otherwise they run against the entire set
- } else {
- fn.call( elems, value );
- fn = null;
- }
- }
-
- if ( fn ) {
- for (; i < length; i++ ) {
- fn( elems[i], key, exec ? value.call( elems[i], i, fn( elems[i], key ) ) : value, pass );
- }
- }
-
- chainable = 1;
- }
-
- return chainable ?
- elems :
-
- // Gets
- bulk ?
- fn.call( elems ) :
- length ? fn( elems[0], key ) : emptyGet;
- },
-
- now: function() {
- return ( new Date() ).getTime();
- },
-
- // Use of jQuery.browser is frowned upon.
- // More details: http://docs.jquery.com/Utilities/jQuery.browser
- uaMatch: function( ua ) {
- ua = ua.toLowerCase();
-
- var match = rwebkit.exec( ua ) ||
- ropera.exec( ua ) ||
- rmsie.exec( ua ) ||
- ua.indexOf("compatible") < 0 && rmozilla.exec( ua ) ||
- [];
-
- return { browser: match[1] || "", version: match[2] || "0" };
- },
-
- sub: function() {
- function jQuerySub( selector, context ) {
- return new jQuerySub.fn.init( selector, context );
- }
- jQuery.extend( true, jQuerySub, this );
- jQuerySub.superclass = this;
- jQuerySub.fn = jQuerySub.prototype = this();
- jQuerySub.fn.constructor = jQuerySub;
- jQuerySub.sub = this.sub;
- jQuerySub.fn.init = function init( selector, context ) {
- if ( context && context instanceof jQuery && !(context instanceof jQuerySub) ) {
- context = jQuerySub( context );
- }
-
- return jQuery.fn.init.call( this, selector, context, rootjQuerySub );
- };
- jQuerySub.fn.init.prototype = jQuerySub.fn;
- var rootjQuerySub = jQuerySub(document);
- return jQuerySub;
- },
-
- browser: {}
-});
-
-// Populate the class2type map
-jQuery.each("Boolean Number String Function Array Date RegExp Object".split(" "), function(i, name) {
- class2type[ "[object " + name + "]" ] = name.toLowerCase();
-});
-
-browserMatch = jQuery.uaMatch( userAgent );
-if ( browserMatch.browser ) {
- jQuery.browser[ browserMatch.browser ] = true;
- jQuery.browser.version = browserMatch.version;
-}
-
-// Deprecated, use jQuery.browser.webkit instead
-if ( jQuery.browser.webkit ) {
- jQuery.browser.safari = true;
-}
-
-// IE doesn't match non-breaking spaces with \s
-if ( rnotwhite.test( "\xA0" ) ) {
- trimLeft = /^[\s\xA0]+/;
- trimRight = /[\s\xA0]+$/;
-}
-
-// All jQuery objects should point back to these
-rootjQuery = jQuery(document);
-
-// Cleanup functions for the document ready method
-if ( document.addEventListener ) {
- DOMContentLoaded = function() {
- document.removeEventListener( "DOMContentLoaded", DOMContentLoaded, false );
- jQuery.ready();
- };
-
-} else if ( document.attachEvent ) {
- DOMContentLoaded = function() {
- // Make sure body exists, at least, in case IE gets a little overzealous (ticket #5443).
- if ( document.readyState === "complete" ) {
- document.detachEvent( "onreadystatechange", DOMContentLoaded );
- jQuery.ready();
- }
- };
-}
-
-// The DOM ready check for Internet Explorer
-function doScrollCheck() {
- if ( jQuery.isReady ) {
- return;
- }
-
- try {
- // If IE is used, use the trick by Diego Perini
- // http://javascript.nwbox.com/IEContentLoaded/
- document.documentElement.doScroll("left");
- } catch(e) {
- setTimeout( doScrollCheck, 1 );
- return;
- }
-
- // and execute any waiting functions
- jQuery.ready();
-}
-
-return jQuery;
-
-})();
-
-
-// String to Object flags format cache
-var flagsCache = {};
-
-// Convert String-formatted flags into Object-formatted ones and store in cache
-function createFlags( flags ) {
- var object = flagsCache[ flags ] = {},
- i, length;
- flags = flags.split( /\s+/ );
- for ( i = 0, length = flags.length; i < length; i++ ) {
- object[ flags[i] ] = true;
- }
- return object;
-}
-
-/*
- * Create a callback list using the following parameters:
- *
- * flags: an optional list of space-separated flags that will change how
- * the callback list behaves
- *
- * By default a callback list will act like an event callback list and can be
- * "fired" multiple times.
- *
- * Possible flags:
- *
- * once: will ensure the callback list can only be fired once (like a Deferred)
- *
- * memory: will keep track of previous values and will call any callback added
- * after the list has been fired right away with the latest "memorized"
- * values (like a Deferred)
- *
- * unique: will ensure a callback can only be added once (no duplicate in the list)
- *
- * stopOnFalse: interrupt callings when a callback returns false
- *
- */
-jQuery.Callbacks = function( flags ) {
-
- // Convert flags from String-formatted to Object-formatted
- // (we check in cache first)
- flags = flags ? ( flagsCache[ flags ] || createFlags( flags ) ) : {};
-
- var // Actual callback list
- list = [],
- // Stack of fire calls for repeatable lists
- stack = [],
- // Last fire value (for non-forgettable lists)
- memory,
- // Flag to know if list was already fired
- fired,
- // Flag to know if list is currently firing
- firing,
- // First callback to fire (used internally by add and fireWith)
- firingStart,
- // End of the loop when firing
- firingLength,
- // Index of currently firing callback (modified by remove if needed)
- firingIndex,
- // Add one or several callbacks to the list
- add = function( args ) {
- var i,
- length,
- elem,
- type,
- actual;
- for ( i = 0, length = args.length; i < length; i++ ) {
- elem = args[ i ];
- type = jQuery.type( elem );
- if ( type === "array" ) {
- // Inspect recursively
- add( elem );
- } else if ( type === "function" ) {
- // Add if not in unique mode and callback is not in
- if ( !flags.unique || !self.has( elem ) ) {
- list.push( elem );
- }
- }
- }
- },
- // Fire callbacks
- fire = function( context, args ) {
- args = args || [];
- memory = !flags.memory || [ context, args ];
- fired = true;
- firing = true;
- firingIndex = firingStart || 0;
- firingStart = 0;
- firingLength = list.length;
- for ( ; list && firingIndex < firingLength; firingIndex++ ) {
- if ( list[ firingIndex ].apply( context, args ) === false && flags.stopOnFalse ) {
- memory = true; // Mark as halted
- break;
- }
- }
- firing = false;
- if ( list ) {
- if ( !flags.once ) {
- if ( stack && stack.length ) {
- memory = stack.shift();
- self.fireWith( memory[ 0 ], memory[ 1 ] );
- }
- } else if ( memory === true ) {
- self.disable();
- } else {
- list = [];
- }
- }
- },
- // Actual Callbacks object
- self = {
- // Add a callback or a collection of callbacks to the list
- add: function() {
- if ( list ) {
- var length = list.length;
- add( arguments );
- // Do we need to add the callbacks to the
- // current firing batch?
- if ( firing ) {
- firingLength = list.length;
- // With memory, if we're not firing then
- // we should call right away, unless previous
- // firing was halted (stopOnFalse)
- } else if ( memory && memory !== true ) {
- firingStart = length;
- fire( memory[ 0 ], memory[ 1 ] );
- }
- }
- return this;
- },
- // Remove a callback from the list
- remove: function() {
- if ( list ) {
- var args = arguments,
- argIndex = 0,
- argLength = args.length;
- for ( ; argIndex < argLength ; argIndex++ ) {
- for ( var i = 0; i < list.length; i++ ) {
- if ( args[ argIndex ] === list[ i ] ) {
- // Handle firingIndex and firingLength
- if ( firing ) {
- if ( i <= firingLength ) {
- firingLength--;
- if ( i <= firingIndex ) {
- firingIndex--;
- }
- }
- }
- // Remove the element
- list.splice( i--, 1 );
- // If we have some unicity property then
- // we only need to do this once
- if ( flags.unique ) {
- break;
- }
- }
- }
- }
- }
- return this;
- },
- // Control if a given callback is in the list
- has: function( fn ) {
- if ( list ) {
- var i = 0,
- length = list.length;
- for ( ; i < length; i++ ) {
- if ( fn === list[ i ] ) {
- return true;
- }
- }
- }
- return false;
- },
- // Remove all callbacks from the list
- empty: function() {
- list = [];
- return this;
- },
- // Have the list do nothing anymore
- disable: function() {
- list = stack = memory = undefined;
- return this;
- },
- // Is it disabled?
- disabled: function() {
- return !list;
- },
- // Lock the list in its current state
- lock: function() {
- stack = undefined;
- if ( !memory || memory === true ) {
- self.disable();
- }
- return this;
- },
- // Is it locked?
- locked: function() {
- return !stack;
- },
- // Call all callbacks with the given context and arguments
- fireWith: function( context, args ) {
- if ( stack ) {
- if ( firing ) {
- if ( !flags.once ) {
- stack.push( [ context, args ] );
- }
- } else if ( !( flags.once && memory ) ) {
- fire( context, args );
- }
- }
- return this;
- },
- // Call all the callbacks with the given arguments
- fire: function() {
- self.fireWith( this, arguments );
- return this;
- },
- // To know if the callbacks have already been called at least once
- fired: function() {
- return !!fired;
- }
- };
-
- return self;
-};
-
-
-
-
-var // Static reference to slice
- sliceDeferred = [].slice;
-
-jQuery.extend({
-
- Deferred: function( func ) {
- var doneList = jQuery.Callbacks( "once memory" ),
- failList = jQuery.Callbacks( "once memory" ),
- progressList = jQuery.Callbacks( "memory" ),
- state = "pending",
- lists = {
- resolve: doneList,
- reject: failList,
- notify: progressList
- },
- promise = {
- done: doneList.add,
- fail: failList.add,
- progress: progressList.add,
-
- state: function() {
- return state;
- },
-
- // Deprecated
- isResolved: doneList.fired,
- isRejected: failList.fired,
-
- then: function( doneCallbacks, failCallbacks, progressCallbacks ) {
- deferred.done( doneCallbacks ).fail( failCallbacks ).progress( progressCallbacks );
- return this;
- },
- always: function() {
- deferred.done.apply( deferred, arguments ).fail.apply( deferred, arguments );
- return this;
- },
- pipe: function( fnDone, fnFail, fnProgress ) {
- return jQuery.Deferred(function( newDefer ) {
- jQuery.each( {
- done: [ fnDone, "resolve" ],
- fail: [ fnFail, "reject" ],
- progress: [ fnProgress, "notify" ]
- }, function( handler, data ) {
- var fn = data[ 0 ],
- action = data[ 1 ],
- returned;
- if ( jQuery.isFunction( fn ) ) {
- deferred[ handler ](function() {
- returned = fn.apply( this, arguments );
- if ( returned && jQuery.isFunction( returned.promise ) ) {
- returned.promise().then( newDefer.resolve, newDefer.reject, newDefer.notify );
- } else {
- newDefer[ action + "With" ]( this === deferred ? newDefer : this, [ returned ] );
- }
- });
- } else {
- deferred[ handler ]( newDefer[ action ] );
- }
- });
- }).promise();
- },
- // Get a promise for this deferred
- // If obj is provided, the promise aspect is added to the object
- promise: function( obj ) {
- if ( obj == null ) {
- obj = promise;
- } else {
- for ( var key in promise ) {
- obj[ key ] = promise[ key ];
- }
- }
- return obj;
- }
- },
- deferred = promise.promise({}),
- key;
-
- for ( key in lists ) {
- deferred[ key ] = lists[ key ].fire;
- deferred[ key + "With" ] = lists[ key ].fireWith;
- }
-
- // Handle state
- deferred.done( function() {
- state = "resolved";
- }, failList.disable, progressList.lock ).fail( function() {
- state = "rejected";
- }, doneList.disable, progressList.lock );
-
- // Call given func if any
- if ( func ) {
- func.call( deferred, deferred );
- }
-
- // All done!
- return deferred;
- },
-
- // Deferred helper
- when: function( firstParam ) {
- var args = sliceDeferred.call( arguments, 0 ),
- i = 0,
- length = args.length,
- pValues = new Array( length ),
- count = length,
- pCount = length,
- deferred = length <= 1 && firstParam && jQuery.isFunction( firstParam.promise ) ?
- firstParam :
- jQuery.Deferred(),
- promise = deferred.promise();
- function resolveFunc( i ) {
- return function( value ) {
- args[ i ] = arguments.length > 1 ? sliceDeferred.call( arguments, 0 ) : value;
- if ( !( --count ) ) {
- deferred.resolveWith( deferred, args );
- }
- };
- }
- function progressFunc( i ) {
- return function( value ) {
- pValues[ i ] = arguments.length > 1 ? sliceDeferred.call( arguments, 0 ) : value;
- deferred.notifyWith( promise, pValues );
- };
- }
- if ( length > 1 ) {
- for ( ; i < length; i++ ) {
- if ( args[ i ] && args[ i ].promise && jQuery.isFunction( args[ i ].promise ) ) {
- args[ i ].promise().then( resolveFunc(i), deferred.reject, progressFunc(i) );
- } else {
- --count;
- }
- }
- if ( !count ) {
- deferred.resolveWith( deferred, args );
- }
- } else if ( deferred !== firstParam ) {
- deferred.resolveWith( deferred, length ? [ firstParam ] : [] );
- }
- return promise;
- }
-});
-
-
-
-
-jQuery.support = (function() {
-
- var support,
- all,
- a,
- select,
- opt,
- input,
- fragment,
- tds,
- events,
- eventName,
- i,
- isSupported,
- div = document.createElement( "div" ),
- documentElement = document.documentElement;
-
- // Preliminary tests
- div.setAttribute("className", "t");
- div.innerHTML = "
a";
-
- all = div.getElementsByTagName( "*" );
- a = div.getElementsByTagName( "a" )[ 0 ];
-
- // Can't get basic test support
- if ( !all || !all.length || !a ) {
- return {};
- }
-
- // First batch of supports tests
- select = document.createElement( "select" );
- opt = select.appendChild( document.createElement("option") );
- input = div.getElementsByTagName( "input" )[ 0 ];
-
- support = {
- // IE strips leading whitespace when .innerHTML is used
- leadingWhitespace: ( div.firstChild.nodeType === 3 ),
-
- // Make sure that tbody elements aren't automatically inserted
- // IE will insert them into empty tables
- tbody: !div.getElementsByTagName("tbody").length,
-
- // Make sure that link elements get serialized correctly by innerHTML
- // This requires a wrapper element in IE
- htmlSerialize: !!div.getElementsByTagName("link").length,
-
- // Get the style information from getAttribute
- // (IE uses .cssText instead)
- style: /top/.test( a.getAttribute("style") ),
-
- // Make sure that URLs aren't manipulated
- // (IE normalizes it by default)
- hrefNormalized: ( a.getAttribute("href") === "/a" ),
-
- // Make sure that element opacity exists
- // (IE uses filter instead)
- // Use a regex to work around a WebKit issue. See #5145
- opacity: /^0.55/.test( a.style.opacity ),
-
- // Verify style float existence
- // (IE uses styleFloat instead of cssFloat)
- cssFloat: !!a.style.cssFloat,
-
- // Make sure that if no value is specified for a checkbox
- // that it defaults to "on".
- // (WebKit defaults to "" instead)
- checkOn: ( input.value === "on" ),
-
- // Make sure that a selected-by-default option has a working selected property.
- // (WebKit defaults to false instead of true, IE too, if it's in an optgroup)
- optSelected: opt.selected,
-
- // Test setAttribute on camelCase class. If it works, we need attrFixes when doing get/setAttribute (ie6/7)
- getSetAttribute: div.className !== "t",
-
- // Tests for enctype support on a form(#6743)
- enctype: !!document.createElement("form").enctype,
-
- // Makes sure cloning an html5 element does not cause problems
- // Where outerHTML is undefined, this still works
- html5Clone: document.createElement("nav").cloneNode( true ).outerHTML !== "<:nav>",
-
- // Will be defined later
- submitBubbles: true,
- changeBubbles: true,
- focusinBubbles: false,
- deleteExpando: true,
- noCloneEvent: true,
- inlineBlockNeedsLayout: false,
- shrinkWrapBlocks: false,
- reliableMarginRight: true,
- pixelMargin: true
- };
-
- // jQuery.boxModel DEPRECATED in 1.3, use jQuery.support.boxModel instead
- jQuery.boxModel = support.boxModel = (document.compatMode === "CSS1Compat");
-
- // Make sure checked status is properly cloned
- input.checked = true;
- support.noCloneChecked = input.cloneNode( true ).checked;
-
- // Make sure that the options inside disabled selects aren't marked as disabled
- // (WebKit marks them as disabled)
- select.disabled = true;
- support.optDisabled = !opt.disabled;
-
- // Test to see if it's possible to delete an expando from an element
- // Fails in Internet Explorer
- try {
- delete div.test;
- } catch( e ) {
- support.deleteExpando = false;
- }
-
- if ( !div.addEventListener && div.attachEvent && div.fireEvent ) {
- div.attachEvent( "onclick", function() {
- // Cloning a node shouldn't copy over any
- // bound event handlers (IE does this)
- support.noCloneEvent = false;
- });
- div.cloneNode( true ).fireEvent( "onclick" );
- }
-
- // Check if a radio maintains its value
- // after being appended to the DOM
- input = document.createElement("input");
- input.value = "t";
- input.setAttribute("type", "radio");
- support.radioValue = input.value === "t";
-
- input.setAttribute("checked", "checked");
-
- // #11217 - WebKit loses check when the name is after the checked attribute
- input.setAttribute( "name", "t" );
-
- div.appendChild( input );
- fragment = document.createDocumentFragment();
- fragment.appendChild( div.lastChild );
-
- // WebKit doesn't clone checked state correctly in fragments
- support.checkClone = fragment.cloneNode( true ).cloneNode( true ).lastChild.checked;
-
- // Check if a disconnected checkbox will retain its checked
- // value of true after appended to the DOM (IE6/7)
- support.appendChecked = input.checked;
-
- fragment.removeChild( input );
- fragment.appendChild( div );
-
- // Technique from Juriy Zaytsev
- // http://perfectionkills.com/detecting-event-support-without-browser-sniffing/
- // We only care about the case where non-standard event systems
- // are used, namely in IE. Short-circuiting here helps us to
- // avoid an eval call (in setAttribute) which can cause CSP
- // to go haywire. See: https://developer.mozilla.org/en/Security/CSP
- if ( div.attachEvent ) {
- for ( i in {
- submit: 1,
- change: 1,
- focusin: 1
- }) {
- eventName = "on" + i;
- isSupported = ( eventName in div );
- if ( !isSupported ) {
- div.setAttribute( eventName, "return;" );
- isSupported = ( typeof div[ eventName ] === "function" );
- }
- support[ i + "Bubbles" ] = isSupported;
- }
- }
-
- fragment.removeChild( div );
-
- // Null elements to avoid leaks in IE
- fragment = select = opt = div = input = null;
-
- // Run tests that need a body at doc ready
- jQuery(function() {
- var container, outer, inner, table, td, offsetSupport,
- marginDiv, conMarginTop, style, html, positionTopLeftWidthHeight,
- paddingMarginBorderVisibility, paddingMarginBorder,
- body = document.getElementsByTagName("body")[0];
-
- if ( !body ) {
- // Return for frameset docs that don't have a body
- return;
- }
-
- conMarginTop = 1;
- paddingMarginBorder = "padding:0;margin:0;border:";
- positionTopLeftWidthHeight = "position:absolute;top:0;left:0;width:1px;height:1px;";
- paddingMarginBorderVisibility = paddingMarginBorder + "0;visibility:hidden;";
- style = "style='" + positionTopLeftWidthHeight + paddingMarginBorder + "5px solid #000;";
- html = "
" +
- "
" +
- "
";
-
- container = document.createElement("div");
- container.style.cssText = paddingMarginBorderVisibility + "width:0;height:0;position:static;top:0;margin-top:" + conMarginTop + "px";
- body.insertBefore( container, body.firstChild );
-
- // Construct the test element
- div = document.createElement("div");
- container.appendChild( div );
-
- // Check if table cells still have offsetWidth/Height when they are set
- // to display:none and there are still other visible table cells in a
- // table row; if so, offsetWidth/Height are not reliable for use when
- // determining if an element has been hidden directly using
- // display:none (it is still safe to use offsets if a parent element is
- // hidden; don safety goggles and see bug #4512 for more information).
- // (only IE 8 fails this test)
- div.innerHTML = "
t
";
- tds = div.getElementsByTagName( "td" );
- isSupported = ( tds[ 0 ].offsetHeight === 0 );
-
- tds[ 0 ].style.display = "";
- tds[ 1 ].style.display = "none";
-
- // Check if empty table cells still have offsetWidth/Height
- // (IE <= 8 fail this test)
- support.reliableHiddenOffsets = isSupported && ( tds[ 0 ].offsetHeight === 0 );
-
- // Check if div with explicit width and no margin-right incorrectly
- // gets computed margin-right based on width of container. For more
- // info see bug #3333
- // Fails in WebKit before Feb 2011 nightlies
- // WebKit Bug 13343 - getComputedStyle returns wrong value for margin-right
- if ( window.getComputedStyle ) {
- div.innerHTML = "";
- marginDiv = document.createElement( "div" );
- marginDiv.style.width = "0";
- marginDiv.style.marginRight = "0";
- div.style.width = "2px";
- div.appendChild( marginDiv );
- support.reliableMarginRight =
- ( parseInt( ( window.getComputedStyle( marginDiv, null ) || { marginRight: 0 } ).marginRight, 10 ) || 0 ) === 0;
- }
-
- if ( typeof div.style.zoom !== "undefined" ) {
- // Check if natively block-level elements act like inline-block
- // elements when setting their display to 'inline' and giving
- // them layout
- // (IE < 8 does this)
- div.innerHTML = "";
- div.style.width = div.style.padding = "1px";
- div.style.border = 0;
- div.style.overflow = "hidden";
- div.style.display = "inline";
- div.style.zoom = 1;
- support.inlineBlockNeedsLayout = ( div.offsetWidth === 3 );
-
- // Check if elements with layout shrink-wrap their children
- // (IE 6 does this)
- div.style.display = "block";
- div.style.overflow = "visible";
- div.innerHTML = "";
- support.shrinkWrapBlocks = ( div.offsetWidth !== 3 );
- }
-
- div.style.cssText = positionTopLeftWidthHeight + paddingMarginBorderVisibility;
- div.innerHTML = html;
-
- outer = div.firstChild;
- inner = outer.firstChild;
- td = outer.nextSibling.firstChild.firstChild;
-
- offsetSupport = {
- doesNotAddBorder: ( inner.offsetTop !== 5 ),
- doesAddBorderForTableAndCells: ( td.offsetTop === 5 )
- };
-
- inner.style.position = "fixed";
- inner.style.top = "20px";
-
- // safari subtracts parent border width here which is 5px
- offsetSupport.fixedPosition = ( inner.offsetTop === 20 || inner.offsetTop === 15 );
- inner.style.position = inner.style.top = "";
-
- outer.style.overflow = "hidden";
- outer.style.position = "relative";
-
- offsetSupport.subtractsBorderForOverflowNotVisible = ( inner.offsetTop === -5 );
- offsetSupport.doesNotIncludeMarginInBodyOffset = ( body.offsetTop !== conMarginTop );
-
- if ( window.getComputedStyle ) {
- div.style.marginTop = "1%";
- support.pixelMargin = ( window.getComputedStyle( div, null ) || { marginTop: 0 } ).marginTop !== "1%";
- }
-
- if ( typeof container.style.zoom !== "undefined" ) {
- container.style.zoom = 1;
- }
-
- body.removeChild( container );
- marginDiv = div = container = null;
-
- jQuery.extend( support, offsetSupport );
- });
-
- return support;
-})();
-
-
-
-
-var rbrace = /^(?:\{.*\}|\[.*\])$/,
- rmultiDash = /([A-Z])/g;
-
-jQuery.extend({
- cache: {},
-
- // Please use with caution
- uuid: 0,
-
- // Unique for each copy of jQuery on the page
- // Non-digits removed to match rinlinejQuery
- expando: "jQuery" + ( jQuery.fn.jquery + Math.random() ).replace( /\D/g, "" ),
-
- // The following elements throw uncatchable exceptions if you
- // attempt to add expando properties to them.
- noData: {
- "embed": true,
- // Ban all objects except for Flash (which handle expandos)
- "object": "clsid:D27CDB6E-AE6D-11cf-96B8-444553540000",
- "applet": true
- },
-
- hasData: function( elem ) {
- elem = elem.nodeType ? jQuery.cache[ elem[jQuery.expando] ] : elem[ jQuery.expando ];
- return !!elem && !isEmptyDataObject( elem );
- },
-
- data: function( elem, name, data, pvt /* Internal Use Only */ ) {
- if ( !jQuery.acceptData( elem ) ) {
- return;
- }
-
- var privateCache, thisCache, ret,
- internalKey = jQuery.expando,
- getByName = typeof name === "string",
-
- // We have to handle DOM nodes and JS objects differently because IE6-7
- // can't GC object references properly across the DOM-JS boundary
- isNode = elem.nodeType,
-
- // Only DOM nodes need the global jQuery cache; JS object data is
- // attached directly to the object so GC can occur automatically
- cache = isNode ? jQuery.cache : elem,
-
- // Only defining an ID for JS objects if its cache already exists allows
- // the code to shortcut on the same path as a DOM node with no cache
- id = isNode ? elem[ internalKey ] : elem[ internalKey ] && internalKey,
- isEvents = name === "events";
-
- // Avoid doing any more work than we need to when trying to get data on an
- // object that has no data at all
- if ( (!id || !cache[id] || (!isEvents && !pvt && !cache[id].data)) && getByName && data === undefined ) {
- return;
- }
-
- if ( !id ) {
- // Only DOM nodes need a new unique ID for each element since their data
- // ends up in the global cache
- if ( isNode ) {
- elem[ internalKey ] = id = ++jQuery.uuid;
- } else {
- id = internalKey;
- }
- }
-
- if ( !cache[ id ] ) {
- cache[ id ] = {};
-
- // Avoids exposing jQuery metadata on plain JS objects when the object
- // is serialized using JSON.stringify
- if ( !isNode ) {
- cache[ id ].toJSON = jQuery.noop;
- }
- }
-
- // An object can be passed to jQuery.data instead of a key/value pair; this gets
- // shallow copied over onto the existing cache
- if ( typeof name === "object" || typeof name === "function" ) {
- if ( pvt ) {
- cache[ id ] = jQuery.extend( cache[ id ], name );
- } else {
- cache[ id ].data = jQuery.extend( cache[ id ].data, name );
- }
- }
-
- privateCache = thisCache = cache[ id ];
-
- // jQuery data() is stored in a separate object inside the object's internal data
- // cache in order to avoid key collisions between internal data and user-defined
- // data.
- if ( !pvt ) {
- if ( !thisCache.data ) {
- thisCache.data = {};
- }
-
- thisCache = thisCache.data;
- }
-
- if ( data !== undefined ) {
- thisCache[ jQuery.camelCase( name ) ] = data;
- }
-
- // Users should not attempt to inspect the internal events object using jQuery.data,
- // it is undocumented and subject to change. But does anyone listen? No.
- if ( isEvents && !thisCache[ name ] ) {
- return privateCache.events;
- }
-
- // Check for both converted-to-camel and non-converted data property names
- // If a data property was specified
- if ( getByName ) {
-
- // First Try to find as-is property data
- ret = thisCache[ name ];
-
- // Test for null|undefined property data
- if ( ret == null ) {
-
- // Try to find the camelCased property
- ret = thisCache[ jQuery.camelCase( name ) ];
- }
- } else {
- ret = thisCache;
- }
-
- return ret;
- },
-
- removeData: function( elem, name, pvt /* Internal Use Only */ ) {
- if ( !jQuery.acceptData( elem ) ) {
- return;
- }
-
- var thisCache, i, l,
-
- // Reference to internal data cache key
- internalKey = jQuery.expando,
-
- isNode = elem.nodeType,
-
- // See jQuery.data for more information
- cache = isNode ? jQuery.cache : elem,
-
- // See jQuery.data for more information
- id = isNode ? elem[ internalKey ] : internalKey;
-
- // If there is already no cache entry for this object, there is no
- // purpose in continuing
- if ( !cache[ id ] ) {
- return;
- }
-
- if ( name ) {
-
- thisCache = pvt ? cache[ id ] : cache[ id ].data;
-
- if ( thisCache ) {
-
- // Support array or space separated string names for data keys
- if ( !jQuery.isArray( name ) ) {
-
- // try the string as a key before any manipulation
- if ( name in thisCache ) {
- name = [ name ];
- } else {
-
- // split the camel cased version by spaces unless a key with the spaces exists
- name = jQuery.camelCase( name );
- if ( name in thisCache ) {
- name = [ name ];
- } else {
- name = name.split( " " );
- }
- }
- }
-
- for ( i = 0, l = name.length; i < l; i++ ) {
- delete thisCache[ name[i] ];
- }
-
- // If there is no data left in the cache, we want to continue
- // and let the cache object itself get destroyed
- if ( !( pvt ? isEmptyDataObject : jQuery.isEmptyObject )( thisCache ) ) {
- return;
- }
- }
- }
-
- // See jQuery.data for more information
- if ( !pvt ) {
- delete cache[ id ].data;
-
- // Don't destroy the parent cache unless the internal data object
- // had been the only thing left in it
- if ( !isEmptyDataObject(cache[ id ]) ) {
- return;
- }
- }
-
- // Browsers that fail expando deletion also refuse to delete expandos on
- // the window, but it will allow it on all other JS objects; other browsers
- // don't care
- // Ensure that `cache` is not a window object #10080
- if ( jQuery.support.deleteExpando || !cache.setInterval ) {
- delete cache[ id ];
- } else {
- cache[ id ] = null;
- }
-
- // We destroyed the cache and need to eliminate the expando on the node to avoid
- // false lookups in the cache for entries that no longer exist
- if ( isNode ) {
- // IE does not allow us to delete expando properties from nodes,
- // nor does it have a removeAttribute function on Document nodes;
- // we must handle all of these cases
- if ( jQuery.support.deleteExpando ) {
- delete elem[ internalKey ];
- } else if ( elem.removeAttribute ) {
- elem.removeAttribute( internalKey );
- } else {
- elem[ internalKey ] = null;
- }
- }
- },
-
- // For internal use only.
- _data: function( elem, name, data ) {
- return jQuery.data( elem, name, data, true );
- },
-
- // A method for determining if a DOM node can handle the data expando
- acceptData: function( elem ) {
- if ( elem.nodeName ) {
- var match = jQuery.noData[ elem.nodeName.toLowerCase() ];
-
- if ( match ) {
- return !(match === true || elem.getAttribute("classid") !== match);
- }
- }
-
- return true;
- }
-});
-
-jQuery.fn.extend({
- data: function( key, value ) {
- var parts, part, attr, name, l,
- elem = this[0],
- i = 0,
- data = null;
-
- // Gets all values
- if ( key === undefined ) {
- if ( this.length ) {
- data = jQuery.data( elem );
-
- if ( elem.nodeType === 1 && !jQuery._data( elem, "parsedAttrs" ) ) {
- attr = elem.attributes;
- for ( l = attr.length; i < l; i++ ) {
- name = attr[i].name;
-
- if ( name.indexOf( "data-" ) === 0 ) {
- name = jQuery.camelCase( name.substring(5) );
-
- dataAttr( elem, name, data[ name ] );
- }
- }
- jQuery._data( elem, "parsedAttrs", true );
- }
- }
-
- return data;
- }
-
- // Sets multiple values
- if ( typeof key === "object" ) {
- return this.each(function() {
- jQuery.data( this, key );
- });
- }
-
- parts = key.split( ".", 2 );
- parts[1] = parts[1] ? "." + parts[1] : "";
- part = parts[1] + "!";
-
- return jQuery.access( this, function( value ) {
-
- if ( value === undefined ) {
- data = this.triggerHandler( "getData" + part, [ parts[0] ] );
-
- // Try to fetch any internally stored data first
- if ( data === undefined && elem ) {
- data = jQuery.data( elem, key );
- data = dataAttr( elem, key, data );
- }
-
- return data === undefined && parts[1] ?
- this.data( parts[0] ) :
- data;
- }
-
- parts[1] = value;
- this.each(function() {
- var self = jQuery( this );
-
- self.triggerHandler( "setData" + part, parts );
- jQuery.data( this, key, value );
- self.triggerHandler( "changeData" + part, parts );
- });
- }, null, value, arguments.length > 1, null, false );
- },
-
- removeData: function( key ) {
- return this.each(function() {
- jQuery.removeData( this, key );
- });
- }
-});
-
-function dataAttr( elem, key, data ) {
- // If nothing was found internally, try to fetch any
- // data from the HTML5 data-* attribute
- if ( data === undefined && elem.nodeType === 1 ) {
-
- var name = "data-" + key.replace( rmultiDash, "-$1" ).toLowerCase();
-
- data = elem.getAttribute( name );
-
- if ( typeof data === "string" ) {
- try {
- data = data === "true" ? true :
- data === "false" ? false :
- data === "null" ? null :
- jQuery.isNumeric( data ) ? +data :
- rbrace.test( data ) ? jQuery.parseJSON( data ) :
- data;
- } catch( e ) {}
-
- // Make sure we set the data so it isn't changed later
- jQuery.data( elem, key, data );
-
- } else {
- data = undefined;
- }
- }
-
- return data;
-}
-
-// checks a cache object for emptiness
-function isEmptyDataObject( obj ) {
- for ( var name in obj ) {
-
- // if the public data object is empty, the private is still empty
- if ( name === "data" && jQuery.isEmptyObject( obj[name] ) ) {
- continue;
- }
- if ( name !== "toJSON" ) {
- return false;
- }
- }
-
- return true;
-}
-
-
-
-
-function handleQueueMarkDefer( elem, type, src ) {
- var deferDataKey = type + "defer",
- queueDataKey = type + "queue",
- markDataKey = type + "mark",
- defer = jQuery._data( elem, deferDataKey );
- if ( defer &&
- ( src === "queue" || !jQuery._data(elem, queueDataKey) ) &&
- ( src === "mark" || !jQuery._data(elem, markDataKey) ) ) {
- // Give room for hard-coded callbacks to fire first
- // and eventually mark/queue something else on the element
- setTimeout( function() {
- if ( !jQuery._data( elem, queueDataKey ) &&
- !jQuery._data( elem, markDataKey ) ) {
- jQuery.removeData( elem, deferDataKey, true );
- defer.fire();
- }
- }, 0 );
- }
-}
-
-jQuery.extend({
-
- _mark: function( elem, type ) {
- if ( elem ) {
- type = ( type || "fx" ) + "mark";
- jQuery._data( elem, type, (jQuery._data( elem, type ) || 0) + 1 );
- }
- },
-
- _unmark: function( force, elem, type ) {
- if ( force !== true ) {
- type = elem;
- elem = force;
- force = false;
- }
- if ( elem ) {
- type = type || "fx";
- var key = type + "mark",
- count = force ? 0 : ( (jQuery._data( elem, key ) || 1) - 1 );
- if ( count ) {
- jQuery._data( elem, key, count );
- } else {
- jQuery.removeData( elem, key, true );
- handleQueueMarkDefer( elem, type, "mark" );
- }
- }
- },
-
- queue: function( elem, type, data ) {
- var q;
- if ( elem ) {
- type = ( type || "fx" ) + "queue";
- q = jQuery._data( elem, type );
-
- // Speed up dequeue by getting out quickly if this is just a lookup
- if ( data ) {
- if ( !q || jQuery.isArray(data) ) {
- q = jQuery._data( elem, type, jQuery.makeArray(data) );
- } else {
- q.push( data );
- }
- }
- return q || [];
- }
- },
-
- dequeue: function( elem, type ) {
- type = type || "fx";
-
- var queue = jQuery.queue( elem, type ),
- fn = queue.shift(),
- hooks = {};
-
- // If the fx queue is dequeued, always remove the progress sentinel
- if ( fn === "inprogress" ) {
- fn = queue.shift();
- }
-
- if ( fn ) {
- // Add a progress sentinel to prevent the fx queue from being
- // automatically dequeued
- if ( type === "fx" ) {
- queue.unshift( "inprogress" );
- }
-
- jQuery._data( elem, type + ".run", hooks );
- fn.call( elem, function() {
- jQuery.dequeue( elem, type );
- }, hooks );
- }
-
- if ( !queue.length ) {
- jQuery.removeData( elem, type + "queue " + type + ".run", true );
- handleQueueMarkDefer( elem, type, "queue" );
- }
- }
-});
-
-jQuery.fn.extend({
- queue: function( type, data ) {
- var setter = 2;
-
- if ( typeof type !== "string" ) {
- data = type;
- type = "fx";
- setter--;
- }
-
- if ( arguments.length < setter ) {
- return jQuery.queue( this[0], type );
- }
-
- return data === undefined ?
- this :
- this.each(function() {
- var queue = jQuery.queue( this, type, data );
-
- if ( type === "fx" && queue[0] !== "inprogress" ) {
- jQuery.dequeue( this, type );
- }
- });
- },
- dequeue: function( type ) {
- return this.each(function() {
- jQuery.dequeue( this, type );
- });
- },
- // Based off of the plugin by Clint Helfers, with permission.
- // http://blindsignals.com/index.php/2009/07/jquery-delay/
- delay: function( time, type ) {
- time = jQuery.fx ? jQuery.fx.speeds[ time ] || time : time;
- type = type || "fx";
-
- return this.queue( type, function( next, hooks ) {
- var timeout = setTimeout( next, time );
- hooks.stop = function() {
- clearTimeout( timeout );
- };
- });
- },
- clearQueue: function( type ) {
- return this.queue( type || "fx", [] );
- },
- // Get a promise resolved when queues of a certain type
- // are emptied (fx is the type by default)
- promise: function( type, object ) {
- if ( typeof type !== "string" ) {
- object = type;
- type = undefined;
- }
- type = type || "fx";
- var defer = jQuery.Deferred(),
- elements = this,
- i = elements.length,
- count = 1,
- deferDataKey = type + "defer",
- queueDataKey = type + "queue",
- markDataKey = type + "mark",
- tmp;
- function resolve() {
- if ( !( --count ) ) {
- defer.resolveWith( elements, [ elements ] );
- }
- }
- while( i-- ) {
- if (( tmp = jQuery.data( elements[ i ], deferDataKey, undefined, true ) ||
- ( jQuery.data( elements[ i ], queueDataKey, undefined, true ) ||
- jQuery.data( elements[ i ], markDataKey, undefined, true ) ) &&
- jQuery.data( elements[ i ], deferDataKey, jQuery.Callbacks( "once memory" ), true ) )) {
- count++;
- tmp.add( resolve );
- }
- }
- resolve();
- return defer.promise( object );
- }
-});
-
-
-
-
-var rclass = /[\n\t\r]/g,
- rspace = /\s+/,
- rreturn = /\r/g,
- rtype = /^(?:button|input)$/i,
- rfocusable = /^(?:button|input|object|select|textarea)$/i,
- rclickable = /^a(?:rea)?$/i,
- rboolean = /^(?:autofocus|autoplay|async|checked|controls|defer|disabled|hidden|loop|multiple|open|readonly|required|scoped|selected)$/i,
- getSetAttribute = jQuery.support.getSetAttribute,
- nodeHook, boolHook, fixSpecified;
-
-jQuery.fn.extend({
- attr: function( name, value ) {
- return jQuery.access( this, jQuery.attr, name, value, arguments.length > 1 );
- },
-
- removeAttr: function( name ) {
- return this.each(function() {
- jQuery.removeAttr( this, name );
- });
- },
-
- prop: function( name, value ) {
- return jQuery.access( this, jQuery.prop, name, value, arguments.length > 1 );
- },
-
- removeProp: function( name ) {
- name = jQuery.propFix[ name ] || name;
- return this.each(function() {
- // try/catch handles cases where IE balks (such as removing a property on window)
- try {
- this[ name ] = undefined;
- delete this[ name ];
- } catch( e ) {}
- });
- },
-
- addClass: function( value ) {
- var classNames, i, l, elem,
- setClass, c, cl;
-
- if ( jQuery.isFunction( value ) ) {
- return this.each(function( j ) {
- jQuery( this ).addClass( value.call(this, j, this.className) );
- });
- }
-
- if ( value && typeof value === "string" ) {
- classNames = value.split( rspace );
-
- for ( i = 0, l = this.length; i < l; i++ ) {
- elem = this[ i ];
-
- if ( elem.nodeType === 1 ) {
- if ( !elem.className && classNames.length === 1 ) {
- elem.className = value;
-
- } else {
- setClass = " " + elem.className + " ";
-
- for ( c = 0, cl = classNames.length; c < cl; c++ ) {
- if ( !~setClass.indexOf( " " + classNames[ c ] + " " ) ) {
- setClass += classNames[ c ] + " ";
- }
- }
- elem.className = jQuery.trim( setClass );
- }
- }
- }
- }
-
- return this;
- },
-
- removeClass: function( value ) {
- var classNames, i, l, elem, className, c, cl;
-
- if ( jQuery.isFunction( value ) ) {
- return this.each(function( j ) {
- jQuery( this ).removeClass( value.call(this, j, this.className) );
- });
- }
-
- if ( (value && typeof value === "string") || value === undefined ) {
- classNames = ( value || "" ).split( rspace );
-
- for ( i = 0, l = this.length; i < l; i++ ) {
- elem = this[ i ];
-
- if ( elem.nodeType === 1 && elem.className ) {
- if ( value ) {
- className = (" " + elem.className + " ").replace( rclass, " " );
- for ( c = 0, cl = classNames.length; c < cl; c++ ) {
- className = className.replace(" " + classNames[ c ] + " ", " ");
- }
- elem.className = jQuery.trim( className );
-
- } else {
- elem.className = "";
- }
- }
- }
- }
-
- return this;
- },
-
- toggleClass: function( value, stateVal ) {
- var type = typeof value,
- isBool = typeof stateVal === "boolean";
-
- if ( jQuery.isFunction( value ) ) {
- return this.each(function( i ) {
- jQuery( this ).toggleClass( value.call(this, i, this.className, stateVal), stateVal );
- });
- }
-
- return this.each(function() {
- if ( type === "string" ) {
- // toggle individual class names
- var className,
- i = 0,
- self = jQuery( this ),
- state = stateVal,
- classNames = value.split( rspace );
-
- while ( (className = classNames[ i++ ]) ) {
- // check each className given, space seperated list
- state = isBool ? state : !self.hasClass( className );
- self[ state ? "addClass" : "removeClass" ]( className );
- }
-
- } else if ( type === "undefined" || type === "boolean" ) {
- if ( this.className ) {
- // store className if set
- jQuery._data( this, "__className__", this.className );
- }
-
- // toggle whole className
- this.className = this.className || value === false ? "" : jQuery._data( this, "__className__" ) || "";
- }
- });
- },
-
- hasClass: function( selector ) {
- var className = " " + selector + " ",
- i = 0,
- l = this.length;
- for ( ; i < l; i++ ) {
- if ( this[i].nodeType === 1 && (" " + this[i].className + " ").replace(rclass, " ").indexOf( className ) > -1 ) {
- return true;
- }
- }
-
- return false;
- },
-
- val: function( value ) {
- var hooks, ret, isFunction,
- elem = this[0];
-
- if ( !arguments.length ) {
- if ( elem ) {
- hooks = jQuery.valHooks[ elem.type ] || jQuery.valHooks[ elem.nodeName.toLowerCase() ];
-
- if ( hooks && "get" in hooks && (ret = hooks.get( elem, "value" )) !== undefined ) {
- return ret;
- }
-
- ret = elem.value;
-
- return typeof ret === "string" ?
- // handle most common string cases
- ret.replace(rreturn, "") :
- // handle cases where value is null/undef or number
- ret == null ? "" : ret;
- }
-
- return;
- }
-
- isFunction = jQuery.isFunction( value );
-
- return this.each(function( i ) {
- var self = jQuery(this), val;
-
- if ( this.nodeType !== 1 ) {
- return;
- }
-
- if ( isFunction ) {
- val = value.call( this, i, self.val() );
- } else {
- val = value;
- }
-
- // Treat null/undefined as ""; convert numbers to string
- if ( val == null ) {
- val = "";
- } else if ( typeof val === "number" ) {
- val += "";
- } else if ( jQuery.isArray( val ) ) {
- val = jQuery.map(val, function ( value ) {
- return value == null ? "" : value + "";
- });
- }
-
- hooks = jQuery.valHooks[ this.type ] || jQuery.valHooks[ this.nodeName.toLowerCase() ];
-
- // If set returns undefined, fall back to normal setting
- if ( !hooks || !("set" in hooks) || hooks.set( this, val, "value" ) === undefined ) {
- this.value = val;
- }
- });
- }
-});
-
-jQuery.extend({
- valHooks: {
- option: {
- get: function( elem ) {
- // attributes.value is undefined in Blackberry 4.7 but
- // uses .value. See #6932
- var val = elem.attributes.value;
- return !val || val.specified ? elem.value : elem.text;
- }
- },
- select: {
- get: function( elem ) {
- var value, i, max, option,
- index = elem.selectedIndex,
- values = [],
- options = elem.options,
- one = elem.type === "select-one";
-
- // Nothing was selected
- if ( index < 0 ) {
- return null;
- }
-
- // Loop through all the selected options
- i = one ? index : 0;
- max = one ? index + 1 : options.length;
- for ( ; i < max; i++ ) {
- option = options[ i ];
-
- // Don't return options that are disabled or in a disabled optgroup
- if ( option.selected && (jQuery.support.optDisabled ? !option.disabled : option.getAttribute("disabled") === null) &&
- (!option.parentNode.disabled || !jQuery.nodeName( option.parentNode, "optgroup" )) ) {
-
- // Get the specific value for the option
- value = jQuery( option ).val();
-
- // We don't need an array for one selects
- if ( one ) {
- return value;
- }
-
- // Multi-Selects return an array
- values.push( value );
- }
- }
-
- // Fixes Bug #2551 -- select.val() broken in IE after form.reset()
- if ( one && !values.length && options.length ) {
- return jQuery( options[ index ] ).val();
- }
-
- return values;
- },
-
- set: function( elem, value ) {
- var values = jQuery.makeArray( value );
-
- jQuery(elem).find("option").each(function() {
- this.selected = jQuery.inArray( jQuery(this).val(), values ) >= 0;
- });
-
- if ( !values.length ) {
- elem.selectedIndex = -1;
- }
- return values;
- }
- }
- },
-
- attrFn: {
- val: true,
- css: true,
- html: true,
- text: true,
- data: true,
- width: true,
- height: true,
- offset: true
- },
-
- attr: function( elem, name, value, pass ) {
- var ret, hooks, notxml,
- nType = elem.nodeType;
-
- // don't get/set attributes on text, comment and attribute nodes
- if ( !elem || nType === 3 || nType === 8 || nType === 2 ) {
- return;
- }
-
- if ( pass && name in jQuery.attrFn ) {
- return jQuery( elem )[ name ]( value );
- }
-
- // Fallback to prop when attributes are not supported
- if ( typeof elem.getAttribute === "undefined" ) {
- return jQuery.prop( elem, name, value );
- }
-
- notxml = nType !== 1 || !jQuery.isXMLDoc( elem );
-
- // All attributes are lowercase
- // Grab necessary hook if one is defined
- if ( notxml ) {
- name = name.toLowerCase();
- hooks = jQuery.attrHooks[ name ] || ( rboolean.test( name ) ? boolHook : nodeHook );
- }
-
- if ( value !== undefined ) {
-
- if ( value === null ) {
- jQuery.removeAttr( elem, name );
- return;
-
- } else if ( hooks && "set" in hooks && notxml && (ret = hooks.set( elem, value, name )) !== undefined ) {
- return ret;
-
- } else {
- elem.setAttribute( name, "" + value );
- return value;
- }
-
- } else if ( hooks && "get" in hooks && notxml && (ret = hooks.get( elem, name )) !== null ) {
- return ret;
-
- } else {
-
- ret = elem.getAttribute( name );
-
- // Non-existent attributes return null, we normalize to undefined
- return ret === null ?
- undefined :
- ret;
- }
- },
-
- removeAttr: function( elem, value ) {
- var propName, attrNames, name, l, isBool,
- i = 0;
-
- if ( value && elem.nodeType === 1 ) {
- attrNames = value.toLowerCase().split( rspace );
- l = attrNames.length;
-
- for ( ; i < l; i++ ) {
- name = attrNames[ i ];
-
- if ( name ) {
- propName = jQuery.propFix[ name ] || name;
- isBool = rboolean.test( name );
-
- // See #9699 for explanation of this approach (setting first, then removal)
- // Do not do this for boolean attributes (see #10870)
- if ( !isBool ) {
- jQuery.attr( elem, name, "" );
- }
- elem.removeAttribute( getSetAttribute ? name : propName );
-
- // Set corresponding property to false for boolean attributes
- if ( isBool && propName in elem ) {
- elem[ propName ] = false;
- }
- }
- }
- }
- },
-
- attrHooks: {
- type: {
- set: function( elem, value ) {
- // We can't allow the type property to be changed (since it causes problems in IE)
- if ( rtype.test( elem.nodeName ) && elem.parentNode ) {
- jQuery.error( "type property can't be changed" );
- } else if ( !jQuery.support.radioValue && value === "radio" && jQuery.nodeName(elem, "input") ) {
- // Setting the type on a radio button after the value resets the value in IE6-9
- // Reset value to it's default in case type is set after value
- // This is for element creation
- var val = elem.value;
- elem.setAttribute( "type", value );
- if ( val ) {
- elem.value = val;
- }
- return value;
- }
- }
- },
- // Use the value property for back compat
- // Use the nodeHook for button elements in IE6/7 (#1954)
- value: {
- get: function( elem, name ) {
- if ( nodeHook && jQuery.nodeName( elem, "button" ) ) {
- return nodeHook.get( elem, name );
- }
- return name in elem ?
- elem.value :
- null;
- },
- set: function( elem, value, name ) {
- if ( nodeHook && jQuery.nodeName( elem, "button" ) ) {
- return nodeHook.set( elem, value, name );
- }
- // Does not return so that setAttribute is also used
- elem.value = value;
- }
- }
- },
-
- propFix: {
- tabindex: "tabIndex",
- readonly: "readOnly",
- "for": "htmlFor",
- "class": "className",
- maxlength: "maxLength",
- cellspacing: "cellSpacing",
- cellpadding: "cellPadding",
- rowspan: "rowSpan",
- colspan: "colSpan",
- usemap: "useMap",
- frameborder: "frameBorder",
- contenteditable: "contentEditable"
- },
-
- prop: function( elem, name, value ) {
- var ret, hooks, notxml,
- nType = elem.nodeType;
-
- // don't get/set properties on text, comment and attribute nodes
- if ( !elem || nType === 3 || nType === 8 || nType === 2 ) {
- return;
- }
-
- notxml = nType !== 1 || !jQuery.isXMLDoc( elem );
-
- if ( notxml ) {
- // Fix name and attach hooks
- name = jQuery.propFix[ name ] || name;
- hooks = jQuery.propHooks[ name ];
- }
-
- if ( value !== undefined ) {
- if ( hooks && "set" in hooks && (ret = hooks.set( elem, value, name )) !== undefined ) {
- return ret;
-
- } else {
- return ( elem[ name ] = value );
- }
-
- } else {
- if ( hooks && "get" in hooks && (ret = hooks.get( elem, name )) !== null ) {
- return ret;
-
- } else {
- return elem[ name ];
- }
- }
- },
-
- propHooks: {
- tabIndex: {
- get: function( elem ) {
- // elem.tabIndex doesn't always return the correct value when it hasn't been explicitly set
- // http://fluidproject.org/blog/2008/01/09/getting-setting-and-removing-tabindex-values-with-javascript/
- var attributeNode = elem.getAttributeNode("tabindex");
-
- return attributeNode && attributeNode.specified ?
- parseInt( attributeNode.value, 10 ) :
- rfocusable.test( elem.nodeName ) || rclickable.test( elem.nodeName ) && elem.href ?
- 0 :
- undefined;
- }
- }
- }
-});
-
-// Add the tabIndex propHook to attrHooks for back-compat (different case is intentional)
-jQuery.attrHooks.tabindex = jQuery.propHooks.tabIndex;
-
-// Hook for boolean attributes
-boolHook = {
- get: function( elem, name ) {
- // Align boolean attributes with corresponding properties
- // Fall back to attribute presence where some booleans are not supported
- var attrNode,
- property = jQuery.prop( elem, name );
- return property === true || typeof property !== "boolean" && ( attrNode = elem.getAttributeNode(name) ) && attrNode.nodeValue !== false ?
- name.toLowerCase() :
- undefined;
- },
- set: function( elem, value, name ) {
- var propName;
- if ( value === false ) {
- // Remove boolean attributes when set to false
- jQuery.removeAttr( elem, name );
- } else {
- // value is true since we know at this point it's type boolean and not false
- // Set boolean attributes to the same name and set the DOM property
- propName = jQuery.propFix[ name ] || name;
- if ( propName in elem ) {
- // Only set the IDL specifically if it already exists on the element
- elem[ propName ] = true;
- }
-
- elem.setAttribute( name, name.toLowerCase() );
- }
- return name;
- }
-};
-
-// IE6/7 do not support getting/setting some attributes with get/setAttribute
-if ( !getSetAttribute ) {
-
- fixSpecified = {
- name: true,
- id: true,
- coords: true
- };
-
- // Use this for any attribute in IE6/7
- // This fixes almost every IE6/7 issue
- nodeHook = jQuery.valHooks.button = {
- get: function( elem, name ) {
- var ret;
- ret = elem.getAttributeNode( name );
- return ret && ( fixSpecified[ name ] ? ret.nodeValue !== "" : ret.specified ) ?
- ret.nodeValue :
- undefined;
- },
- set: function( elem, value, name ) {
- // Set the existing or create a new attribute node
- var ret = elem.getAttributeNode( name );
- if ( !ret ) {
- ret = document.createAttribute( name );
- elem.setAttributeNode( ret );
- }
- return ( ret.nodeValue = value + "" );
- }
- };
-
- // Apply the nodeHook to tabindex
- jQuery.attrHooks.tabindex.set = nodeHook.set;
-
- // Set width and height to auto instead of 0 on empty string( Bug #8150 )
- // This is for removals
- jQuery.each([ "width", "height" ], function( i, name ) {
- jQuery.attrHooks[ name ] = jQuery.extend( jQuery.attrHooks[ name ], {
- set: function( elem, value ) {
- if ( value === "" ) {
- elem.setAttribute( name, "auto" );
- return value;
- }
- }
- });
- });
-
- // Set contenteditable to false on removals(#10429)
- // Setting to empty string throws an error as an invalid value
- jQuery.attrHooks.contenteditable = {
- get: nodeHook.get,
- set: function( elem, value, name ) {
- if ( value === "" ) {
- value = "false";
- }
- nodeHook.set( elem, value, name );
- }
- };
-}
-
-
-// Some attributes require a special call on IE
-if ( !jQuery.support.hrefNormalized ) {
- jQuery.each([ "href", "src", "width", "height" ], function( i, name ) {
- jQuery.attrHooks[ name ] = jQuery.extend( jQuery.attrHooks[ name ], {
- get: function( elem ) {
- var ret = elem.getAttribute( name, 2 );
- return ret === null ? undefined : ret;
- }
- });
- });
-}
-
-if ( !jQuery.support.style ) {
- jQuery.attrHooks.style = {
- get: function( elem ) {
- // Return undefined in the case of empty string
- // Normalize to lowercase since IE uppercases css property names
- return elem.style.cssText.toLowerCase() || undefined;
- },
- set: function( elem, value ) {
- return ( elem.style.cssText = "" + value );
- }
- };
-}
-
-// Safari mis-reports the default selected property of an option
-// Accessing the parent's selectedIndex property fixes it
-if ( !jQuery.support.optSelected ) {
- jQuery.propHooks.selected = jQuery.extend( jQuery.propHooks.selected, {
- get: function( elem ) {
- var parent = elem.parentNode;
-
- if ( parent ) {
- parent.selectedIndex;
-
- // Make sure that it also works with optgroups, see #5701
- if ( parent.parentNode ) {
- parent.parentNode.selectedIndex;
- }
- }
- return null;
- }
- });
-}
-
-// IE6/7 call enctype encoding
-if ( !jQuery.support.enctype ) {
- jQuery.propFix.enctype = "encoding";
-}
-
-// Radios and checkboxes getter/setter
-if ( !jQuery.support.checkOn ) {
- jQuery.each([ "radio", "checkbox" ], function() {
- jQuery.valHooks[ this ] = {
- get: function( elem ) {
- // Handle the case where in Webkit "" is returned instead of "on" if a value isn't specified
- return elem.getAttribute("value") === null ? "on" : elem.value;
- }
- };
- });
-}
-jQuery.each([ "radio", "checkbox" ], function() {
- jQuery.valHooks[ this ] = jQuery.extend( jQuery.valHooks[ this ], {
- set: function( elem, value ) {
- if ( jQuery.isArray( value ) ) {
- return ( elem.checked = jQuery.inArray( jQuery(elem).val(), value ) >= 0 );
- }
- }
- });
-});
-
-
-
-
-var rformElems = /^(?:textarea|input|select)$/i,
- rtypenamespace = /^([^\.]*)?(?:\.(.+))?$/,
- rhoverHack = /(?:^|\s)hover(\.\S+)?\b/,
- rkeyEvent = /^key/,
- rmouseEvent = /^(?:mouse|contextmenu)|click/,
- rfocusMorph = /^(?:focusinfocus|focusoutblur)$/,
- rquickIs = /^(\w*)(?:#([\w\-]+))?(?:\.([\w\-]+))?$/,
- quickParse = function( selector ) {
- var quick = rquickIs.exec( selector );
- if ( quick ) {
- // 0 1 2 3
- // [ _, tag, id, class ]
- quick[1] = ( quick[1] || "" ).toLowerCase();
- quick[3] = quick[3] && new RegExp( "(?:^|\\s)" + quick[3] + "(?:\\s|$)" );
- }
- return quick;
- },
- quickIs = function( elem, m ) {
- var attrs = elem.attributes || {};
- return (
- (!m[1] || elem.nodeName.toLowerCase() === m[1]) &&
- (!m[2] || (attrs.id || {}).value === m[2]) &&
- (!m[3] || m[3].test( (attrs[ "class" ] || {}).value ))
- );
- },
- hoverHack = function( events ) {
- return jQuery.event.special.hover ? events : events.replace( rhoverHack, "mouseenter$1 mouseleave$1" );
- };
-
-/*
- * Helper functions for managing events -- not part of the public interface.
- * Props to Dean Edwards' addEvent library for many of the ideas.
- */
-jQuery.event = {
-
- add: function( elem, types, handler, data, selector ) {
-
- var elemData, eventHandle, events,
- t, tns, type, namespaces, handleObj,
- handleObjIn, quick, handlers, special;
-
- // Don't attach events to noData or text/comment nodes (allow plain objects tho)
- if ( elem.nodeType === 3 || elem.nodeType === 8 || !types || !handler || !(elemData = jQuery._data( elem )) ) {
- return;
- }
-
- // Caller can pass in an object of custom data in lieu of the handler
- if ( handler.handler ) {
- handleObjIn = handler;
- handler = handleObjIn.handler;
- selector = handleObjIn.selector;
- }
-
- // Make sure that the handler has a unique ID, used to find/remove it later
- if ( !handler.guid ) {
- handler.guid = jQuery.guid++;
- }
-
- // Init the element's event structure and main handler, if this is the first
- events = elemData.events;
- if ( !events ) {
- elemData.events = events = {};
- }
- eventHandle = elemData.handle;
- if ( !eventHandle ) {
- elemData.handle = eventHandle = function( e ) {
- // Discard the second event of a jQuery.event.trigger() and
- // when an event is called after a page has unloaded
- return typeof jQuery !== "undefined" && (!e || jQuery.event.triggered !== e.type) ?
- jQuery.event.dispatch.apply( eventHandle.elem, arguments ) :
- undefined;
- };
- // Add elem as a property of the handle fn to prevent a memory leak with IE non-native events
- eventHandle.elem = elem;
- }
-
- // Handle multiple events separated by a space
- // jQuery(...).bind("mouseover mouseout", fn);
- types = jQuery.trim( hoverHack(types) ).split( " " );
- for ( t = 0; t < types.length; t++ ) {
-
- tns = rtypenamespace.exec( types[t] ) || [];
- type = tns[1];
- namespaces = ( tns[2] || "" ).split( "." ).sort();
-
- // If event changes its type, use the special event handlers for the changed type
- special = jQuery.event.special[ type ] || {};
-
- // If selector defined, determine special event api type, otherwise given type
- type = ( selector ? special.delegateType : special.bindType ) || type;
-
- // Update special based on newly reset type
- special = jQuery.event.special[ type ] || {};
-
- // handleObj is passed to all event handlers
- handleObj = jQuery.extend({
- type: type,
- origType: tns[1],
- data: data,
- handler: handler,
- guid: handler.guid,
- selector: selector,
- quick: selector && quickParse( selector ),
- namespace: namespaces.join(".")
- }, handleObjIn );
-
- // Init the event handler queue if we're the first
- handlers = events[ type ];
- if ( !handlers ) {
- handlers = events[ type ] = [];
- handlers.delegateCount = 0;
-
- // Only use addEventListener/attachEvent if the special events handler returns false
- if ( !special.setup || special.setup.call( elem, data, namespaces, eventHandle ) === false ) {
- // Bind the global event handler to the element
- if ( elem.addEventListener ) {
- elem.addEventListener( type, eventHandle, false );
-
- } else if ( elem.attachEvent ) {
- elem.attachEvent( "on" + type, eventHandle );
- }
- }
- }
-
- if ( special.add ) {
- special.add.call( elem, handleObj );
-
- if ( !handleObj.handler.guid ) {
- handleObj.handler.guid = handler.guid;
- }
- }
-
- // Add to the element's handler list, delegates in front
- if ( selector ) {
- handlers.splice( handlers.delegateCount++, 0, handleObj );
- } else {
- handlers.push( handleObj );
- }
-
- // Keep track of which events have ever been used, for event optimization
- jQuery.event.global[ type ] = true;
- }
-
- // Nullify elem to prevent memory leaks in IE
- elem = null;
- },
-
- global: {},
-
- // Detach an event or set of events from an element
- remove: function( elem, types, handler, selector, mappedTypes ) {
-
- var elemData = jQuery.hasData( elem ) && jQuery._data( elem ),
- t, tns, type, origType, namespaces, origCount,
- j, events, special, handle, eventType, handleObj;
-
- if ( !elemData || !(events = elemData.events) ) {
- return;
- }
-
- // Once for each type.namespace in types; type may be omitted
- types = jQuery.trim( hoverHack( types || "" ) ).split(" ");
- for ( t = 0; t < types.length; t++ ) {
- tns = rtypenamespace.exec( types[t] ) || [];
- type = origType = tns[1];
- namespaces = tns[2];
-
- // Unbind all events (on this namespace, if provided) for the element
- if ( !type ) {
- for ( type in events ) {
- jQuery.event.remove( elem, type + types[ t ], handler, selector, true );
- }
- continue;
- }
-
- special = jQuery.event.special[ type ] || {};
- type = ( selector? special.delegateType : special.bindType ) || type;
- eventType = events[ type ] || [];
- origCount = eventType.length;
- namespaces = namespaces ? new RegExp("(^|\\.)" + namespaces.split(".").sort().join("\\.(?:.*\\.)?") + "(\\.|$)") : null;
-
- // Remove matching events
- for ( j = 0; j < eventType.length; j++ ) {
- handleObj = eventType[ j ];
-
- if ( ( mappedTypes || origType === handleObj.origType ) &&
- ( !handler || handler.guid === handleObj.guid ) &&
- ( !namespaces || namespaces.test( handleObj.namespace ) ) &&
- ( !selector || selector === handleObj.selector || selector === "**" && handleObj.selector ) ) {
- eventType.splice( j--, 1 );
-
- if ( handleObj.selector ) {
- eventType.delegateCount--;
- }
- if ( special.remove ) {
- special.remove.call( elem, handleObj );
- }
- }
- }
-
- // Remove generic event handler if we removed something and no more handlers exist
- // (avoids potential for endless recursion during removal of special event handlers)
- if ( eventType.length === 0 && origCount !== eventType.length ) {
- if ( !special.teardown || special.teardown.call( elem, namespaces ) === false ) {
- jQuery.removeEvent( elem, type, elemData.handle );
- }
-
- delete events[ type ];
- }
- }
-
- // Remove the expando if it's no longer used
- if ( jQuery.isEmptyObject( events ) ) {
- handle = elemData.handle;
- if ( handle ) {
- handle.elem = null;
- }
-
- // removeData also checks for emptiness and clears the expando if empty
- // so use it instead of delete
- jQuery.removeData( elem, [ "events", "handle" ], true );
- }
- },
-
- // Events that are safe to short-circuit if no handlers are attached.
- // Native DOM events should not be added, they may have inline handlers.
- customEvent: {
- "getData": true,
- "setData": true,
- "changeData": true
- },
-
- trigger: function( event, data, elem, onlyHandlers ) {
- // Don't do events on text and comment nodes
- if ( elem && (elem.nodeType === 3 || elem.nodeType === 8) ) {
- return;
- }
-
- // Event object or event type
- var type = event.type || event,
- namespaces = [],
- cache, exclusive, i, cur, old, ontype, special, handle, eventPath, bubbleType;
-
- // focus/blur morphs to focusin/out; ensure we're not firing them right now
- if ( rfocusMorph.test( type + jQuery.event.triggered ) ) {
- return;
- }
-
- if ( type.indexOf( "!" ) >= 0 ) {
- // Exclusive events trigger only for the exact event (no namespaces)
- type = type.slice(0, -1);
- exclusive = true;
- }
-
- if ( type.indexOf( "." ) >= 0 ) {
- // Namespaced trigger; create a regexp to match event type in handle()
- namespaces = type.split(".");
- type = namespaces.shift();
- namespaces.sort();
- }
-
- if ( (!elem || jQuery.event.customEvent[ type ]) && !jQuery.event.global[ type ] ) {
- // No jQuery handlers for this event type, and it can't have inline handlers
- return;
- }
-
- // Caller can pass in an Event, Object, or just an event type string
- event = typeof event === "object" ?
- // jQuery.Event object
- event[ jQuery.expando ] ? event :
- // Object literal
- new jQuery.Event( type, event ) :
- // Just the event type (string)
- new jQuery.Event( type );
-
- event.type = type;
- event.isTrigger = true;
- event.exclusive = exclusive;
- event.namespace = namespaces.join( "." );
- event.namespace_re = event.namespace? new RegExp("(^|\\.)" + namespaces.join("\\.(?:.*\\.)?") + "(\\.|$)") : null;
- ontype = type.indexOf( ":" ) < 0 ? "on" + type : "";
-
- // Handle a global trigger
- if ( !elem ) {
-
- // TODO: Stop taunting the data cache; remove global events and always attach to document
- cache = jQuery.cache;
- for ( i in cache ) {
- if ( cache[ i ].events && cache[ i ].events[ type ] ) {
- jQuery.event.trigger( event, data, cache[ i ].handle.elem, true );
- }
- }
- return;
- }
-
- // Clean up the event in case it is being reused
- event.result = undefined;
- if ( !event.target ) {
- event.target = elem;
- }
-
- // Clone any incoming data and prepend the event, creating the handler arg list
- data = data != null ? jQuery.makeArray( data ) : [];
- data.unshift( event );
-
- // Allow special events to draw outside the lines
- special = jQuery.event.special[ type ] || {};
- if ( special.trigger && special.trigger.apply( elem, data ) === false ) {
- return;
- }
-
- // Determine event propagation path in advance, per W3C events spec (#9951)
- // Bubble up to document, then to window; watch for a global ownerDocument var (#9724)
- eventPath = [[ elem, special.bindType || type ]];
- if ( !onlyHandlers && !special.noBubble && !jQuery.isWindow( elem ) ) {
-
- bubbleType = special.delegateType || type;
- cur = rfocusMorph.test( bubbleType + type ) ? elem : elem.parentNode;
- old = null;
- for ( ; cur; cur = cur.parentNode ) {
- eventPath.push([ cur, bubbleType ]);
- old = cur;
- }
-
- // Only add window if we got to document (e.g., not plain obj or detached DOM)
- if ( old && old === elem.ownerDocument ) {
- eventPath.push([ old.defaultView || old.parentWindow || window, bubbleType ]);
- }
- }
-
- // Fire handlers on the event path
- for ( i = 0; i < eventPath.length && !event.isPropagationStopped(); i++ ) {
-
- cur = eventPath[i][0];
- event.type = eventPath[i][1];
-
- handle = ( jQuery._data( cur, "events" ) || {} )[ event.type ] && jQuery._data( cur, "handle" );
- if ( handle ) {
- handle.apply( cur, data );
- }
- // Note that this is a bare JS function and not a jQuery handler
- handle = ontype && cur[ ontype ];
- if ( handle && jQuery.acceptData( cur ) && handle.apply( cur, data ) === false ) {
- event.preventDefault();
- }
- }
- event.type = type;
-
- // If nobody prevented the default action, do it now
- if ( !onlyHandlers && !event.isDefaultPrevented() ) {
-
- if ( (!special._default || special._default.apply( elem.ownerDocument, data ) === false) &&
- !(type === "click" && jQuery.nodeName( elem, "a" )) && jQuery.acceptData( elem ) ) {
-
- // Call a native DOM method on the target with the same name name as the event.
- // Can't use an .isFunction() check here because IE6/7 fails that test.
- // Don't do default actions on window, that's where global variables be (#6170)
- // IE<9 dies on focus/blur to hidden element (#1486)
- if ( ontype && elem[ type ] && ((type !== "focus" && type !== "blur") || event.target.offsetWidth !== 0) && !jQuery.isWindow( elem ) ) {
-
- // Don't re-trigger an onFOO event when we call its FOO() method
- old = elem[ ontype ];
-
- if ( old ) {
- elem[ ontype ] = null;
- }
-
- // Prevent re-triggering of the same event, since we already bubbled it above
- jQuery.event.triggered = type;
- elem[ type ]();
- jQuery.event.triggered = undefined;
-
- if ( old ) {
- elem[ ontype ] = old;
- }
- }
- }
- }
-
- return event.result;
- },
-
- dispatch: function( event ) {
-
- // Make a writable jQuery.Event from the native event object
- event = jQuery.event.fix( event || window.event );
-
- var handlers = ( (jQuery._data( this, "events" ) || {} )[ event.type ] || []),
- delegateCount = handlers.delegateCount,
- args = [].slice.call( arguments, 0 ),
- run_all = !event.exclusive && !event.namespace,
- special = jQuery.event.special[ event.type ] || {},
- handlerQueue = [],
- i, j, cur, jqcur, ret, selMatch, matched, matches, handleObj, sel, related;
-
- // Use the fix-ed jQuery.Event rather than the (read-only) native event
- args[0] = event;
- event.delegateTarget = this;
-
- // Call the preDispatch hook for the mapped type, and let it bail if desired
- if ( special.preDispatch && special.preDispatch.call( this, event ) === false ) {
- return;
- }
-
- // Determine handlers that should run if there are delegated events
- // Avoid non-left-click bubbling in Firefox (#3861)
- if ( delegateCount && !(event.button && event.type === "click") ) {
-
- // Pregenerate a single jQuery object for reuse with .is()
- jqcur = jQuery(this);
- jqcur.context = this.ownerDocument || this;
-
- for ( cur = event.target; cur != this; cur = cur.parentNode || this ) {
-
- // Don't process events on disabled elements (#6911, #8165)
- if ( cur.disabled !== true ) {
- selMatch = {};
- matches = [];
- jqcur[0] = cur;
- for ( i = 0; i < delegateCount; i++ ) {
- handleObj = handlers[ i ];
- sel = handleObj.selector;
-
- if ( selMatch[ sel ] === undefined ) {
- selMatch[ sel ] = (
- handleObj.quick ? quickIs( cur, handleObj.quick ) : jqcur.is( sel )
- );
- }
- if ( selMatch[ sel ] ) {
- matches.push( handleObj );
- }
- }
- if ( matches.length ) {
- handlerQueue.push({ elem: cur, matches: matches });
- }
- }
- }
- }
-
- // Add the remaining (directly-bound) handlers
- if ( handlers.length > delegateCount ) {
- handlerQueue.push({ elem: this, matches: handlers.slice( delegateCount ) });
- }
-
- // Run delegates first; they may want to stop propagation beneath us
- for ( i = 0; i < handlerQueue.length && !event.isPropagationStopped(); i++ ) {
- matched = handlerQueue[ i ];
- event.currentTarget = matched.elem;
-
- for ( j = 0; j < matched.matches.length && !event.isImmediatePropagationStopped(); j++ ) {
- handleObj = matched.matches[ j ];
-
- // Triggered event must either 1) be non-exclusive and have no namespace, or
- // 2) have namespace(s) a subset or equal to those in the bound event (both can have no namespace).
- if ( run_all || (!event.namespace && !handleObj.namespace) || event.namespace_re && event.namespace_re.test( handleObj.namespace ) ) {
-
- event.data = handleObj.data;
- event.handleObj = handleObj;
-
- ret = ( (jQuery.event.special[ handleObj.origType ] || {}).handle || handleObj.handler )
- .apply( matched.elem, args );
-
- if ( ret !== undefined ) {
- event.result = ret;
- if ( ret === false ) {
- event.preventDefault();
- event.stopPropagation();
- }
- }
- }
- }
- }
-
- // Call the postDispatch hook for the mapped type
- if ( special.postDispatch ) {
- special.postDispatch.call( this, event );
- }
-
- return event.result;
- },
-
- // Includes some event props shared by KeyEvent and MouseEvent
- // *** attrChange attrName relatedNode srcElement are not normalized, non-W3C, deprecated, will be removed in 1.8 ***
- props: "attrChange attrName relatedNode srcElement altKey bubbles cancelable ctrlKey currentTarget eventPhase metaKey relatedTarget shiftKey target timeStamp view which".split(" "),
-
- fixHooks: {},
-
- keyHooks: {
- props: "char charCode key keyCode".split(" "),
- filter: function( event, original ) {
-
- // Add which for key events
- if ( event.which == null ) {
- event.which = original.charCode != null ? original.charCode : original.keyCode;
- }
-
- return event;
- }
- },
-
- mouseHooks: {
- props: "button buttons clientX clientY fromElement offsetX offsetY pageX pageY screenX screenY toElement".split(" "),
- filter: function( event, original ) {
- var eventDoc, doc, body,
- button = original.button,
- fromElement = original.fromElement;
-
- // Calculate pageX/Y if missing and clientX/Y available
- if ( event.pageX == null && original.clientX != null ) {
- eventDoc = event.target.ownerDocument || document;
- doc = eventDoc.documentElement;
- body = eventDoc.body;
-
- event.pageX = original.clientX + ( doc && doc.scrollLeft || body && body.scrollLeft || 0 ) - ( doc && doc.clientLeft || body && body.clientLeft || 0 );
- event.pageY = original.clientY + ( doc && doc.scrollTop || body && body.scrollTop || 0 ) - ( doc && doc.clientTop || body && body.clientTop || 0 );
- }
-
- // Add relatedTarget, if necessary
- if ( !event.relatedTarget && fromElement ) {
- event.relatedTarget = fromElement === event.target ? original.toElement : fromElement;
- }
-
- // Add which for click: 1 === left; 2 === middle; 3 === right
- // Note: button is not normalized, so don't use it
- if ( !event.which && button !== undefined ) {
- event.which = ( button & 1 ? 1 : ( button & 2 ? 3 : ( button & 4 ? 2 : 0 ) ) );
- }
-
- return event;
- }
- },
-
- fix: function( event ) {
- if ( event[ jQuery.expando ] ) {
- return event;
- }
-
- // Create a writable copy of the event object and normalize some properties
- var i, prop,
- originalEvent = event,
- fixHook = jQuery.event.fixHooks[ event.type ] || {},
- copy = fixHook.props ? this.props.concat( fixHook.props ) : this.props;
-
- event = jQuery.Event( originalEvent );
-
- for ( i = copy.length; i; ) {
- prop = copy[ --i ];
- event[ prop ] = originalEvent[ prop ];
- }
-
- // Fix target property, if necessary (#1925, IE 6/7/8 & Safari2)
- if ( !event.target ) {
- event.target = originalEvent.srcElement || document;
- }
-
- // Target should not be a text node (#504, Safari)
- if ( event.target.nodeType === 3 ) {
- event.target = event.target.parentNode;
- }
-
- // For mouse/key events; add metaKey if it's not there (#3368, IE6/7/8)
- if ( event.metaKey === undefined ) {
- event.metaKey = event.ctrlKey;
- }
-
- return fixHook.filter? fixHook.filter( event, originalEvent ) : event;
- },
-
- special: {
- ready: {
- // Make sure the ready event is setup
- setup: jQuery.bindReady
- },
-
- load: {
- // Prevent triggered image.load events from bubbling to window.load
- noBubble: true
- },
-
- focus: {
- delegateType: "focusin"
- },
- blur: {
- delegateType: "focusout"
- },
-
- beforeunload: {
- setup: function( data, namespaces, eventHandle ) {
- // We only want to do this special case on windows
- if ( jQuery.isWindow( this ) ) {
- this.onbeforeunload = eventHandle;
- }
- },
-
- teardown: function( namespaces, eventHandle ) {
- if ( this.onbeforeunload === eventHandle ) {
- this.onbeforeunload = null;
- }
- }
- }
- },
-
- simulate: function( type, elem, event, bubble ) {
- // Piggyback on a donor event to simulate a different one.
- // Fake originalEvent to avoid donor's stopPropagation, but if the
- // simulated event prevents default then we do the same on the donor.
- var e = jQuery.extend(
- new jQuery.Event(),
- event,
- { type: type,
- isSimulated: true,
- originalEvent: {}
- }
- );
- if ( bubble ) {
- jQuery.event.trigger( e, null, elem );
- } else {
- jQuery.event.dispatch.call( elem, e );
- }
- if ( e.isDefaultPrevented() ) {
- event.preventDefault();
- }
- }
-};
-
-// Some plugins are using, but it's undocumented/deprecated and will be removed.
-// The 1.7 special event interface should provide all the hooks needed now.
-jQuery.event.handle = jQuery.event.dispatch;
-
-jQuery.removeEvent = document.removeEventListener ?
- function( elem, type, handle ) {
- if ( elem.removeEventListener ) {
- elem.removeEventListener( type, handle, false );
- }
- } :
- function( elem, type, handle ) {
- if ( elem.detachEvent ) {
- elem.detachEvent( "on" + type, handle );
- }
- };
-
-jQuery.Event = function( src, props ) {
- // Allow instantiation without the 'new' keyword
- if ( !(this instanceof jQuery.Event) ) {
- return new jQuery.Event( src, props );
- }
-
- // Event object
- if ( src && src.type ) {
- this.originalEvent = src;
- this.type = src.type;
-
- // Events bubbling up the document may have been marked as prevented
- // by a handler lower down the tree; reflect the correct value.
- this.isDefaultPrevented = ( src.defaultPrevented || src.returnValue === false ||
- src.getPreventDefault && src.getPreventDefault() ) ? returnTrue : returnFalse;
-
- // Event type
- } else {
- this.type = src;
- }
-
- // Put explicitly provided properties onto the event object
- if ( props ) {
- jQuery.extend( this, props );
- }
-
- // Create a timestamp if incoming event doesn't have one
- this.timeStamp = src && src.timeStamp || jQuery.now();
-
- // Mark it as fixed
- this[ jQuery.expando ] = true;
-};
-
-function returnFalse() {
- return false;
-}
-function returnTrue() {
- return true;
-}
-
-// jQuery.Event is based on DOM3 Events as specified by the ECMAScript Language Binding
-// http://www.w3.org/TR/2003/WD-DOM-Level-3-Events-20030331/ecma-script-binding.html
-jQuery.Event.prototype = {
- preventDefault: function() {
- this.isDefaultPrevented = returnTrue;
-
- var e = this.originalEvent;
- if ( !e ) {
- return;
- }
-
- // if preventDefault exists run it on the original event
- if ( e.preventDefault ) {
- e.preventDefault();
-
- // otherwise set the returnValue property of the original event to false (IE)
- } else {
- e.returnValue = false;
- }
- },
- stopPropagation: function() {
- this.isPropagationStopped = returnTrue;
-
- var e = this.originalEvent;
- if ( !e ) {
- return;
- }
- // if stopPropagation exists run it on the original event
- if ( e.stopPropagation ) {
- e.stopPropagation();
- }
- // otherwise set the cancelBubble property of the original event to true (IE)
- e.cancelBubble = true;
- },
- stopImmediatePropagation: function() {
- this.isImmediatePropagationStopped = returnTrue;
- this.stopPropagation();
- },
- isDefaultPrevented: returnFalse,
- isPropagationStopped: returnFalse,
- isImmediatePropagationStopped: returnFalse
-};
-
-// Create mouseenter/leave events using mouseover/out and event-time checks
-jQuery.each({
- mouseenter: "mouseover",
- mouseleave: "mouseout"
-}, function( orig, fix ) {
- jQuery.event.special[ orig ] = {
- delegateType: fix,
- bindType: fix,
-
- handle: function( event ) {
- var target = this,
- related = event.relatedTarget,
- handleObj = event.handleObj,
- selector = handleObj.selector,
- ret;
-
- // For mousenter/leave call the handler if related is outside the target.
- // NB: No relatedTarget if the mouse left/entered the browser window
- if ( !related || (related !== target && !jQuery.contains( target, related )) ) {
- event.type = handleObj.origType;
- ret = handleObj.handler.apply( this, arguments );
- event.type = fix;
- }
- return ret;
- }
- };
-});
-
-// IE submit delegation
-if ( !jQuery.support.submitBubbles ) {
-
- jQuery.event.special.submit = {
- setup: function() {
- // Only need this for delegated form submit events
- if ( jQuery.nodeName( this, "form" ) ) {
- return false;
- }
-
- // Lazy-add a submit handler when a descendant form may potentially be submitted
- jQuery.event.add( this, "click._submit keypress._submit", function( e ) {
- // Node name check avoids a VML-related crash in IE (#9807)
- var elem = e.target,
- form = jQuery.nodeName( elem, "input" ) || jQuery.nodeName( elem, "button" ) ? elem.form : undefined;
- if ( form && !form._submit_attached ) {
- jQuery.event.add( form, "submit._submit", function( event ) {
- event._submit_bubble = true;
- });
- form._submit_attached = true;
- }
- });
- // return undefined since we don't need an event listener
- },
-
- postDispatch: function( event ) {
- // If form was submitted by the user, bubble the event up the tree
- if ( event._submit_bubble ) {
- delete event._submit_bubble;
- if ( this.parentNode && !event.isTrigger ) {
- jQuery.event.simulate( "submit", this.parentNode, event, true );
- }
- }
- },
-
- teardown: function() {
- // Only need this for delegated form submit events
- if ( jQuery.nodeName( this, "form" ) ) {
- return false;
- }
-
- // Remove delegated handlers; cleanData eventually reaps submit handlers attached above
- jQuery.event.remove( this, "._submit" );
- }
- };
-}
-
-// IE change delegation and checkbox/radio fix
-if ( !jQuery.support.changeBubbles ) {
-
- jQuery.event.special.change = {
-
- setup: function() {
-
- if ( rformElems.test( this.nodeName ) ) {
- // IE doesn't fire change on a check/radio until blur; trigger it on click
- // after a propertychange. Eat the blur-change in special.change.handle.
- // This still fires onchange a second time for check/radio after blur.
- if ( this.type === "checkbox" || this.type === "radio" ) {
- jQuery.event.add( this, "propertychange._change", function( event ) {
- if ( event.originalEvent.propertyName === "checked" ) {
- this._just_changed = true;
- }
- });
- jQuery.event.add( this, "click._change", function( event ) {
- if ( this._just_changed && !event.isTrigger ) {
- this._just_changed = false;
- jQuery.event.simulate( "change", this, event, true );
- }
- });
- }
- return false;
- }
- // Delegated event; lazy-add a change handler on descendant inputs
- jQuery.event.add( this, "beforeactivate._change", function( e ) {
- var elem = e.target;
-
- if ( rformElems.test( elem.nodeName ) && !elem._change_attached ) {
- jQuery.event.add( elem, "change._change", function( event ) {
- if ( this.parentNode && !event.isSimulated && !event.isTrigger ) {
- jQuery.event.simulate( "change", this.parentNode, event, true );
- }
- });
- elem._change_attached = true;
- }
- });
- },
-
- handle: function( event ) {
- var elem = event.target;
-
- // Swallow native change events from checkbox/radio, we already triggered them above
- if ( this !== elem || event.isSimulated || event.isTrigger || (elem.type !== "radio" && elem.type !== "checkbox") ) {
- return event.handleObj.handler.apply( this, arguments );
- }
- },
-
- teardown: function() {
- jQuery.event.remove( this, "._change" );
-
- return rformElems.test( this.nodeName );
- }
- };
-}
-
-// Create "bubbling" focus and blur events
-if ( !jQuery.support.focusinBubbles ) {
- jQuery.each({ focus: "focusin", blur: "focusout" }, function( orig, fix ) {
-
- // Attach a single capturing handler while someone wants focusin/focusout
- var attaches = 0,
- handler = function( event ) {
- jQuery.event.simulate( fix, event.target, jQuery.event.fix( event ), true );
- };
-
- jQuery.event.special[ fix ] = {
- setup: function() {
- if ( attaches++ === 0 ) {
- document.addEventListener( orig, handler, true );
- }
- },
- teardown: function() {
- if ( --attaches === 0 ) {
- document.removeEventListener( orig, handler, true );
- }
- }
- };
- });
-}
-
-jQuery.fn.extend({
-
- on: function( types, selector, data, fn, /*INTERNAL*/ one ) {
- var origFn, type;
-
- // Types can be a map of types/handlers
- if ( typeof types === "object" ) {
- // ( types-Object, selector, data )
- if ( typeof selector !== "string" ) { // && selector != null
- // ( types-Object, data )
- data = data || selector;
- selector = undefined;
- }
- for ( type in types ) {
- this.on( type, selector, data, types[ type ], one );
- }
- return this;
- }
-
- if ( data == null && fn == null ) {
- // ( types, fn )
- fn = selector;
- data = selector = undefined;
- } else if ( fn == null ) {
- if ( typeof selector === "string" ) {
- // ( types, selector, fn )
- fn = data;
- data = undefined;
- } else {
- // ( types, data, fn )
- fn = data;
- data = selector;
- selector = undefined;
- }
- }
- if ( fn === false ) {
- fn = returnFalse;
- } else if ( !fn ) {
- return this;
- }
-
- if ( one === 1 ) {
- origFn = fn;
- fn = function( event ) {
- // Can use an empty set, since event contains the info
- jQuery().off( event );
- return origFn.apply( this, arguments );
- };
- // Use same guid so caller can remove using origFn
- fn.guid = origFn.guid || ( origFn.guid = jQuery.guid++ );
- }
- return this.each( function() {
- jQuery.event.add( this, types, fn, data, selector );
- });
- },
- one: function( types, selector, data, fn ) {
- return this.on( types, selector, data, fn, 1 );
- },
- off: function( types, selector, fn ) {
- if ( types && types.preventDefault && types.handleObj ) {
- // ( event ) dispatched jQuery.Event
- var handleObj = types.handleObj;
- jQuery( types.delegateTarget ).off(
- handleObj.namespace ? handleObj.origType + "." + handleObj.namespace : handleObj.origType,
- handleObj.selector,
- handleObj.handler
- );
- return this;
- }
- if ( typeof types === "object" ) {
- // ( types-object [, selector] )
- for ( var type in types ) {
- this.off( type, selector, types[ type ] );
- }
- return this;
- }
- if ( selector === false || typeof selector === "function" ) {
- // ( types [, fn] )
- fn = selector;
- selector = undefined;
- }
- if ( fn === false ) {
- fn = returnFalse;
- }
- return this.each(function() {
- jQuery.event.remove( this, types, fn, selector );
- });
- },
-
- bind: function( types, data, fn ) {
- return this.on( types, null, data, fn );
- },
- unbind: function( types, fn ) {
- return this.off( types, null, fn );
- },
-
- live: function( types, data, fn ) {
- jQuery( this.context ).on( types, this.selector, data, fn );
- return this;
- },
- die: function( types, fn ) {
- jQuery( this.context ).off( types, this.selector || "**", fn );
- return this;
- },
-
- delegate: function( selector, types, data, fn ) {
- return this.on( types, selector, data, fn );
- },
- undelegate: function( selector, types, fn ) {
- // ( namespace ) or ( selector, types [, fn] )
- return arguments.length == 1? this.off( selector, "**" ) : this.off( types, selector, fn );
- },
-
- trigger: function( type, data ) {
- return this.each(function() {
- jQuery.event.trigger( type, data, this );
- });
- },
- triggerHandler: function( type, data ) {
- if ( this[0] ) {
- return jQuery.event.trigger( type, data, this[0], true );
- }
- },
-
- toggle: function( fn ) {
- // Save reference to arguments for access in closure
- var args = arguments,
- guid = fn.guid || jQuery.guid++,
- i = 0,
- toggler = function( event ) {
- // Figure out which function to execute
- var lastToggle = ( jQuery._data( this, "lastToggle" + fn.guid ) || 0 ) % i;
- jQuery._data( this, "lastToggle" + fn.guid, lastToggle + 1 );
-
- // Make sure that clicks stop
- event.preventDefault();
-
- // and execute the function
- return args[ lastToggle ].apply( this, arguments ) || false;
- };
-
- // link all the functions, so any of them can unbind this click handler
- toggler.guid = guid;
- while ( i < args.length ) {
- args[ i++ ].guid = guid;
- }
-
- return this.click( toggler );
- },
-
- hover: function( fnOver, fnOut ) {
- return this.mouseenter( fnOver ).mouseleave( fnOut || fnOver );
- }
-});
-
-jQuery.each( ("blur focus focusin focusout load resize scroll unload click dblclick " +
- "mousedown mouseup mousemove mouseover mouseout mouseenter mouseleave " +
- "change select submit keydown keypress keyup error contextmenu").split(" "), function( i, name ) {
-
- // Handle event binding
- jQuery.fn[ name ] = function( data, fn ) {
- if ( fn == null ) {
- fn = data;
- data = null;
- }
-
- return arguments.length > 0 ?
- this.on( name, null, data, fn ) :
- this.trigger( name );
- };
-
- if ( jQuery.attrFn ) {
- jQuery.attrFn[ name ] = true;
- }
-
- if ( rkeyEvent.test( name ) ) {
- jQuery.event.fixHooks[ name ] = jQuery.event.keyHooks;
- }
-
- if ( rmouseEvent.test( name ) ) {
- jQuery.event.fixHooks[ name ] = jQuery.event.mouseHooks;
- }
-});
-
-
-
-/*!
- * Sizzle CSS Selector Engine
- * Copyright 2011, The Dojo Foundation
- * Released under the MIT, BSD, and GPL Licenses.
- * More information: http://sizzlejs.com/
- */
-(function(){
-
-var chunker = /((?:\((?:\([^()]+\)|[^()]+)+\)|\[(?:\[[^\[\]]*\]|['"][^'"]*['"]|[^\[\]'"]+)+\]|\\.|[^ >+~,(\[\\]+)+|[>+~])(\s*,\s*)?((?:.|\r|\n)*)/g,
- expando = "sizcache" + (Math.random() + '').replace('.', ''),
- done = 0,
- toString = Object.prototype.toString,
- hasDuplicate = false,
- baseHasDuplicate = true,
- rBackslash = /\\/g,
- rReturn = /\r\n/g,
- rNonWord = /\W/;
-
-// Here we check if the JavaScript engine is using some sort of
-// optimization where it does not always call our comparision
-// function. If that is the case, discard the hasDuplicate value.
-// Thus far that includes Google Chrome.
-[0, 0].sort(function() {
- baseHasDuplicate = false;
- return 0;
-});
-
-var Sizzle = function( selector, context, results, seed ) {
- results = results || [];
- context = context || document;
-
- var origContext = context;
-
- if ( context.nodeType !== 1 && context.nodeType !== 9 ) {
- return [];
- }
-
- if ( !selector || typeof selector !== "string" ) {
- return results;
- }
-
- var m, set, checkSet, extra, ret, cur, pop, i,
- prune = true,
- contextXML = Sizzle.isXML( context ),
- parts = [],
- soFar = selector;
-
- // Reset the position of the chunker regexp (start from head)
- do {
- chunker.exec( "" );
- m = chunker.exec( soFar );
-
- if ( m ) {
- soFar = m[3];
-
- parts.push( m[1] );
-
- if ( m[2] ) {
- extra = m[3];
- break;
- }
- }
- } while ( m );
-
- if ( parts.length > 1 && origPOS.exec( selector ) ) {
-
- if ( parts.length === 2 && Expr.relative[ parts[0] ] ) {
- set = posProcess( parts[0] + parts[1], context, seed );
-
- } else {
- set = Expr.relative[ parts[0] ] ?
- [ context ] :
- Sizzle( parts.shift(), context );
-
- while ( parts.length ) {
- selector = parts.shift();
-
- if ( Expr.relative[ selector ] ) {
- selector += parts.shift();
- }
-
- set = posProcess( selector, set, seed );
- }
- }
-
- } else {
- // Take a shortcut and set the context if the root selector is an ID
- // (but not if it'll be faster if the inner selector is an ID)
- if ( !seed && parts.length > 1 && context.nodeType === 9 && !contextXML &&
- Expr.match.ID.test(parts[0]) && !Expr.match.ID.test(parts[parts.length - 1]) ) {
-
- ret = Sizzle.find( parts.shift(), context, contextXML );
- context = ret.expr ?
- Sizzle.filter( ret.expr, ret.set )[0] :
- ret.set[0];
- }
-
- if ( context ) {
- ret = seed ?
- { expr: parts.pop(), set: makeArray(seed) } :
- Sizzle.find( parts.pop(), parts.length === 1 && (parts[0] === "~" || parts[0] === "+") && context.parentNode ? context.parentNode : context, contextXML );
-
- set = ret.expr ?
- Sizzle.filter( ret.expr, ret.set ) :
- ret.set;
-
- if ( parts.length > 0 ) {
- checkSet = makeArray( set );
-
- } else {
- prune = false;
- }
-
- while ( parts.length ) {
- cur = parts.pop();
- pop = cur;
-
- if ( !Expr.relative[ cur ] ) {
- cur = "";
- } else {
- pop = parts.pop();
- }
-
- if ( pop == null ) {
- pop = context;
- }
-
- Expr.relative[ cur ]( checkSet, pop, contextXML );
- }
-
- } else {
- checkSet = parts = [];
- }
- }
-
- if ( !checkSet ) {
- checkSet = set;
- }
-
- if ( !checkSet ) {
- Sizzle.error( cur || selector );
- }
-
- if ( toString.call(checkSet) === "[object Array]" ) {
- if ( !prune ) {
- results.push.apply( results, checkSet );
-
- } else if ( context && context.nodeType === 1 ) {
- for ( i = 0; checkSet[i] != null; i++ ) {
- if ( checkSet[i] && (checkSet[i] === true || checkSet[i].nodeType === 1 && Sizzle.contains(context, checkSet[i])) ) {
- results.push( set[i] );
- }
- }
-
- } else {
- for ( i = 0; checkSet[i] != null; i++ ) {
- if ( checkSet[i] && checkSet[i].nodeType === 1 ) {
- results.push( set[i] );
- }
- }
- }
-
- } else {
- makeArray( checkSet, results );
- }
-
- if ( extra ) {
- Sizzle( extra, origContext, results, seed );
- Sizzle.uniqueSort( results );
- }
-
- return results;
-};
-
-Sizzle.uniqueSort = function( results ) {
- if ( sortOrder ) {
- hasDuplicate = baseHasDuplicate;
- results.sort( sortOrder );
-
- if ( hasDuplicate ) {
- for ( var i = 1; i < results.length; i++ ) {
- if ( results[i] === results[ i - 1 ] ) {
- results.splice( i--, 1 );
- }
- }
- }
- }
-
- return results;
-};
-
-Sizzle.matches = function( expr, set ) {
- return Sizzle( expr, null, null, set );
-};
-
-Sizzle.matchesSelector = function( node, expr ) {
- return Sizzle( expr, null, null, [node] ).length > 0;
-};
-
-Sizzle.find = function( expr, context, isXML ) {
- var set, i, len, match, type, left;
-
- if ( !expr ) {
- return [];
- }
-
- for ( i = 0, len = Expr.order.length; i < len; i++ ) {
- type = Expr.order[i];
-
- if ( (match = Expr.leftMatch[ type ].exec( expr )) ) {
- left = match[1];
- match.splice( 1, 1 );
-
- if ( left.substr( left.length - 1 ) !== "\\" ) {
- match[1] = (match[1] || "").replace( rBackslash, "" );
- set = Expr.find[ type ]( match, context, isXML );
-
- if ( set != null ) {
- expr = expr.replace( Expr.match[ type ], "" );
- break;
- }
- }
- }
- }
-
- if ( !set ) {
- set = typeof context.getElementsByTagName !== "undefined" ?
- context.getElementsByTagName( "*" ) :
- [];
- }
-
- return { set: set, expr: expr };
-};
-
-Sizzle.filter = function( expr, set, inplace, not ) {
- var match, anyFound,
- type, found, item, filter, left,
- i, pass,
- old = expr,
- result = [],
- curLoop = set,
- isXMLFilter = set && set[0] && Sizzle.isXML( set[0] );
-
- while ( expr && set.length ) {
- for ( type in Expr.filter ) {
- if ( (match = Expr.leftMatch[ type ].exec( expr )) != null && match[2] ) {
- filter = Expr.filter[ type ];
- left = match[1];
-
- anyFound = false;
-
- match.splice(1,1);
-
- if ( left.substr( left.length - 1 ) === "\\" ) {
- continue;
- }
-
- if ( curLoop === result ) {
- result = [];
- }
-
- if ( Expr.preFilter[ type ] ) {
- match = Expr.preFilter[ type ]( match, curLoop, inplace, result, not, isXMLFilter );
-
- if ( !match ) {
- anyFound = found = true;
-
- } else if ( match === true ) {
- continue;
- }
- }
-
- if ( match ) {
- for ( i = 0; (item = curLoop[i]) != null; i++ ) {
- if ( item ) {
- found = filter( item, match, i, curLoop );
- pass = not ^ found;
-
- if ( inplace && found != null ) {
- if ( pass ) {
- anyFound = true;
-
- } else {
- curLoop[i] = false;
- }
-
- } else if ( pass ) {
- result.push( item );
- anyFound = true;
- }
- }
- }
- }
-
- if ( found !== undefined ) {
- if ( !inplace ) {
- curLoop = result;
- }
-
- expr = expr.replace( Expr.match[ type ], "" );
-
- if ( !anyFound ) {
- return [];
- }
-
- break;
- }
- }
- }
-
- // Improper expression
- if ( expr === old ) {
- if ( anyFound == null ) {
- Sizzle.error( expr );
-
- } else {
- break;
- }
- }
-
- old = expr;
- }
-
- return curLoop;
-};
-
-Sizzle.error = function( msg ) {
- throw new Error( "Syntax error, unrecognized expression: " + msg );
-};
-
-/**
- * Utility function for retreiving the text value of an array of DOM nodes
- * @param {Array|Element} elem
- */
-var getText = Sizzle.getText = function( elem ) {
- var i, node,
- nodeType = elem.nodeType,
- ret = "";
-
- if ( nodeType ) {
- if ( nodeType === 1 || nodeType === 9 || nodeType === 11 ) {
- // Use textContent || innerText for elements
- if ( typeof elem.textContent === 'string' ) {
- return elem.textContent;
- } else if ( typeof elem.innerText === 'string' ) {
- // Replace IE's carriage returns
- return elem.innerText.replace( rReturn, '' );
- } else {
- // Traverse it's children
- for ( elem = elem.firstChild; elem; elem = elem.nextSibling) {
- ret += getText( elem );
- }
- }
- } else if ( nodeType === 3 || nodeType === 4 ) {
- return elem.nodeValue;
- }
- } else {
-
- // If no nodeType, this is expected to be an array
- for ( i = 0; (node = elem[i]); i++ ) {
- // Do not traverse comment nodes
- if ( node.nodeType !== 8 ) {
- ret += getText( node );
- }
- }
- }
- return ret;
-};
-
-var Expr = Sizzle.selectors = {
- order: [ "ID", "NAME", "TAG" ],
-
- match: {
- ID: /#((?:[\w\u00c0-\uFFFF\-]|\\.)+)/,
- CLASS: /\.((?:[\w\u00c0-\uFFFF\-]|\\.)+)/,
- NAME: /\[name=['"]*((?:[\w\u00c0-\uFFFF\-]|\\.)+)['"]*\]/,
- ATTR: /\[\s*((?:[\w\u00c0-\uFFFF\-]|\\.)+)\s*(?:(\S?=)\s*(?:(['"])(.*?)\3|(#?(?:[\w\u00c0-\uFFFF\-]|\\.)*)|)|)\s*\]/,
- TAG: /^((?:[\w\u00c0-\uFFFF\*\-]|\\.)+)/,
- CHILD: /:(only|nth|last|first)-child(?:\(\s*(even|odd|(?:[+\-]?\d+|(?:[+\-]?\d*)?n\s*(?:[+\-]\s*\d+)?))\s*\))?/,
- POS: /:(nth|eq|gt|lt|first|last|even|odd)(?:\((\d*)\))?(?=[^\-]|$)/,
- PSEUDO: /:((?:[\w\u00c0-\uFFFF\-]|\\.)+)(?:\((['"]?)((?:\([^\)]+\)|[^\(\)]*)+)\2\))?/
- },
-
- leftMatch: {},
-
- attrMap: {
- "class": "className",
- "for": "htmlFor"
- },
-
- attrHandle: {
- href: function( elem ) {
- return elem.getAttribute( "href" );
- },
- type: function( elem ) {
- return elem.getAttribute( "type" );
- }
- },
-
- relative: {
- "+": function(checkSet, part){
- var isPartStr = typeof part === "string",
- isTag = isPartStr && !rNonWord.test( part ),
- isPartStrNotTag = isPartStr && !isTag;
-
- if ( isTag ) {
- part = part.toLowerCase();
- }
-
- for ( var i = 0, l = checkSet.length, elem; i < l; i++ ) {
- if ( (elem = checkSet[i]) ) {
- while ( (elem = elem.previousSibling) && elem.nodeType !== 1 ) {}
-
- checkSet[i] = isPartStrNotTag || elem && elem.nodeName.toLowerCase() === part ?
- elem || false :
- elem === part;
- }
- }
-
- if ( isPartStrNotTag ) {
- Sizzle.filter( part, checkSet, true );
- }
- },
-
- ">": function( checkSet, part ) {
- var elem,
- isPartStr = typeof part === "string",
- i = 0,
- l = checkSet.length;
-
- if ( isPartStr && !rNonWord.test( part ) ) {
- part = part.toLowerCase();
-
- for ( ; i < l; i++ ) {
- elem = checkSet[i];
-
- if ( elem ) {
- var parent = elem.parentNode;
- checkSet[i] = parent.nodeName.toLowerCase() === part ? parent : false;
- }
- }
-
- } else {
- for ( ; i < l; i++ ) {
- elem = checkSet[i];
-
- if ( elem ) {
- checkSet[i] = isPartStr ?
- elem.parentNode :
- elem.parentNode === part;
- }
- }
-
- if ( isPartStr ) {
- Sizzle.filter( part, checkSet, true );
- }
- }
- },
-
- "": function(checkSet, part, isXML){
- var nodeCheck,
- doneName = done++,
- checkFn = dirCheck;
-
- if ( typeof part === "string" && !rNonWord.test( part ) ) {
- part = part.toLowerCase();
- nodeCheck = part;
- checkFn = dirNodeCheck;
- }
-
- checkFn( "parentNode", part, doneName, checkSet, nodeCheck, isXML );
- },
-
- "~": function( checkSet, part, isXML ) {
- var nodeCheck,
- doneName = done++,
- checkFn = dirCheck;
-
- if ( typeof part === "string" && !rNonWord.test( part ) ) {
- part = part.toLowerCase();
- nodeCheck = part;
- checkFn = dirNodeCheck;
- }
-
- checkFn( "previousSibling", part, doneName, checkSet, nodeCheck, isXML );
- }
- },
-
- find: {
- ID: function( match, context, isXML ) {
- if ( typeof context.getElementById !== "undefined" && !isXML ) {
- var m = context.getElementById(match[1]);
- // Check parentNode to catch when Blackberry 4.6 returns
- // nodes that are no longer in the document #6963
- return m && m.parentNode ? [m] : [];
- }
- },
-
- NAME: function( match, context ) {
- if ( typeof context.getElementsByName !== "undefined" ) {
- var ret = [],
- results = context.getElementsByName( match[1] );
-
- for ( var i = 0, l = results.length; i < l; i++ ) {
- if ( results[i].getAttribute("name") === match[1] ) {
- ret.push( results[i] );
- }
- }
-
- return ret.length === 0 ? null : ret;
- }
- },
-
- TAG: function( match, context ) {
- if ( typeof context.getElementsByTagName !== "undefined" ) {
- return context.getElementsByTagName( match[1] );
- }
- }
- },
- preFilter: {
- CLASS: function( match, curLoop, inplace, result, not, isXML ) {
- match = " " + match[1].replace( rBackslash, "" ) + " ";
-
- if ( isXML ) {
- return match;
- }
-
- for ( var i = 0, elem; (elem = curLoop[i]) != null; i++ ) {
- if ( elem ) {
- if ( not ^ (elem.className && (" " + elem.className + " ").replace(/[\t\n\r]/g, " ").indexOf(match) >= 0) ) {
- if ( !inplace ) {
- result.push( elem );
- }
-
- } else if ( inplace ) {
- curLoop[i] = false;
- }
- }
- }
-
- return false;
- },
-
- ID: function( match ) {
- return match[1].replace( rBackslash, "" );
- },
-
- TAG: function( match, curLoop ) {
- return match[1].replace( rBackslash, "" ).toLowerCase();
- },
-
- CHILD: function( match ) {
- if ( match[1] === "nth" ) {
- if ( !match[2] ) {
- Sizzle.error( match[0] );
- }
-
- match[2] = match[2].replace(/^\+|\s*/g, '');
-
- // parse equations like 'even', 'odd', '5', '2n', '3n+2', '4n-1', '-n+6'
- var test = /(-?)(\d*)(?:n([+\-]?\d*))?/.exec(
- match[2] === "even" && "2n" || match[2] === "odd" && "2n+1" ||
- !/\D/.test( match[2] ) && "0n+" + match[2] || match[2]);
-
- // calculate the numbers (first)n+(last) including if they are negative
- match[2] = (test[1] + (test[2] || 1)) - 0;
- match[3] = test[3] - 0;
- }
- else if ( match[2] ) {
- Sizzle.error( match[0] );
- }
-
- // TODO: Move to normal caching system
- match[0] = done++;
-
- return match;
- },
-
- ATTR: function( match, curLoop, inplace, result, not, isXML ) {
- var name = match[1] = match[1].replace( rBackslash, "" );
-
- if ( !isXML && Expr.attrMap[name] ) {
- match[1] = Expr.attrMap[name];
- }
-
- // Handle if an un-quoted value was used
- match[4] = ( match[4] || match[5] || "" ).replace( rBackslash, "" );
-
- if ( match[2] === "~=" ) {
- match[4] = " " + match[4] + " ";
- }
-
- return match;
- },
-
- PSEUDO: function( match, curLoop, inplace, result, not ) {
- if ( match[1] === "not" ) {
- // If we're dealing with a complex expression, or a simple one
- if ( ( chunker.exec(match[3]) || "" ).length > 1 || /^\w/.test(match[3]) ) {
- match[3] = Sizzle(match[3], null, null, curLoop);
-
- } else {
- var ret = Sizzle.filter(match[3], curLoop, inplace, true ^ not);
-
- if ( !inplace ) {
- result.push.apply( result, ret );
- }
-
- return false;
- }
-
- } else if ( Expr.match.POS.test( match[0] ) || Expr.match.CHILD.test( match[0] ) ) {
- return true;
- }
-
- return match;
- },
-
- POS: function( match ) {
- match.unshift( true );
-
- return match;
- }
- },
-
- filters: {
- enabled: function( elem ) {
- return elem.disabled === false && elem.type !== "hidden";
- },
-
- disabled: function( elem ) {
- return elem.disabled === true;
- },
-
- checked: function( elem ) {
- return elem.checked === true;
- },
-
- selected: function( elem ) {
- // Accessing this property makes selected-by-default
- // options in Safari work properly
- if ( elem.parentNode ) {
- elem.parentNode.selectedIndex;
- }
-
- return elem.selected === true;
- },
-
- parent: function( elem ) {
- return !!elem.firstChild;
- },
-
- empty: function( elem ) {
- return !elem.firstChild;
- },
-
- has: function( elem, i, match ) {
- return !!Sizzle( match[3], elem ).length;
- },
-
- header: function( elem ) {
- return (/h\d/i).test( elem.nodeName );
- },
-
- text: function( elem ) {
- var attr = elem.getAttribute( "type" ), type = elem.type;
- // IE6 and 7 will map elem.type to 'text' for new HTML5 types (search, etc)
- // use getAttribute instead to test this case
- return elem.nodeName.toLowerCase() === "input" && "text" === type && ( attr === type || attr === null );
- },
-
- radio: function( elem ) {
- return elem.nodeName.toLowerCase() === "input" && "radio" === elem.type;
- },
-
- checkbox: function( elem ) {
- return elem.nodeName.toLowerCase() === "input" && "checkbox" === elem.type;
- },
-
- file: function( elem ) {
- return elem.nodeName.toLowerCase() === "input" && "file" === elem.type;
- },
-
- password: function( elem ) {
- return elem.nodeName.toLowerCase() === "input" && "password" === elem.type;
- },
-
- submit: function( elem ) {
- var name = elem.nodeName.toLowerCase();
- return (name === "input" || name === "button") && "submit" === elem.type;
- },
-
- image: function( elem ) {
- return elem.nodeName.toLowerCase() === "input" && "image" === elem.type;
- },
-
- reset: function( elem ) {
- var name = elem.nodeName.toLowerCase();
- return (name === "input" || name === "button") && "reset" === elem.type;
- },
-
- button: function( elem ) {
- var name = elem.nodeName.toLowerCase();
- return name === "input" && "button" === elem.type || name === "button";
- },
-
- input: function( elem ) {
- return (/input|select|textarea|button/i).test( elem.nodeName );
- },
-
- focus: function( elem ) {
- return elem === elem.ownerDocument.activeElement;
- }
- },
- setFilters: {
- first: function( elem, i ) {
- return i === 0;
- },
-
- last: function( elem, i, match, array ) {
- return i === array.length - 1;
- },
-
- even: function( elem, i ) {
- return i % 2 === 0;
- },
-
- odd: function( elem, i ) {
- return i % 2 === 1;
- },
-
- lt: function( elem, i, match ) {
- return i < match[3] - 0;
- },
-
- gt: function( elem, i, match ) {
- return i > match[3] - 0;
- },
-
- nth: function( elem, i, match ) {
- return match[3] - 0 === i;
- },
-
- eq: function( elem, i, match ) {
- return match[3] - 0 === i;
- }
- },
- filter: {
- PSEUDO: function( elem, match, i, array ) {
- var name = match[1],
- filter = Expr.filters[ name ];
-
- if ( filter ) {
- return filter( elem, i, match, array );
-
- } else if ( name === "contains" ) {
- return (elem.textContent || elem.innerText || getText([ elem ]) || "").indexOf(match[3]) >= 0;
-
- } else if ( name === "not" ) {
- var not = match[3];
-
- for ( var j = 0, l = not.length; j < l; j++ ) {
- if ( not[j] === elem ) {
- return false;
- }
- }
-
- return true;
-
- } else {
- Sizzle.error( name );
- }
- },
-
- CHILD: function( elem, match ) {
- var first, last,
- doneName, parent, cache,
- count, diff,
- type = match[1],
- node = elem;
-
- switch ( type ) {
- case "only":
- case "first":
- while ( (node = node.previousSibling) ) {
- if ( node.nodeType === 1 ) {
- return false;
- }
- }
-
- if ( type === "first" ) {
- return true;
- }
-
- node = elem;
-
- /* falls through */
- case "last":
- while ( (node = node.nextSibling) ) {
- if ( node.nodeType === 1 ) {
- return false;
- }
- }
-
- return true;
-
- case "nth":
- first = match[2];
- last = match[3];
-
- if ( first === 1 && last === 0 ) {
- return true;
- }
-
- doneName = match[0];
- parent = elem.parentNode;
-
- if ( parent && (parent[ expando ] !== doneName || !elem.nodeIndex) ) {
- count = 0;
-
- for ( node = parent.firstChild; node; node = node.nextSibling ) {
- if ( node.nodeType === 1 ) {
- node.nodeIndex = ++count;
- }
- }
-
- parent[ expando ] = doneName;
- }
-
- diff = elem.nodeIndex - last;
-
- if ( first === 0 ) {
- return diff === 0;
-
- } else {
- return ( diff % first === 0 && diff / first >= 0 );
- }
- }
- },
-
- ID: function( elem, match ) {
- return elem.nodeType === 1 && elem.getAttribute("id") === match;
- },
-
- TAG: function( elem, match ) {
- return (match === "*" && elem.nodeType === 1) || !!elem.nodeName && elem.nodeName.toLowerCase() === match;
- },
-
- CLASS: function( elem, match ) {
- return (" " + (elem.className || elem.getAttribute("class")) + " ")
- .indexOf( match ) > -1;
- },
-
- ATTR: function( elem, match ) {
- var name = match[1],
- result = Sizzle.attr ?
- Sizzle.attr( elem, name ) :
- Expr.attrHandle[ name ] ?
- Expr.attrHandle[ name ]( elem ) :
- elem[ name ] != null ?
- elem[ name ] :
- elem.getAttribute( name ),
- value = result + "",
- type = match[2],
- check = match[4];
-
- return result == null ?
- type === "!=" :
- !type && Sizzle.attr ?
- result != null :
- type === "=" ?
- value === check :
- type === "*=" ?
- value.indexOf(check) >= 0 :
- type === "~=" ?
- (" " + value + " ").indexOf(check) >= 0 :
- !check ?
- value && result !== false :
- type === "!=" ?
- value !== check :
- type === "^=" ?
- value.indexOf(check) === 0 :
- type === "$=" ?
- value.substr(value.length - check.length) === check :
- type === "|=" ?
- value === check || value.substr(0, check.length + 1) === check + "-" :
- false;
- },
-
- POS: function( elem, match, i, array ) {
- var name = match[2],
- filter = Expr.setFilters[ name ];
-
- if ( filter ) {
- return filter( elem, i, match, array );
- }
- }
- }
-};
-
-var origPOS = Expr.match.POS,
- fescape = function(all, num){
- return "\\" + (num - 0 + 1);
- };
-
-for ( var type in Expr.match ) {
- Expr.match[ type ] = new RegExp( Expr.match[ type ].source + (/(?![^\[]*\])(?![^\(]*\))/.source) );
- Expr.leftMatch[ type ] = new RegExp( /(^(?:.|\r|\n)*?)/.source + Expr.match[ type ].source.replace(/\\(\d+)/g, fescape) );
-}
-// Expose origPOS
-// "global" as in regardless of relation to brackets/parens
-Expr.match.globalPOS = origPOS;
-
-var makeArray = function( array, results ) {
- array = Array.prototype.slice.call( array, 0 );
-
- if ( results ) {
- results.push.apply( results, array );
- return results;
- }
-
- return array;
-};
-
-// Perform a simple check to determine if the browser is capable of
-// converting a NodeList to an array using builtin methods.
-// Also verifies that the returned array holds DOM nodes
-// (which is not the case in the Blackberry browser)
-try {
- Array.prototype.slice.call( document.documentElement.childNodes, 0 )[0].nodeType;
-
-// Provide a fallback method if it does not work
-} catch( e ) {
- makeArray = function( array, results ) {
- var i = 0,
- ret = results || [];
-
- if ( toString.call(array) === "[object Array]" ) {
- Array.prototype.push.apply( ret, array );
-
- } else {
- if ( typeof array.length === "number" ) {
- for ( var l = array.length; i < l; i++ ) {
- ret.push( array[i] );
- }
-
- } else {
- for ( ; array[i]; i++ ) {
- ret.push( array[i] );
- }
- }
- }
-
- return ret;
- };
-}
-
-var sortOrder, siblingCheck;
-
-if ( document.documentElement.compareDocumentPosition ) {
- sortOrder = function( a, b ) {
- if ( a === b ) {
- hasDuplicate = true;
- return 0;
- }
-
- if ( !a.compareDocumentPosition || !b.compareDocumentPosition ) {
- return a.compareDocumentPosition ? -1 : 1;
- }
-
- return a.compareDocumentPosition(b) & 4 ? -1 : 1;
- };
-
-} else {
- sortOrder = function( a, b ) {
- // The nodes are identical, we can exit early
- if ( a === b ) {
- hasDuplicate = true;
- return 0;
-
- // Fallback to using sourceIndex (in IE) if it's available on both nodes
- } else if ( a.sourceIndex && b.sourceIndex ) {
- return a.sourceIndex - b.sourceIndex;
- }
-
- var al, bl,
- ap = [],
- bp = [],
- aup = a.parentNode,
- bup = b.parentNode,
- cur = aup;
-
- // If the nodes are siblings (or identical) we can do a quick check
- if ( aup === bup ) {
- return siblingCheck( a, b );
-
- // If no parents were found then the nodes are disconnected
- } else if ( !aup ) {
- return -1;
-
- } else if ( !bup ) {
- return 1;
- }
-
- // Otherwise they're somewhere else in the tree so we need
- // to build up a full list of the parentNodes for comparison
- while ( cur ) {
- ap.unshift( cur );
- cur = cur.parentNode;
- }
-
- cur = bup;
-
- while ( cur ) {
- bp.unshift( cur );
- cur = cur.parentNode;
- }
-
- al = ap.length;
- bl = bp.length;
-
- // Start walking down the tree looking for a discrepancy
- for ( var i = 0; i < al && i < bl; i++ ) {
- if ( ap[i] !== bp[i] ) {
- return siblingCheck( ap[i], bp[i] );
- }
- }
-
- // We ended someplace up the tree so do a sibling check
- return i === al ?
- siblingCheck( a, bp[i], -1 ) :
- siblingCheck( ap[i], b, 1 );
- };
-
- siblingCheck = function( a, b, ret ) {
- if ( a === b ) {
- return ret;
- }
-
- var cur = a.nextSibling;
-
- while ( cur ) {
- if ( cur === b ) {
- return -1;
- }
-
- cur = cur.nextSibling;
- }
-
- return 1;
- };
-}
-
-// Check to see if the browser returns elements by name when
-// querying by getElementById (and provide a workaround)
-(function(){
- // We're going to inject a fake input element with a specified name
- var form = document.createElement("div"),
- id = "script" + (new Date()).getTime(),
- root = document.documentElement;
-
- form.innerHTML = "";
-
- // Inject it into the root element, check its status, and remove it quickly
- root.insertBefore( form, root.firstChild );
-
- // The workaround has to do additional checks after a getElementById
- // Which slows things down for other browsers (hence the branching)
- if ( document.getElementById( id ) ) {
- Expr.find.ID = function( match, context, isXML ) {
- if ( typeof context.getElementById !== "undefined" && !isXML ) {
- var m = context.getElementById(match[1]);
-
- return m ?
- m.id === match[1] || typeof m.getAttributeNode !== "undefined" && m.getAttributeNode("id").nodeValue === match[1] ?
- [m] :
- undefined :
- [];
- }
- };
-
- Expr.filter.ID = function( elem, match ) {
- var node = typeof elem.getAttributeNode !== "undefined" && elem.getAttributeNode("id");
-
- return elem.nodeType === 1 && node && node.nodeValue === match;
- };
- }
-
- root.removeChild( form );
-
- // release memory in IE
- root = form = null;
-})();
-
-(function(){
- // Check to see if the browser returns only elements
- // when doing getElementsByTagName("*")
-
- // Create a fake element
- var div = document.createElement("div");
- div.appendChild( document.createComment("") );
-
- // Make sure no comments are found
- if ( div.getElementsByTagName("*").length > 0 ) {
- Expr.find.TAG = function( match, context ) {
- var results = context.getElementsByTagName( match[1] );
-
- // Filter out possible comments
- if ( match[1] === "*" ) {
- var tmp = [];
-
- for ( var i = 0; results[i]; i++ ) {
- if ( results[i].nodeType === 1 ) {
- tmp.push( results[i] );
- }
- }
-
- results = tmp;
- }
-
- return results;
- };
- }
-
- // Check to see if an attribute returns normalized href attributes
- div.innerHTML = "";
-
- if ( div.firstChild && typeof div.firstChild.getAttribute !== "undefined" &&
- div.firstChild.getAttribute("href") !== "#" ) {
-
- Expr.attrHandle.href = function( elem ) {
- return elem.getAttribute( "href", 2 );
- };
- }
-
- // release memory in IE
- div = null;
-})();
-
-if ( document.querySelectorAll ) {
- (function(){
- var oldSizzle = Sizzle,
- div = document.createElement("div"),
- id = "__sizzle__";
-
- div.innerHTML = "";
-
- // Safari can't handle uppercase or unicode characters when
- // in quirks mode.
- if ( div.querySelectorAll && div.querySelectorAll(".TEST").length === 0 ) {
- return;
- }
-
- Sizzle = function( query, context, extra, seed ) {
- context = context || document;
-
- // Only use querySelectorAll on non-XML documents
- // (ID selectors don't work in non-HTML documents)
- if ( !seed && !Sizzle.isXML(context) ) {
- // See if we find a selector to speed up
- var match = /^(\w+$)|^\.([\w\-]+$)|^#([\w\-]+$)/.exec( query );
-
- if ( match && (context.nodeType === 1 || context.nodeType === 9) ) {
- // Speed-up: Sizzle("TAG")
- if ( match[1] ) {
- return makeArray( context.getElementsByTagName( query ), extra );
-
- // Speed-up: Sizzle(".CLASS")
- } else if ( match[2] && Expr.find.CLASS && context.getElementsByClassName ) {
- return makeArray( context.getElementsByClassName( match[2] ), extra );
- }
- }
-
- if ( context.nodeType === 9 ) {
- // Speed-up: Sizzle("body")
- // The body element only exists once, optimize finding it
- if ( query === "body" && context.body ) {
- return makeArray( [ context.body ], extra );
-
- // Speed-up: Sizzle("#ID")
- } else if ( match && match[3] ) {
- var elem = context.getElementById( match[3] );
-
- // Check parentNode to catch when Blackberry 4.6 returns
- // nodes that are no longer in the document #6963
- if ( elem && elem.parentNode ) {
- // Handle the case where IE and Opera return items
- // by name instead of ID
- if ( elem.id === match[3] ) {
- return makeArray( [ elem ], extra );
- }
-
- } else {
- return makeArray( [], extra );
- }
- }
-
- try {
- return makeArray( context.querySelectorAll(query), extra );
- } catch(qsaError) {}
-
- // qSA works strangely on Element-rooted queries
- // We can work around this by specifying an extra ID on the root
- // and working up from there (Thanks to Andrew Dupont for the technique)
- // IE 8 doesn't work on object elements
- } else if ( context.nodeType === 1 && context.nodeName.toLowerCase() !== "object" ) {
- var oldContext = context,
- old = context.getAttribute( "id" ),
- nid = old || id,
- hasParent = context.parentNode,
- relativeHierarchySelector = /^\s*[+~]/.test( query );
-
- if ( !old ) {
- context.setAttribute( "id", nid );
- } else {
- nid = nid.replace( /'/g, "\\$&" );
- }
- if ( relativeHierarchySelector && hasParent ) {
- context = context.parentNode;
- }
-
- try {
- if ( !relativeHierarchySelector || hasParent ) {
- return makeArray( context.querySelectorAll( "[id='" + nid + "'] " + query ), extra );
- }
-
- } catch(pseudoError) {
- } finally {
- if ( !old ) {
- oldContext.removeAttribute( "id" );
- }
- }
- }
- }
-
- return oldSizzle(query, context, extra, seed);
- };
-
- for ( var prop in oldSizzle ) {
- Sizzle[ prop ] = oldSizzle[ prop ];
- }
-
- // release memory in IE
- div = null;
- })();
-}
-
-(function(){
- var html = document.documentElement,
- matches = html.matchesSelector || html.mozMatchesSelector || html.webkitMatchesSelector || html.msMatchesSelector;
-
- if ( matches ) {
- // Check to see if it's possible to do matchesSelector
- // on a disconnected node (IE 9 fails this)
- var disconnectedMatch = !matches.call( document.createElement( "div" ), "div" ),
- pseudoWorks = false;
-
- try {
- // This should fail with an exception
- // Gecko does not error, returns false instead
- matches.call( document.documentElement, "[test!='']:sizzle" );
-
- } catch( pseudoError ) {
- pseudoWorks = true;
- }
-
- Sizzle.matchesSelector = function( node, expr ) {
- // Make sure that attribute selectors are quoted
- expr = expr.replace(/\=\s*([^'"\]]*)\s*\]/g, "='$1']");
-
- if ( !Sizzle.isXML( node ) ) {
- try {
- if ( pseudoWorks || !Expr.match.PSEUDO.test( expr ) && !/!=/.test( expr ) ) {
- var ret = matches.call( node, expr );
-
- // IE 9's matchesSelector returns false on disconnected nodes
- if ( ret || !disconnectedMatch ||
- // As well, disconnected nodes are said to be in a document
- // fragment in IE 9, so check for that
- node.document && node.document.nodeType !== 11 ) {
- return ret;
- }
- }
- } catch(e) {}
- }
-
- return Sizzle(expr, null, null, [node]).length > 0;
- };
- }
-})();
-
-(function(){
- var div = document.createElement("div");
-
- div.innerHTML = "";
-
- // Opera can't find a second classname (in 9.6)
- // Also, make sure that getElementsByClassName actually exists
- if ( !div.getElementsByClassName || div.getElementsByClassName("e").length === 0 ) {
- return;
- }
-
- // Safari caches class attributes, doesn't catch changes (in 3.2)
- div.lastChild.className = "e";
-
- if ( div.getElementsByClassName("e").length === 1 ) {
- return;
- }
-
- Expr.order.splice(1, 0, "CLASS");
- Expr.find.CLASS = function( match, context, isXML ) {
- if ( typeof context.getElementsByClassName !== "undefined" && !isXML ) {
- return context.getElementsByClassName(match[1]);
- }
- };
-
- // release memory in IE
- div = null;
-})();
-
-function dirNodeCheck( dir, cur, doneName, checkSet, nodeCheck, isXML ) {
- for ( var i = 0, l = checkSet.length; i < l; i++ ) {
- var elem = checkSet[i];
-
- if ( elem ) {
- var match = false;
-
- elem = elem[dir];
-
- while ( elem ) {
- if ( elem[ expando ] === doneName ) {
- match = checkSet[elem.sizset];
- break;
- }
-
- if ( elem.nodeType === 1 && !isXML ){
- elem[ expando ] = doneName;
- elem.sizset = i;
- }
-
- if ( elem.nodeName.toLowerCase() === cur ) {
- match = elem;
- break;
- }
-
- elem = elem[dir];
- }
-
- checkSet[i] = match;
- }
- }
-}
-
-function dirCheck( dir, cur, doneName, checkSet, nodeCheck, isXML ) {
- for ( var i = 0, l = checkSet.length; i < l; i++ ) {
- var elem = checkSet[i];
-
- if ( elem ) {
- var match = false;
-
- elem = elem[dir];
-
- while ( elem ) {
- if ( elem[ expando ] === doneName ) {
- match = checkSet[elem.sizset];
- break;
- }
-
- if ( elem.nodeType === 1 ) {
- if ( !isXML ) {
- elem[ expando ] = doneName;
- elem.sizset = i;
- }
-
- if ( typeof cur !== "string" ) {
- if ( elem === cur ) {
- match = true;
- break;
- }
-
- } else if ( Sizzle.filter( cur, [elem] ).length > 0 ) {
- match = elem;
- break;
- }
- }
-
- elem = elem[dir];
- }
-
- checkSet[i] = match;
- }
- }
-}
-
-if ( document.documentElement.contains ) {
- Sizzle.contains = function( a, b ) {
- return a !== b && (a.contains ? a.contains(b) : true);
- };
-
-} else if ( document.documentElement.compareDocumentPosition ) {
- Sizzle.contains = function( a, b ) {
- return !!(a.compareDocumentPosition(b) & 16);
- };
-
-} else {
- Sizzle.contains = function() {
- return false;
- };
-}
-
-Sizzle.isXML = function( elem ) {
- // documentElement is verified for cases where it doesn't yet exist
- // (such as loading iframes in IE - #4833)
- var documentElement = (elem ? elem.ownerDocument || elem : 0).documentElement;
-
- return documentElement ? documentElement.nodeName !== "HTML" : false;
-};
-
-var posProcess = function( selector, context, seed ) {
- var match,
- tmpSet = [],
- later = "",
- root = context.nodeType ? [context] : context;
-
- // Position selectors must be done after the filter
- // And so must :not(positional) so we move all PSEUDOs to the end
- while ( (match = Expr.match.PSEUDO.exec( selector )) ) {
- later += match[0];
- selector = selector.replace( Expr.match.PSEUDO, "" );
- }
-
- selector = Expr.relative[selector] ? selector + "*" : selector;
-
- for ( var i = 0, l = root.length; i < l; i++ ) {
- Sizzle( selector, root[i], tmpSet, seed );
- }
-
- return Sizzle.filter( later, tmpSet );
-};
-
-// EXPOSE
-// Override sizzle attribute retrieval
-Sizzle.attr = jQuery.attr;
-Sizzle.selectors.attrMap = {};
-jQuery.find = Sizzle;
-jQuery.expr = Sizzle.selectors;
-jQuery.expr[":"] = jQuery.expr.filters;
-jQuery.unique = Sizzle.uniqueSort;
-jQuery.text = Sizzle.getText;
-jQuery.isXMLDoc = Sizzle.isXML;
-jQuery.contains = Sizzle.contains;
-
-
-})();
-
-
-var runtil = /Until$/,
- rparentsprev = /^(?:parents|prevUntil|prevAll)/,
- // Note: This RegExp should be improved, or likely pulled from Sizzle
- rmultiselector = /,/,
- isSimple = /^.[^:#\[\.,]*$/,
- slice = Array.prototype.slice,
- POS = jQuery.expr.match.globalPOS,
- // methods guaranteed to produce a unique set when starting from a unique set
- guaranteedUnique = {
- children: true,
- contents: true,
- next: true,
- prev: true
- };
-
-jQuery.fn.extend({
- find: function( selector ) {
- var self = this,
- i, l;
-
- if ( typeof selector !== "string" ) {
- return jQuery( selector ).filter(function() {
- for ( i = 0, l = self.length; i < l; i++ ) {
- if ( jQuery.contains( self[ i ], this ) ) {
- return true;
- }
- }
- });
- }
-
- var ret = this.pushStack( "", "find", selector ),
- length, n, r;
-
- for ( i = 0, l = this.length; i < l; i++ ) {
- length = ret.length;
- jQuery.find( selector, this[i], ret );
-
- if ( i > 0 ) {
- // Make sure that the results are unique
- for ( n = length; n < ret.length; n++ ) {
- for ( r = 0; r < length; r++ ) {
- if ( ret[r] === ret[n] ) {
- ret.splice(n--, 1);
- break;
- }
- }
- }
- }
- }
-
- return ret;
- },
-
- has: function( target ) {
- var targets = jQuery( target );
- return this.filter(function() {
- for ( var i = 0, l = targets.length; i < l; i++ ) {
- if ( jQuery.contains( this, targets[i] ) ) {
- return true;
- }
- }
- });
- },
-
- not: function( selector ) {
- return this.pushStack( winnow(this, selector, false), "not", selector);
- },
-
- filter: function( selector ) {
- return this.pushStack( winnow(this, selector, true), "filter", selector );
- },
-
- is: function( selector ) {
- return !!selector && (
- typeof selector === "string" ?
- // If this is a positional selector, check membership in the returned set
- // so $("p:first").is("p:last") won't return true for a doc with two "p".
- POS.test( selector ) ?
- jQuery( selector, this.context ).index( this[0] ) >= 0 :
- jQuery.filter( selector, this ).length > 0 :
- this.filter( selector ).length > 0 );
- },
-
- closest: function( selectors, context ) {
- var ret = [], i, l, cur = this[0];
-
- // Array (deprecated as of jQuery 1.7)
- if ( jQuery.isArray( selectors ) ) {
- var level = 1;
-
- while ( cur && cur.ownerDocument && cur !== context ) {
- for ( i = 0; i < selectors.length; i++ ) {
-
- if ( jQuery( cur ).is( selectors[ i ] ) ) {
- ret.push({ selector: selectors[ i ], elem: cur, level: level });
- }
- }
-
- cur = cur.parentNode;
- level++;
- }
-
- return ret;
- }
-
- // String
- var pos = POS.test( selectors ) || typeof selectors !== "string" ?
- jQuery( selectors, context || this.context ) :
- 0;
-
- for ( i = 0, l = this.length; i < l; i++ ) {
- cur = this[i];
-
- while ( cur ) {
- if ( pos ? pos.index(cur) > -1 : jQuery.find.matchesSelector(cur, selectors) ) {
- ret.push( cur );
- break;
-
- } else {
- cur = cur.parentNode;
- if ( !cur || !cur.ownerDocument || cur === context || cur.nodeType === 11 ) {
- break;
- }
- }
- }
- }
-
- ret = ret.length > 1 ? jQuery.unique( ret ) : ret;
-
- return this.pushStack( ret, "closest", selectors );
- },
-
- // Determine the position of an element within
- // the matched set of elements
- index: function( elem ) {
-
- // No argument, return index in parent
- if ( !elem ) {
- return ( this[0] && this[0].parentNode ) ? this.prevAll().length : -1;
- }
-
- // index in selector
- if ( typeof elem === "string" ) {
- return jQuery.inArray( this[0], jQuery( elem ) );
- }
-
- // Locate the position of the desired element
- return jQuery.inArray(
- // If it receives a jQuery object, the first element is used
- elem.jquery ? elem[0] : elem, this );
- },
-
- add: function( selector, context ) {
- var set = typeof selector === "string" ?
- jQuery( selector, context ) :
- jQuery.makeArray( selector && selector.nodeType ? [ selector ] : selector ),
- all = jQuery.merge( this.get(), set );
-
- return this.pushStack( isDisconnected( set[0] ) || isDisconnected( all[0] ) ?
- all :
- jQuery.unique( all ) );
- },
-
- andSelf: function() {
- return this.add( this.prevObject );
- }
-});
-
-// A painfully simple check to see if an element is disconnected
-// from a document (should be improved, where feasible).
-function isDisconnected( node ) {
- return !node || !node.parentNode || node.parentNode.nodeType === 11;
-}
-
-jQuery.each({
- parent: function( elem ) {
- var parent = elem.parentNode;
- return parent && parent.nodeType !== 11 ? parent : null;
- },
- parents: function( elem ) {
- return jQuery.dir( elem, "parentNode" );
- },
- parentsUntil: function( elem, i, until ) {
- return jQuery.dir( elem, "parentNode", until );
- },
- next: function( elem ) {
- return jQuery.nth( elem, 2, "nextSibling" );
- },
- prev: function( elem ) {
- return jQuery.nth( elem, 2, "previousSibling" );
- },
- nextAll: function( elem ) {
- return jQuery.dir( elem, "nextSibling" );
- },
- prevAll: function( elem ) {
- return jQuery.dir( elem, "previousSibling" );
- },
- nextUntil: function( elem, i, until ) {
- return jQuery.dir( elem, "nextSibling", until );
- },
- prevUntil: function( elem, i, until ) {
- return jQuery.dir( elem, "previousSibling", until );
- },
- siblings: function( elem ) {
- return jQuery.sibling( ( elem.parentNode || {} ).firstChild, elem );
- },
- children: function( elem ) {
- return jQuery.sibling( elem.firstChild );
- },
- contents: function( elem ) {
- return jQuery.nodeName( elem, "iframe" ) ?
- elem.contentDocument || elem.contentWindow.document :
- jQuery.makeArray( elem.childNodes );
- }
-}, function( name, fn ) {
- jQuery.fn[ name ] = function( until, selector ) {
- var ret = jQuery.map( this, fn, until );
-
- if ( !runtil.test( name ) ) {
- selector = until;
- }
-
- if ( selector && typeof selector === "string" ) {
- ret = jQuery.filter( selector, ret );
- }
-
- ret = this.length > 1 && !guaranteedUnique[ name ] ? jQuery.unique( ret ) : ret;
-
- if ( (this.length > 1 || rmultiselector.test( selector )) && rparentsprev.test( name ) ) {
- ret = ret.reverse();
- }
-
- return this.pushStack( ret, name, slice.call( arguments ).join(",") );
- };
-});
-
-jQuery.extend({
- filter: function( expr, elems, not ) {
- if ( not ) {
- expr = ":not(" + expr + ")";
- }
-
- return elems.length === 1 ?
- jQuery.find.matchesSelector(elems[0], expr) ? [ elems[0] ] : [] :
- jQuery.find.matches(expr, elems);
- },
-
- dir: function( elem, dir, until ) {
- var matched = [],
- cur = elem[ dir ];
-
- while ( cur && cur.nodeType !== 9 && (until === undefined || cur.nodeType !== 1 || !jQuery( cur ).is( until )) ) {
- if ( cur.nodeType === 1 ) {
- matched.push( cur );
- }
- cur = cur[dir];
- }
- return matched;
- },
-
- nth: function( cur, result, dir, elem ) {
- result = result || 1;
- var num = 0;
-
- for ( ; cur; cur = cur[dir] ) {
- if ( cur.nodeType === 1 && ++num === result ) {
- break;
- }
- }
-
- return cur;
- },
-
- sibling: function( n, elem ) {
- var r = [];
-
- for ( ; n; n = n.nextSibling ) {
- if ( n.nodeType === 1 && n !== elem ) {
- r.push( n );
- }
- }
-
- return r;
- }
-});
-
-// Implement the identical functionality for filter and not
-function winnow( elements, qualifier, keep ) {
-
- // Can't pass null or undefined to indexOf in Firefox 4
- // Set to 0 to skip string check
- qualifier = qualifier || 0;
-
- if ( jQuery.isFunction( qualifier ) ) {
- return jQuery.grep(elements, function( elem, i ) {
- var retVal = !!qualifier.call( elem, i, elem );
- return retVal === keep;
- });
-
- } else if ( qualifier.nodeType ) {
- return jQuery.grep(elements, function( elem, i ) {
- return ( elem === qualifier ) === keep;
- });
-
- } else if ( typeof qualifier === "string" ) {
- var filtered = jQuery.grep(elements, function( elem ) {
- return elem.nodeType === 1;
- });
-
- if ( isSimple.test( qualifier ) ) {
- return jQuery.filter(qualifier, filtered, !keep);
- } else {
- qualifier = jQuery.filter( qualifier, filtered );
- }
- }
-
- return jQuery.grep(elements, function( elem, i ) {
- return ( jQuery.inArray( elem, qualifier ) >= 0 ) === keep;
- });
-}
-
-
-
-
-function createSafeFragment( document ) {
- var list = nodeNames.split( "|" ),
- safeFrag = document.createDocumentFragment();
-
- if ( safeFrag.createElement ) {
- while ( list.length ) {
- safeFrag.createElement(
- list.pop()
- );
- }
- }
- return safeFrag;
-}
-
-var nodeNames = "abbr|article|aside|audio|bdi|canvas|data|datalist|details|figcaption|figure|footer|" +
- "header|hgroup|mark|meter|nav|output|progress|section|summary|time|video",
- rinlinejQuery = / jQuery\d+="(?:\d+|null)"/g,
- rleadingWhitespace = /^\s+/,
- rxhtmlTag = /<(?!area|br|col|embed|hr|img|input|link|meta|param)(([\w:]+)[^>]*)\/>/ig,
- rtagName = /<([\w:]+)/,
- rtbody = /]", "i"),
- // checked="checked" or checked
- rchecked = /checked\s*(?:[^=]|=\s*.checked.)/i,
- rscriptType = /\/(java|ecma)script/i,
- rcleanScript = /^\s*", "" ],
- legend: [ 1, "" ],
- thead: [ 1, "