Chris Leonello avatar Chris Leonello committed f5339d3

Added jQuery plugin syntax compatability for plot creation. Can now use $('some-selector').jqplot(data, options) syntax and chain the results.

Comments (0)

Files changed (1)

src/jqplot.core.js

       }
     };
 
+    $.fn.jqplot = function(data, options) {
+
+        return this.each(function() {
+            var tid, 
+                plot, 
+                $this = $(this);
+            // does el have an id?
+            // if not assign it one.
+            tid = $this.attr('id');
+            if (tid === undefined) {
+                tid = 'jqplot_target_' + $.jqplot.targetCounter++;
+                $this.attr('id', tid);
+            }
+
+            plot = $.jqplot(tid, data, options);
+
+            $this.data('jqplot', plot);
+        });
+    };
+
 
     /**
      * Namespace: $.jqplot
 
     $.jqplot.version = "@VERSION";
 
+    $.jqplot.targetCounter = 1;
+
     // canvas manager to reuse canvases on the plot.
     // Should help solve problem of canvases not being freed and
     // problem of waiting forever for firefox to decide to free memory.
             // Add a reference to plot
             //////
             if (this._addDomReference) {
-                this.target.data('jqplot_plot', this);
+                this.target.data('jqplot', this);
             }
             // remove any error class that may be stuck on target.
             this.target.removeClass('jqplot-error');
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.