Skip to content

Commit 590c9a3

Browse files
committed
Add GitHub banner, fix code padding, fix bug with marking menu items on hashchange
1 parent 9f0d604 commit 590c9a3

36 files changed

+5337
-4585
lines changed

.DS_Store

0 Bytes
Binary file not shown.

_layouts/default.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
<title>CanJS</title>
55
<link rel="stylesheet" type="text/css" href="stylesheets/styles.css">
66
<link rel="stylesheet" type="text/css" href="stylesheets/tango.css">
7-
87
</head>
98
<body>
109
<div id='bg'>
@@ -29,11 +28,12 @@
2928
</div>
3029
<div id='content-wrapper'>
3130
<div id='content'>
31+
<a href="http://github.com/jupiterjs/canjs" class="github-fork"><img src="https://a248.e.akamai.net/assets.github.com/img/30f550e0d38ceb6ef5b81500c64d970b7fb0f028/687474703a2f2f73332e616d617a6f6e6177732e636f6d2f6769746875622f726962626f6e732f666f726b6d655f72696768745f6f72616e67655f6666373630302e706e67" alt="Fork me on GitHub"></a>
3232
{{ content }}
3333
</div>
3434
</div>
3535
</div>
36-
<script src="javascripts/jquery-1.6.4.min.js" type="text/javascript"></script>
36+
<script src="javascripts/jquery-1.7.1.min.js" type="text/javascript"></script>
3737
<script src="javascripts/jquerymx-3.2.custom.js" type="text/javascript"></script>
3838
<script src="javascripts/application.js" type="text/javascript"></script>
3939
</body>

_site/index.html

Lines changed: 115 additions & 165 deletions
Large diffs are not rendered by default.

_site/javascripts/application.js

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
var currentH2slug = "";
22

