This repository has been archived by the owner on Jun 7, 2019. It is now read-only.
forked from yui/yui3-gallery
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
gallery-2012.08.01-13-16 joeauty gallery-nmpjaxplus
- Loading branch information
YUI Builder
committed
Aug 1, 2012
1 parent
9caca0c
commit 3ad0bea
Showing
3 changed files
with
319 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
# NetMusician PJAX Plus Build Properties | ||
|
||
# As long as the 'builder' project is cloned to the default folder | ||
# next to the 'yui3-gallery' project folder, the 'builddir' property does not | ||
# need to be changed | ||
# | ||
# If the 'builder' project is checked out to an alternate location, this | ||
# property should be updated to point to the checkout location. | ||
builddir=../../../builder/componentbuild | ||
|
||
# The name of the component. E.g. event, attribute, widget | ||
component=gallery-nmpjaxplus | ||
|
||
# The list of files which should be concatenated to create the component | ||
# NOTE: For a css component. (e.g. cssfonts, cssgrids etc.) use component.cssfiles instead. | ||
# component.jsfiles=nmmenus.js, nmmenusHelperClass.js, nmmenusSubComponentClass.js | ||
component.jsfiles=nmpjaxplus.js | ||
|
||
# The list of modules this component. requires. Used to set up the Y.add module call for YUI 3. | ||
component.requires=base-build, widget, node, io, history, pjax, event-delegate, cache-base, selector-css3 | ||
|
||
# The list of modules this component. supersedes. Used to set up the Y.add module call for YUI 3. | ||
component.supersedes= | ||
|
||
# The list of modules that are optional for this module. Used to set up the Y.add module call for YUI 3. | ||
component.optional= | ||
# If your module has a skin file, set this flag to "true" | ||
component.skinnable=false | ||
#component.skinnable=true; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<!-- YUI 3 Gallery Component Build File --> | ||
<project name="NetMusician PJAX Plus" default="local"> | ||
<description>NetMusician PJAX Plus Build File</description> | ||
<property file="build.properties" /> | ||
<import file="${builddir}/3.x/bootstrap.xml" description="Default Build Properties and Targets" /> | ||
</project> | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,282 @@ | ||
YUI.add('gallery-nmpjaxplus', function(Y){ | ||
|
||
Y.PjaxPlus = Y.Base.create('pjaxplus', Y.Widget, [], { | ||
initializer : function( config ) { | ||
// error checking for missing required variables | ||
|
||
this.set('history', new Y.History()); | ||
//this.set('history', new Y.HistoryHash()); | ||
this.set('html5support', Y.HistoryBase.html5); | ||
//this.set('html5support', false); | ||
this.ppCache = new Y.Cache({max:this.get('cacheNum')}); | ||
this.domain = new RegExp('^(http|https):\/\/' + window.location.hostname.replace('.','\.')); | ||
|
||
// remove leading dot from omitLinkClass, if any | ||
if (this.get('omitLinkClass').match(/^\./)) { | ||
this.set('omitLinkClass', this.get('omitLinkClass').replace(/^\./,'')); | ||
} | ||
}, | ||
|
||
initAjaxLinks : function() { | ||
var clickedLink, | ||
clickedTarget; | ||
|
||
if (this.get('html5support')) { | ||
// attach yui3-pjax class to links with REST-like URLs or URLs with permitted file extensions | ||
var goodext = false; | ||
Y.all('a:not(.' + this.get('omitLinkClass') + ')').each(function(node) { | ||
var pathnamearr = node.get('pathname').split(/\//); | ||
var pathnameidx = pathnamearr.length - 1; | ||
var filename = pathnamearr[pathnameidx]; | ||
|
||
if (!filename.match(/\./)) { | ||
// no file extension, valid REST-like URL | ||
goodext = true; | ||
} | ||
else { | ||
// URL contains file extensions, look for permitted file extensions | ||
goodext = Y.Array.some(this.get('permittedFileExts'), function(ext) { | ||
var thisregex = new RegExp('\.' + ext + '$'); | ||
if (filename.match(thisregex)) { | ||
return true; | ||
} | ||
}); | ||
} | ||
|
||
if (goodext && !node.get('href').match(/^(mailto|javascript):/) && !node.get('href').match(/^#/) && | ||
node.get('href').match(this.domain) && !node.hasClass(this.get('omitLinkClass'))) { | ||
node.addClass('yui3-pjax'); | ||
} | ||
}, this); | ||
|
||
var PjaxLoader = new Y.Pjax({ | ||
addPjaxParam : this.get('addPjaxParam'), | ||
container: this.get('container'), | ||
contentSelector: this.get('contentSelector'), | ||
linkSelector: this.get('linkSelector'), | ||
navigateOnHash: this.get('navigateOnHash'), | ||
scrollToTop: this.get('scrollToTop'), | ||
timeout: this.get('timeout'), | ||
titleSelector: this.get('titleSelector') | ||
}); | ||
|
||
// trigger start callback | ||
PjaxLoader.on('navigate', function(e) { | ||
// set var for currently clicked link | ||
clickedLink = e.originEvent.target.get('href'); | ||
var html5support = this.get('html5support'); | ||
|
||
if (this.get('startCallbackFunc') && !this.ppCache.retrieve(clickedLink)) { | ||
//Y.log('trigger start callback'); | ||
this.get('startCallbackFunc').call(null, { | ||
clickTarget:e.originEvent.target, | ||
path:e.originEvent.target.get('pathname'), | ||
url:e.originEvent.target.get('href'), | ||
html5support:html5support | ||
}, this); | ||
} | ||
}, this); | ||
|
||
// trigger callback | ||
PjaxLoader.after('load', function(e) { | ||
var html5support = this.get('html5support'); | ||
|
||
if (this.get('callbackFunc')) { | ||
this.get('callbackFunc').call(null, { | ||
clickTarget:clickedTarget, | ||
path:clickedTarget.get('pathname'), | ||
url:clickedTarget.get('href'), | ||
html5support:html5support | ||
}, this); | ||
} | ||
|
||
Y.all(this.get('container') + ' a:not(.' + this.get('omitLinkClass') + ')').addClass('yui3-pjax'); | ||
//Y.log('add ' + clickedLink + ' to cache'); | ||
// add content to cache | ||
this.ppCache.add(clickedLink, Y.one(this.get('contentSelector')).getContent()); | ||
}, this); | ||
|
||
Y.delegate('click', function(e) { | ||
clickedTarget = e.target; | ||
|
||
//Y.log('checking cache for ' + e.target.get('href')); | ||
if (this.ppCache.retrieve(e.target.get('href'))) { | ||
//Y.log('CACHE FOUND'); | ||
Y.one(this.get('contentSelector')).setContent(this.ppCache.retrieve(e.target.get('href')).response); | ||
} | ||
}, document.body, 'a.yui3-pjax', this); | ||
} | ||
else { | ||
Y.delegate('click', function(e) { | ||
var html5support = this.get('html5support'); | ||
|
||
if (typeof e.target.get('pathname') !== "undefined") { | ||
var historyhash = e.target.get('pathname').replace(/_/g,'-'); | ||
historyhash = e.target.get('pathname').replace(/\//g,'_'); | ||
|
||
if (this.ppCache.retrieve(e.target.get('href'))) { | ||
// output cache, set history token | ||
Y.one(this.get('contentSelector')).setContent(this.ppCache.retrieve(e.target.get('href')).response); | ||
|
||
this.get('history').add({ | ||
page:historyhash | ||
}); | ||
|
||
if (this.get('callbackFunc')) { | ||
// invoke custom function | ||
this.get('callbackFunc').call(null, { | ||
clickTarget:e.target, | ||
path:e.target.get('pathname'), | ||
url:e.target.get('href'), | ||
historyhash:historyhash, | ||
html5support:html5support | ||
}, this); | ||
} | ||
return; | ||
} | ||
} | ||
|
||
var goodext = false; | ||
if (typeof e.target.get('pathname') == "undefined") { | ||
// no path provided, default to homepage | ||
e.preventDefault(); | ||
this.startAjaxLoad({ | ||
clickTarget:e.target, | ||
url:'/' | ||
}); | ||
} | ||
else { | ||
var pathnamearr = e.target.get('pathname').split(/\//); | ||
var pathnameidx = pathnamearr.length - 1; | ||
var filename = pathnamearr[pathnameidx]; | ||
|
||
if (!filename.match(/\./)) { | ||
// no file extension, valid REST-like URL | ||
goodext = true; | ||
} | ||
else { | ||
// URL contains file extensions, look for permitted file extensions | ||
goodext = Y.Array.some(this.get('permittedFileExts'), function(ext) { | ||
var thisregex = new RegExp('\.' + ext + '$'); | ||
if (filename.match(thisregex)) { | ||
return true; | ||
} | ||
}); | ||
} | ||
|
||
if (goodext && !e.target.get('href').match(/^(mailto|javascript):/) && !e.target.get('href').match(/^#/) && | ||
e.target.get('href').match(this.domain) && !e.target.hasClass(this.get('omitLinkClass'))) { | ||
e.preventDefault(); | ||
this.startAjaxLoad({ | ||
clickTarget:e.target, | ||
path:e.target.get('pathname'), | ||
url:e.target.get('href'), | ||
historyhash:historyhash, | ||
html5support:html5support | ||
}); | ||
} | ||
} | ||
|
||
}, this.get('findLinksIn'), 'a:not(.' + this.get('omitLinkClass') + ')', this); | ||
|
||
} | ||
}, | ||
|
||
startAjaxLoad : function(configObj) { | ||
if (this.get('startCallbackFunc') && !this.ppCache.retrieve(configObj.url)) { | ||
//Y.log('trigger start callback - AJAX'); | ||
this.get('startCallbackFunc').call(null, configObj, this); | ||
} | ||
|
||
var cfg = { | ||
timeout: this.get('timeout'), | ||
on : { | ||
complete:Y.bind(function(id, transport) { | ||
var frag = Y.Node.create(transport.responseText); | ||
Y.one(this.get('contentSelector')).setContent(frag.one(this.get('contentSelector')).getContent()); | ||
|
||
// set history token | ||
this.get('history').add({ | ||
page:configObj.historyhash | ||
}); | ||
|
||
// cache output | ||
this.ppCache.add(configObj.url, frag.one(this.get('contentSelector')).getContent()); | ||
|
||
}, this), | ||
|
||
success:Y.bind(function(id, transport) { | ||
configObj.transport = transport; | ||
|
||
if (this.get('callbackFunc')) { | ||
// invoke custom function | ||
this.get('callbackFunc').call(null, configObj, this); | ||
} | ||
}, this) | ||
} | ||
}; | ||
|
||
Y.io(configObj.url, cfg); | ||
} | ||
|
||
}, { | ||
ATTRS : { | ||
findLinksIn : { | ||
value : document.body | ||
}, | ||
|
||
container : { | ||
|
||
}, | ||
|
||
timeout : { | ||
value : 30000 | ||
}, | ||
|
||
addPjaxParam : { | ||
value : true | ||
}, | ||
|
||
linkSelector : { | ||
value : 'a.yui3-pjax' | ||
}, | ||
|
||
scrollToTop : { | ||
value : true | ||
}, | ||
|
||
navigateOnHash : { | ||
value : false | ||
}, | ||
|
||
titleSelector : { | ||
value : 'title' | ||
}, | ||
|
||
contentSelector : { | ||
|
||
}, | ||
|
||
omitLinkClass : { | ||
|
||
}, | ||
|
||
permittedFileExts : { | ||
|
||
}, | ||
|
||
startCallbackFunc : { | ||
|
||
}, | ||
|
||
callbackFunc : { | ||
|
||
}, | ||
|
||
cacheNum : { | ||
value : 10 | ||
} | ||
} | ||
}); | ||
|
||
}, '@VERSION@', {requires: ['base-build', 'widget', 'node', 'io', 'history', 'pjax', 'event-delegate', 'cache-base', 'selector-css3']}); |