Skip welcome & menu and move to editor
Welcome to JS Bin
Load cached copy from
 
<!DOCTYPE html>
<html>
<head>
<script src="http://code.jquery.com/jquery-1.10.2.min.js"></script>
<meta charset=utf-8 />
<title>JS Bin</title>
</head>
<body>
  <div id="target">This is the target</div>
  <script>
    (function ($, undefined) {
      var methods = {
        init: function(options) {
          // Determine options
          var opts = $.extend({
            opacity: 0.5             
          }, options);
          
          // Remember them
          this.data("pluginname", opts);
          
          // Initial stuff
          this.css("opacity", opts.opacity);
        },
        
        callThis: function(opts) {
          // Use 'opts' if relevant
          this.css("display","none");
        },
        
        destroy: function(opts) {
          this.removeData("pluginame");
          this.css("display", "").css("opacity", "");
        }
      };
      
      jQuery.fn.pluginname = function (options) {
        var method, args;
        
        // Method?
        if (typeof options === "string") {
          // Yes, grab the name
          method = options;
          
          // And arguments (we copy the arguments, then
          // replace the first with our options)
          args = Array.prototype.slice.call(arguments, 0);
          
          // Get our options from setup call
          args[0] = this.data("pluginname");
          if (!args[0]) {
            // There was no setup call, do setup with defaults
            methods.init.call(this);
            args[0] = this.data("pluginname");
          }
        }
        else {
          // Not a method call, use init
          method = "init";
          args = [options];
        }
        
        // Do the call
        methods[method].apply(this, args);
      };
    })(jQuery);
    
    function doInit() {
      $("#target").pluginname();
      setTimeout(doCallThis, 700);
    }
    function doCallThis() {
      $("#target").pluginname("callThis");
      setTimeout(doDestroy, 700);
    }
    function doDestroy() {
      $("#target").pluginname("destroy");
      setTimeout(doInit, 700);
    }
    setTimeout(doInit, 1000);
  </script>
</body>
</html>
Output

You can jump to the latest bin by adding /latest to your URL

Dismiss x
public
Bin info
anonymouspro
0viewers