Skip to content

Commit

Permalink
moving to jquery 1.7 and $.Callbacks pub/sub
Browse files Browse the repository at this point in the history
  • Loading branch information
draeton committed Dec 7, 2011
1 parent fe74c65 commit 97c49e8
Show file tree
Hide file tree
Showing 6 changed files with 59 additions and 43 deletions.
4 changes: 2 additions & 2 deletions _templates/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ Stitches requires a stylesheet, a script, and an HTML element to get the job don

<link rel="stylesheet" href="css/stitches-@[email protected]">

<script src="js/jquery-1.6.2.min.js"></script>
<script src="js/jquery-1.7.1.min.js"></script>
<script src="js/modernizr-2.0.6.min.js"></script>

<script src="js/stitches-@[email protected]"></script>
Expand All @@ -30,7 +30,7 @@ Once that's in place, the sprite generator is created by the `init` method:

## Dependencies

jQuery 1.6.2+, Modernizr; *Dropfile, Flashcanvas for older browser support*
jQuery 1.7.1+, Modernizr; *Dropfile, Flashcanvas for older browser support*

## License

Expand Down
18 changes: 0 additions & 18 deletions src/lib/jquery-1.6.2.min.js

This file was deleted.

4 changes: 4 additions & 0 deletions src/lib/jquery-1.7.1.min.js

Large diffs are not rendered by default.

21 changes: 5 additions & 16 deletions src/page.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,21 +43,8 @@
// ### init
//
// Creates the stitches widget using the `$elem` as a container
//
// @param {jQuery} $elem The container node
init: function ($elem) {
if (!$elem) {
$elem = $('<div>').appendTo('body');
}
Stitches.Page.$elem = $elem;

if (typeof FileReader !== "undefined" && Modernizr.draganddrop) {
/* load templates */
Stitches.Page.getTemplates();
} else {
/* browser is not compatible */
// TODO show an error message
}
init: function () {
Stitches.Page.getTemplates();
},

// ### getTemplates
Expand Down Expand Up @@ -133,6 +120,8 @@
// @param {Event} evt Click event
// @return {Boolean}
handleButtons: function (evt) {
evt.preventDefault();

if (/disabled/.test(this.className)) {
return false;
}
Expand Down Expand Up @@ -162,7 +151,7 @@
setButtonDisabled: function (disabled, buttons) {
var action = disabled ? "add" : "remove";

buttons.forEach(function (val, idx) {
buttons.forEach(function (val) {
Stitches.Page.buttons["$" + val][action + "Class"]("disabled");
});
},
Expand Down
53 changes: 47 additions & 6 deletions src/stitches.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@
"jsdir": "js"
};

// **Pub/sub subscription manager**
var topics = {};

return {
// ### init
//
Expand All @@ -30,20 +33,58 @@
// @param {Object} config An optional settings object
init: function ($elem, config) {
Stitches.settings = $.extend({}, defaults, config);
Stitches.filesCount = 0;
Stitches.Page.$elem = $elem;

var jsdir = Stitches.settings.jsdir;
Stitches.sub("page.init", Stitches.Page.init);
Stitches.sub("page.error", Stitches.Page.error);

if (typeof FileReader === "undefined" || Modernizr.draganddrop) {
Stitches.loadSupport();
} else {
Stitches.pub("page.init");
}
},

// ### sub
//
// Subscribe to a topic
//
// @param {String} topic The subscription topic name
// @param {Function} fn A callback to fire
sub: function (topic, fn) {
topics[topic] = topics[topic] || $.Callbacks("stopOnFalse");
topics[topic].add(fn);
},

// ### pub
//
// Publish a topic
//
// @param {String} topic The subscription topic name
pub: function (topic) {
var callbacks, args;
if (topics[topic]) {
callbacks = topics[topic];
args = Array.prototype.slice.call(arguments, 1);
callbacks.fire.apply(callbacks, args);
}
},

// ### loadSupport
//
// Load supporting libraries for browsers with no native support
loadSupport: function () {
Modernizr.load([
{
test: typeof FileReader !== "undefined" && Modernizr.draganddrop,
nope: jsdir + "/dropfile/dropfile.js"
nope: Stitches.settings.jsdir + "/dropfile/dropfile.js"
},
{
test: Modernizr.canvas,
nope: jsdir + "/flashcanvas/flashcanvas.js",
nope: Stitches.settings.jsdir + "/flashcanvas/flashcanvas.js",
complete: function () {
Stitches.filesCount = 0;
Stitches.Page.init($elem);
Stitches.pub("page.init");
}
}
]);
Expand Down Expand Up @@ -124,7 +165,7 @@
text += " background: url(sprite.png) no-repeat;\n";
text += "}\n\n";

Stitches.placedIcons.forEach(function (icon, idx) {
Stitches.placedIcons.forEach(function (icon) {
text += ".sprite-" + icon.name + " {\n";
text += " width: " + icon.width + "px;\n";
text += " height: " + icon.height + "px;\n";
Expand Down
2 changes: 1 addition & 1 deletion tests/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

<link rel="stylesheet" href="../src/stitches.css">

<script src="../src/lib/jquery-1.6.2.min.js"></script>
<script src="../src/lib/jquery-1.7.1.min.js"></script>
<script src="../src/lib/modernizr-2.0.6.min.js"></script>

<script src="../src/stitches.js"></script>
Expand Down

0 comments on commit 97c49e8

Please sign in to comment.