3-
$.Controller('Menu', {}, {
3+
$.Controller('Menu', {
4+
}, {
45
init : function(){
56
this.find('#menu').append(this.buildMenu());
67
setTimeout(this.proxy(function(){
@@ -88,7 +89,6 @@ $.Controller('Menu', {}, {
8889
}
8990
},
9091
markActive : function(active, current){
91-
console.log(active, current)
9292
var currentLevel = current.data('level'),
9393
activeLevel = active.data('level'),
9494
method = {2: 'siblings', 3: 'closest'}[currentLevel],
@@ -158,9 +158,18 @@ $.Controller('Menu', {}, {
158158
slideDur : function(ul, hide){
159159
var base = hide ? 50 : 30,
160160
dur = base * ul.find('li').length;
161-
console.log(dur)
162161
dur = dur > 200 ? dur : 200
163162
return dur;
163+
},
164+
"{window} hashchange" : function(el, ev){
165+
var hash = location.hash,
166+
current = this.find('#menu a[href$='+hash+']'),
167+
active = this.find('#menu a.active'),
168+
self = this;
169+
setTimeout(function(){
170+
self.markActive(active, current);
171+
}, 1)
172+
164173
}
165174
});
166175

_site/javascripts/development/jquery.class.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@
5454
* @parent jquerymx
5555
* @download dist/jquery/jquery.class.js
5656
* @test jquery/class/qunit.html
57+
* @description Easy inheritance in JavaScript.
5758
*
5859
* Class provides simulated inheritance in JavaScript. Use clss to bridge the gap between
5960
* jQuery's functional programming style and Object Oriented Programming. It
@@ -649,7 +650,7 @@
649650

650651
// call the class init
651652
if ( Class.init ) {
652-
Class.init.apply(Class, args || []);
653+
Class.init.apply(Class, args || concatArgs([_super_class],arguments));
653654
}
654655

655656
/* @Prototype*/

_site/javascripts/development/jquery.controller.js

Lines changed: 45 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@
8080
* @download http://jmvcsite.heroku.com/pluginify?plugins[]=jquery/controller/controller.js
8181
* @test jquery/controller/qunit.html
8282
* @inherits jQuery.Class
83+
* @description jQuery widget factory.
8384
*
8485
* jQuery.Controller helps create organized, memory-leak free, rapidly performing
8586
* jQuery widgets. Its extreme flexibility allows it to serve as both
@@ -222,7 +223,7 @@
222223
* el.css("backgroundColor","")
223224
* },
224225
* ".create click" : function() {
225-
* this.find("ol").append("&lt;li class='todo'>New Todo&lt;/li>");
226+
* this.find("ol").append("<li class='todo'>New Todo</li>");
226227
* }
227228
* })
228229
*
@@ -607,7 +608,8 @@
607608
var funcName, ready, cls = this[STR_CONSTRUCTOR];
608609

609610
//want the raw element here
610-
element = element.jquery ? element[0] : element;
611+
element = (typeof element == 'string' ? $(element) :
612+
(element.jquery ? element : [element]) )[0];
611613

612614
//set element and className on element
613615
var pluginname = cls.pluginName || cls._fullName;
@@ -621,12 +623,28 @@
621623

622624
/**
623625
* @attribute options
624-
* Options is [jQuery.Controller.static.defaults] merged with the 2nd argument
626+
*
627+
* Options are used to configure an controller. They are
628+
* the 2nd argument
625629
* passed to a controller (or the first argument passed to the
626630
* [jquery.controller.plugin controller's jQuery plugin]).
627631
*
628632
* For example:
629633
*
634+
* $.Controller('Hello')
635+
*
636+
* var h1 = new Hello($('#content1'), {message: 'World'} );
637+
* equal( h1.options.message , "World" )
638+
*
639+
* var h2 = $('#content2').hello({message: 'There'})
640+
* .controller();
641+
* equal( h2.options.message , "There" )
642+
*
643+
* Options are merged with [jQuery.Controller.static.defaults defaults] in
644+
* [jQuery.Controller.prototype.setup setup].
645+
*
646+
* For example:
647+
*
630648
* $.Controller("Tabs",
631649
* {
632650
* defaults : {
@@ -642,7 +660,9 @@
642660
* $("#tabs1").tabs() // adds 'ui-active-state'
643661
* $("#tabs2").tabs({activeClass : 'active'}) // adds 'active'
644662
*
645-
*
663+
* Options are typically updated by calling
664+
* [jQuery.Controller.prototype.update update];
665+
*
646666
*/
647667
this.options = extend( extend(true, {}, cls.defaults), options);
648668

@@ -704,7 +724,12 @@
704724
* }
705725
* }
706726
*/
707-
return this.element;
727+
return [this.element, this.options].concat(makeArray(arguments).slice(2));
728+
/**
729+
* @function init
730+
*
731+
* Implement this.
732+
*/
708733
},
709734
/**
710735
* Bind attaches event handlers that will be
@@ -832,15 +857,15 @@
832857
* $.Controller('Creator',{
833858
* "{recipe} created" : function(){
834859
* this.update({recipe : new Recipe()});
835-
* this.element[0].reset();
836-
* this.find("[type=submit]").val("Create Recipe")
860+
* this.element[0].reset();
861+
* this.find("[type=submit]").val("Create Recipe")
837862
* },
838863
* "submit" : function(el, ev){
839-
* ev.preventDefault();
840-
* var recipe = this.options.recipe;
841-
* recipe.attrs( this.element.formParams() );
842-
* this.find("[type=submit]").val("Saving...")
843-
* recipe.save();
864+
* ev.preventDefault();
865+
* var recipe = this.options.recipe;
866+
* recipe.attrs( this.element.formParams() );
867+
* this.find("[type=submit]").val("Saving...")
868+
* recipe.save();
844869
* }
845870
* });
846871
* $('#createRecipes').creator({recipe : new Recipe()})
@@ -858,24 +883,24 @@
858883
* $.Controller('Updater',{
859884
* // when the controller is created, update the html
860885
* init : function(){
861-
* this.updateView();
886+
* this.updateView();
862887
* },
863888
*
864889
* // update the html with a template
865890
* updateView : function(){
866-
* this.element.html( "content.ejs",
867-
* this.options.model );
891+
* this.element.html( "content.ejs",
892+
* this.options.model );
868893
* },
869894
*
870895
* // if the model is updated
871896
* "{model} updated" : function(){
872-
* this.updateView();
897+
* this.updateView();
873898
* },
874899
* update : function(options){
875-
* // make sure you call super
876-
* this._super(options);
900+
* // make sure you call super
901+
* this._super(options);
877902
*
878-
* this.updateView();
903+
* this.updateView();
879904
* }
880905
* })
881906
*
@@ -1002,7 +1027,7 @@
10021027

10031028

10041029

1005-
//set commong events to be processed as a basicProcessor
1030+
//set common events to be processed as a basicProcessor
10061031
each("change click contextmenu dblclick keydown keyup keypress mousedown mousemove mouseout mouseover mouseup reset resize scroll select submit focusin focusout mouseenter mouseleave".split(" "), function( i, v ) {
10071032
processors[v] = basicProcessor;
10081033
});
Lines changed: 174 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,174 @@
1+
(function($){
2+
'$:nomunge'; // Used by YUI compressor.
3+
4+
// Method / object references.
5+
var fake_onhashchange,
6+
jq_event_special = $.event.special,
7+
8+
// Reused strings.
9+
str_location = 'location',
10+
str_hashchange = 'hashchange',
11+
str_href = 'href',
12+
13+
// IE6/7 specifically need some special love when it comes to back-button
14+
// support, so let's do a little browser sniffing..
15+
browser = $.browser,
16+
mode = document.documentMode,
17+
is_old_ie = browser.msie && ( mode === undefined || mode < 8 ),
18+
19+
// Does the browser support window.onhashchange? Test for IE version, since
20+
// IE8 incorrectly reports this when in "IE7" or "IE8 Compatibility View"!
21+
supports_onhashchange = 'on' + str_hashchange in window && !is_old_ie;
22+
23+
// Get location.hash (or what you'd expect location.hash to be) sans any
24+
// leading #. Thanks for making this necessary, Firefox!
25+
function get_fragment( url ) {
26+
url = url || window[ str_location ][ str_href ];
27+
return url.replace( /^[^#]*#?(.*)$/, '$1' );
28+
};
29+
30+
// Property: jQuery.hashchangeDelay
31+
//
32+
// The numeric interval (in milliseconds) at which the <hashchange event>
33+
// polling loop executes. Defaults to 100.
34+
35+
$[ str_hashchange + 'Delay' ] = 100;
36+
37+
// Event: hashchange event
38+
//
39+
// Fired when location.hash changes. In browsers that support it, the native
40+
// window.onhashchange event is used (IE8, FF3.6), otherwise a polling loop is
41+
// initialized, running every <jQuery.hashchangeDelay> milliseconds to see if
42+
// the hash has changed. In IE 6 and 7, a hidden Iframe is created to allow
43+
// the back button and hash-based history to work.
44+
//
45+
// Usage:
46+
//
47+
// > $(window).bind( 'hashchange', function(e) {
48+
// > var hash = location.hash;
49+
// > ...
50+
// > });
51+
//
52+
// Additional Notes:
53+
//
54+
// * The polling loop and Iframe are not created until at least one callback
55+
// is actually bound to 'hashchange'.
56+
// * If you need the bound callback(s) to execute immediately, in cases where
57+
// the page 'state' exists on page load (via bookmark or page refresh, for
58+
// example) use $(window).trigger( 'hashchange' );
59+
// * The event can be bound before DOM ready, but since it won't be usable
60+
// before then in IE6/7 (due to the necessary Iframe), recommended usage is
61+
// to bind it inside a $(document).ready() callback.
62+
63+
jq_event_special[ str_hashchange ] = $.extend( jq_event_special[ str_hashchange ], {
64+
65+
// Called only when the first 'hashchange' event is bound to window.
66+
setup: function() {
67+
// If window.onhashchange is supported natively, there's nothing to do..
68+
if ( supports_onhashchange ) { return false; }
69+
70+
// Otherwise, we need to create our own. And we don't want to call this
71+
// until the user binds to the event, just in case they never do, since it
72+
// will create a polling loop and possibly even a hidden Iframe.
73+
$( fake_onhashchange.start );
74+
},
75+
76+
// Called only when the last 'hashchange' event is unbound from window.
77+
teardown: function() {
78+
// If window.onhashchange is supported natively, there's nothing to do..
79+
if ( supports_onhashchange ) { return false; }
80+
81+
// Otherwise, we need to stop ours (if possible).
82+
$( fake_onhashchange.stop );
83+
}
84+
85+
});
86+
87+
// fake_onhashchange does all the work of triggering the window.onhashchange
88+
// event for browsers that don't natively support it, including creating a
89+
// polling loop to watch for hash changes and in IE 6/7 creating a hidden
90+
// Iframe to enable back and forward.
91+
fake_onhashchange = (function(){
92+
var self = {},
93+
timeout_id,
94+
iframe,
95+
set_history,
96+
get_history;
97+
98+
// Initialize. In IE 6/7, creates a hidden Iframe for history handling.
99+
function init(){
100+
// Most browsers don't need special methods here..
101+
set_history = get_history = function(val){ return val; };
102+
103+
// But IE6/7 do!
104+
if ( is_old_ie ) {
105+
106+
// Create hidden Iframe after the end of the body to prevent initial
107+
// page load from scrolling unnecessarily.
108+
iframe = $('<iframe src="javascript:0"/>').hide().insertAfter( 'body' )[0].contentWindow;
109+
110+
// Get history by looking at the hidden Iframe's location.hash.
111+
get_history = function() {
112+
return get_fragment( iframe.document[ str_location ][ str_href ] );
113+
};
114+
115+
// Set a new history item by opening and then closing the Iframe
116+
// document, *then* setting its location.hash.
117+
set_history = function( hash, history_hash ) {
118+
if ( hash !== history_hash ) {
119+
var doc = iframe.document;
120+
doc.open().close();
121+
doc[ str_location ].hash = '#' + hash;
122+
}
123+
};
124+
125+
// Set initial history.
126+
set_history( get_fragment() );
127+
}
128+
};
129+
130+
// Start the polling loop.
131+
self.start = function() {
132+
// Polling loop is already running!
133+
if ( timeout_id ) { return; }
134+
135+
// Remember the initial hash so it doesn't get triggered immediately.
136+
var last_hash = get_fragment();
137+
138+
// Initialize if not yet initialized.
139+
set_history || init();
140+
141+
// This polling loop checks every $.hashchangeDelay milliseconds to see if
142+
// location.hash has changed, and triggers the 'hashchange' event on
143+
// window when necessary.
144+
if(!navigator.userAgent.match(/Rhino/))
145+
(function loopy(){
146+
var hash = get_fragment(),
147+
history_hash = get_history( last_hash );
148+
149+
if ( hash !== last_hash ) {
150+
set_history( last_hash = hash, history_hash );
151+
152+
$(window).trigger( str_hashchange );
153+
154+
} else if ( history_hash !== last_hash ) {
155+
window[ str_location ][ str_href ] = window[ str_location ][ str_href ].replace( /#.*/, '' ) + '#' + history_hash;
156+
}
157+
158+
timeout_id = setTimeout( loopy, $[ str_hashchange + 'Delay' ] );
159+
})();
160+
};
161+
162+
// Stop the polling loop, but only if an IE6/7 Iframe wasn't created. In
163+
// that case, even if there are no longer any bound event handlers, the
164+
// polling loop is still necessary for back/next to work at all!
165+
self.stop = function() {
166+
if ( !iframe ) {
167+
timeout_id && clearTimeout( timeout_id );
168+
timeout_id = 0;
169+
}
170+
};
171+
172+
return self;
173+
})();
174+
})(jQuery);

0 commit comments

Comments
 (0)