Skip to content
Browse files

Better javascript api.

  • Loading branch information...
1 parent b4744d8 commit 8d9f0681496c430f3d9737f6ee2720189eb63484 Tom Shaw committed Mar 11, 2012
Showing with 120 additions and 25 deletions.
  1. +120 −25 public/js/gridola.js
View
145 public/js/gridola.js
@@ -1,36 +1,131 @@
+/* Gridola - Super Simple Grid for Zend Framework 1.11.11
+ * ============================================================
+ * http://github.com/tomshaw/gridola
+ * ============================================================
+ * (The MIT License)
+ *
+ * Copyright(c) 2011 Tom Shaw <tom@tomshaw.info>
+ * 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.
+ * ============================================================ */
+
/*!
- * Gridola - Super Simple Grid for Zend Framework 1.x
+ * Gridola - Super Simple Grid for Zend Framework 1.11.11
* Copyright(c) 2011 Tom Shaw <tom@tomshaw.info>
* MIT Licensed
-*/
-
-/**
- * Dynamically injects a new form action based on the mass action select url key value.
*/
-$(document).ready(function () {
- $('#massaction').change(function () {
- var action = $(this).val();
- jQuery.each(jsonActions, function (key, val) {
- if (key == action) {
- $(gridolaFormId).attr('action', val.url);
- return false;
- }
+
+!function ($) {
+
+ "use strict";
+
+ var Action = function (element) {
+ this.$element = $(element);
+ this.$jsonActions = jsonActions;
+ this.process();
+ };
+
+ Action.prototype = {
+ constructor: Action,
+ process: function () {
+ var $el = this.$element,
+ $jsonActions = this.$jsonActions;
+ jQuery.each($jsonActions, function (key, val) {
+ if (key == $el.val()) {
+ $(gridolaFormId).attr('action', val.url);
+ return false;
+ }
+ });
+ }
+ };
+
+ $.fn.action = function (option) {
+ return this.each(function () {
+ var $this = $(this),
+ data = $this.data('action');
+ if (!this.$default) this.$default = $(gridolaFormId).attr("action");
+ $(gridolaFormId).attr('action', this.$default);
+ if (!data) $this.data('action', (data = new Action(this)));
+ if (typeof option == 'string') data[option].call($this);
+ });
+ };
+
+ $.fn.action.Constructor = Action;
+
+ $(function () {
+ $('body').on('change', '#massaction', function () {
+ var $switch = $(this);
+ $switch.action($switch.data());
});
});
-});
+
+}(window.jQuery);
-/**
- * Removes the clickable row functionality in table elements using inputs.
- * Namely checkboxes for mass actions.
+/*!
+ * Gridola - Super Simple Grid for Zend Framework 1.11.11
+ * Copyright(c) 2011 Tom Shaw <tom@tomshaw.info>
+ * MIT Licensed
*/
-jQuery(function ($) {
- $('tbody tr[data-href]').addClass('clickable').click(function () {
- window.location = $(this).attr('data-href');
- }).find('input').hover(function () {
- $(this).parents('tr').unbind('click');
- }, function () {
- $(this).parents('tr').click(function () {
+
+!function ($) {
+
+ "use strict";
+
+ var selector = 'tbody tr[data-href]',
+ namespace = 'click.table-row.data-api',
+ Row = function (element) {
+ this.checkboxes($(element).on(namespace, this.location));
+ };
+
+ Row.prototype = {
+ constructor: Row,
+ location: function () {
window.location = $(this).attr('data-href');
+ return false;
+ },
+ checkboxes: function (element) {
+ var $element = $(element);
+ $element.find('input').hover(function () {
+ $(this).parents('tr').unbind(namespace);
+ }).parents('tr').on(namespace, function () {
+ this.location();
+ });
+ }
+ };
+
+ $.fn.tablerow = function (option) {
+ return this.each(function () {
+ var $this = $(this),
+ data = $this.data('tablerow');
+ if (!data) $this.data('tablerow', (data = new Row(this)));
+ if (typeof option == 'string') data[option].call($this);
+ });
+ };
+
+ $.fn.tablerow.Constructor = Row;
+
+ $(function () {
+ $(selector).each(function () {
+ var $this = $(this);
+ if ($this.data('tablerow')) return;
+ $this.tablerow($this.data());
});
});
-});
+
+}(window.jQuery);

0 comments on commit 8d9f068

Please sign in to comment.
Something went wrong with that request. Please try again.