youthtree-js 0.2.0 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +45 -0
- data/Rakefile +1 -1
- data/coffeescripts/youth_tree/ck_editor.coffee +32 -0
- data/coffeescripts/youth_tree/convertable_editor.coffee +29 -0
- data/coffeescripts/youth_tree/disqus.coffee +27 -0
- data/coffeescripts/youth_tree/flickr/gallery.coffee +48 -0
- data/coffeescripts/youth_tree/flickr.coffee +35 -0
- data/coffeescripts/youth_tree/util.coffee +52 -0
- data/javascripts/youth_tree/ck_editor.js +27 -0
- data/javascripts/youth_tree/convertable_editor.js +33 -0
- data/javascripts/youth_tree/disqus.js +35 -0
- data/javascripts/youth_tree/flickr/gallery.js +66 -0
- data/javascripts/youth_tree/flickr.js +35 -0
- data/javascripts/youth_tree/util.js +64 -0
- data/lib/youthtree-js.rb +6 -2
- data/youthtree-js.gemspec +21 -10
- metadata +18 -6
data/README.md
CHANGED
@@ -6,6 +6,51 @@ Developed primarily for [TEDxPerth](http://tedxperth.org/) and [Big Help Mob](ht
|
|
6
6
|
|
7
7
|
Relies on [Shuriken](http://github.com/Sutto/shuriken/).
|
8
8
|
|
9
|
+
## Currently provided tools
|
10
|
+
|
11
|
+
YouthTree JS provides a small number of different pieces of code for a variety of common tasks.
|
12
|
+
|
13
|
+
Out of the box, the main namespaces are:
|
14
|
+
|
15
|
+
### YouthTree.CKEditor
|
16
|
+
|
17
|
+
A simple wrapper around CKEditor that unobtrusively sets up the jQuery adapter on fields
|
18
|
+
with a class of `.ckeditor` on the container. Also, the width is set to deal with the
|
19
|
+
common [bhm-admin](http://github.com/YouthTree/bhm-admin) sides images.
|
20
|
+
|
21
|
+
### YouthTree.ConvertableEditor
|
22
|
+
|
23
|
+
Even more magic for YouthTree.CKEditor. Let's you mark a fieldset wrapper with `.convertable` and it'll
|
24
|
+
automatically find the select and textarea, showing when the select has a format of "raw". Designed
|
25
|
+
to work out of the box with how most [almost-happy](http://github.com/Sutto/almost-happy) editors work.
|
26
|
+
|
27
|
+
### YouthTree.Disqus
|
28
|
+
|
29
|
+
Unobtrusively adds the Disqus html based on the presence of meta tags in the page with the names:
|
30
|
+
|
31
|
+
* `disqus-identifier`
|
32
|
+
* `disqus-site`
|
33
|
+
* `disqus-developer`
|
34
|
+
|
35
|
+
Aka, super simple Disqus commenting for pretty much any website.
|
36
|
+
|
37
|
+
### YouthTree.Flickr
|
38
|
+
|
39
|
+
Simple, unobtrusive wrapper around the flickr api for use with the Flickr Gallery.
|
40
|
+
|
41
|
+
### YouthTree.Flickr.Gallery
|
42
|
+
|
43
|
+
Gives the ability to pull in simple HTML from given flickr tags / photo set ids.
|
44
|
+
|
45
|
+
### YouthTree.Gallery
|
46
|
+
|
47
|
+
Generic facy-boxed autosetup and gallery features based on simple markup.
|
48
|
+
|
49
|
+
### YouthTree.Util
|
50
|
+
|
51
|
+
A set of common JS helper methods similar to their Rails counterparts,
|
52
|
+
exposed via JS for use in arbitrary rails apps frontends.
|
53
|
+
|
9
54
|
## Contributing ##
|
10
55
|
|
11
56
|
We encourage all community contributions. Keeping this in mind, please follow these general guidelines when contributing:
|
data/Rakefile
CHANGED
@@ -23,7 +23,7 @@ desc "Compiles the javascript from Coffeescript to Javascript"
|
|
23
23
|
task :compile_scripts do
|
24
24
|
Dir["coffeescripts/**/*.coffee"].each do |cs|
|
25
25
|
output = File.dirname(cs).gsub("coffeescripts", "javascripts")
|
26
|
-
system "coffee", "--no-wrap",
|
26
|
+
system "coffee", "-c", "--no-wrap", '-o', output, cs
|
27
27
|
end
|
28
28
|
end
|
29
29
|
|
@@ -0,0 +1,32 @@
|
|
1
|
+
YouthTree.withNS 'CKEditor', (ns) ->
|
2
|
+
|
3
|
+
window.CKEDITOR_BASEPATH = '/ckeditor/'
|
4
|
+
|
5
|
+
ns.editorSelector = '.ckeditor textarea'
|
6
|
+
ns.editorOptions =
|
7
|
+
toolbar: 'youthtree'
|
8
|
+
width: '71%'
|
9
|
+
customConfig: false
|
10
|
+
|
11
|
+
ns.toolbar_layout = [
|
12
|
+
['Source','-','Templates'], ['Cut','Copy','Paste','PasteText','PasteFromWord','-', 'SpellChecker', 'Scayt'],
|
13
|
+
['Undo','Redo','-','Find','Replace','RemoveFormat'],
|
14
|
+
'/',
|
15
|
+
['Bold','Italic','Underline','Strike'], ['NumberedList','BulletedList', 'Blockquote'],
|
16
|
+
['JustifyLeft','JustifyCenter','JustifyRight','JustifyBlock'], ['Link','Unlink','Anchor'], ['Image','Flash','Table','HorizontalRule'],
|
17
|
+
'/',
|
18
|
+
['Styles','Format','Font','FontSize'], ['TextColor','BGColor'], ['Maximize', 'ShowBlocks']
|
19
|
+
]
|
20
|
+
|
21
|
+
currentEditorOptions = ->
|
22
|
+
options = $.extend {}, ns.editorOptions
|
23
|
+
options.toolbar_youthtree = ns.toolbar_layout
|
24
|
+
options
|
25
|
+
|
26
|
+
ns.makeEditor = (jq) ->
|
27
|
+
jq.ckeditor currentEditorOptions()
|
28
|
+
|
29
|
+
ns.destroyEditor = (jq) ->
|
30
|
+
jq.ckeditorGet()?.destroy()
|
31
|
+
|
32
|
+
ns.setup = -> ns.makeEditor $(ns.editorSelector)
|
@@ -0,0 +1,29 @@
|
|
1
|
+
YouthTree.withNS 'ConvertableEditor', (ns) ->
|
2
|
+
|
3
|
+
ns.containerSelector = 'fieldset.inputs.convertable'
|
4
|
+
ns.editorSelector = 'textarea'
|
5
|
+
ns.formatSelector = 'select'
|
6
|
+
|
7
|
+
ns.showEditor = (s) ->
|
8
|
+
YouthTree.CKEditor.makeEditor s
|
9
|
+
|
10
|
+
ns.hideEditor = (s) ->
|
11
|
+
YouthTree.CKEditor.destroyEditor s
|
12
|
+
|
13
|
+
ns.shouldShowEditor = (s) ->
|
14
|
+
s.find(ns.formatSelector).val() is "raw"
|
15
|
+
|
16
|
+
ns.toggleEditorOn = (scope) ->
|
17
|
+
ns.debug scope
|
18
|
+
$scope = $ scope
|
19
|
+
if ns.shouldShowEditor $scope
|
20
|
+
ns.showEditor $scope.find(ns.editorSelector)
|
21
|
+
else
|
22
|
+
ns.hideEditor $scope.find(ns.editorSelector)
|
23
|
+
|
24
|
+
ns.attachEvents = ->
|
25
|
+
$(ns.containerSelector).each ->
|
26
|
+
$(@).find(ns.formatSelector).change =>
|
27
|
+
ns.toggleEditorOn @
|
28
|
+
|
29
|
+
ns.setup = -> ns.attachEvents()
|
@@ -0,0 +1,27 @@
|
|
1
|
+
YouthTree.withNS 'Disqus', (ns) ->
|
2
|
+
|
3
|
+
ns.collectionSelector = '#posts'
|
4
|
+
|
5
|
+
ns.currentIdentifier = ->
|
6
|
+
$.metaAttr "disqus-identifier"
|
7
|
+
|
8
|
+
ns.currentSite = ->
|
9
|
+
$.metaAttr "disqus-site"
|
10
|
+
|
11
|
+
ns.isDebug = ->
|
12
|
+
$.metaAttr("disqus-developer") is "true"
|
13
|
+
|
14
|
+
ns.configureDisqus = ->
|
15
|
+
window.disqus_identifier = ns.currentIdentifier()
|
16
|
+
window.disqus_developer = 1 if ns.isDebug()
|
17
|
+
|
18
|
+
ns.addScripts = ->
|
19
|
+
ns.configureDisqus()
|
20
|
+
script = $ "<script />", type: "text/javascript", async: true
|
21
|
+
if $(ns.collectionSelector).size() > 0
|
22
|
+
script.attr "src", "http://disqus.com/forums/#{ns.currentSite()}/count.js"
|
23
|
+
else
|
24
|
+
script.attr "src", "http://#{ns.currentSite()}.disqus.com/embed.js"
|
25
|
+
script.appendTo $ "head"
|
26
|
+
|
27
|
+
ns.setup = -> ns.addScripts()
|
@@ -0,0 +1,48 @@
|
|
1
|
+
YouthTree.withNS 'Flickr.Gallery', (ns) ->
|
2
|
+
|
3
|
+
flickr = YouthTree.Flickr
|
4
|
+
|
5
|
+
ns.navigationClass = 'flickr-gallery-navigation'
|
6
|
+
ns.containerClass = 'flickr-gallery'
|
7
|
+
|
8
|
+
class InnerFlickrGallery
|
9
|
+
|
10
|
+
constructor: (@name, @container) ->
|
11
|
+
@container.addClass ns.containerClass
|
12
|
+
|
13
|
+
fetchPhotoset: (photosetId, extraParams) ->
|
14
|
+
params =
|
15
|
+
photoset_id: photosetId
|
16
|
+
extras: 'url_sq,url_m'
|
17
|
+
$.extend params, extraParams if extraParams?
|
18
|
+
flickr.apiCall 'flickr.photosets.getPhotos', params, (response) =>
|
19
|
+
@process response.photoset.photo
|
20
|
+
|
21
|
+
fetchUserTagged: (user, tag, extraParams) ->
|
22
|
+
params =
|
23
|
+
tags: tag
|
24
|
+
user_id: user
|
25
|
+
sort: 'interestingness-desc'
|
26
|
+
content_type: '1'
|
27
|
+
media: 'photos'
|
28
|
+
$.extend params, extraParams if extraParams?
|
29
|
+
flickr.apiCall 'flickr.photos.search', params, (response) =>
|
30
|
+
@process response.photos.photo
|
31
|
+
|
32
|
+
process: (photos) ->
|
33
|
+
@container.empty()
|
34
|
+
$.each photos, (i, item) =>
|
35
|
+
img = $('<img/>').attr('src', item.url_sq)
|
36
|
+
link = $('<a></a>').attr('href', item.url_m).append img
|
37
|
+
@container.append link
|
38
|
+
YouthTree.Gallery.create @name, @container.find('a')
|
39
|
+
|
40
|
+
ns.fromPhotoset = (name, container, photoset, extraParams) ->
|
41
|
+
flickr_gallery = new InnerFlickrGallery name, container
|
42
|
+
flickr_gallery.fetchPhotoset photoset, extraParams
|
43
|
+
flickr_gallery
|
44
|
+
|
45
|
+
ns.fromUserTag = (name, container, user, tag, extraParams) ->
|
46
|
+
flickr_gallery = new InnerFlickrGallery name, container
|
47
|
+
flickr_gallery.fetchUserTagged user, tag, extraParams
|
48
|
+
flickr_gallery
|
@@ -0,0 +1,35 @@
|
|
1
|
+
YouthTree.withNS 'Flickr', (ns) ->
|
2
|
+
|
3
|
+
ns.apiBaseURL = 'http://api.flickr.com/services/rest/'
|
4
|
+
|
5
|
+
ns.defaultOptions =
|
6
|
+
format: 'json'
|
7
|
+
api_key: ''
|
8
|
+
|
9
|
+
ns.defaultErrorHandler = (response) ->
|
10
|
+
if window.console?
|
11
|
+
ns.log "Error: #{response.code} - #{response.message}"
|
12
|
+
|
13
|
+
ns.apiCall = (name, options, callback, errback) ->
|
14
|
+
return unless ns.apiKey?
|
15
|
+
errback?= ns.defaultErrorHandler
|
16
|
+
# Do something here,
|
17
|
+
apiOptions = method: name
|
18
|
+
$.extend apiOptions, options, ns.defaultOptions
|
19
|
+
$.ajax
|
20
|
+
url: ns.apiBaseURL
|
21
|
+
dataType: 'jsonp',
|
22
|
+
jsonp: 'jsoncallback'
|
23
|
+
data: apiOptions
|
24
|
+
success: (data) ->
|
25
|
+
if data.stat is 'ok'
|
26
|
+
callback data
|
27
|
+
else
|
28
|
+
errback data
|
29
|
+
|
30
|
+
ns.setup = ->
|
31
|
+
# Get the current api key
|
32
|
+
ns.apiKey = $.metaAttr 'flickr-api-key'
|
33
|
+
# Set it for requests.
|
34
|
+
ns.defaultOptions.api_key = ns.apiKey
|
35
|
+
|
@@ -0,0 +1,52 @@
|
|
1
|
+
YouthTree.withNS 'Util', (ns) ->
|
2
|
+
|
3
|
+
ns.escapeHTML = (s) ->
|
4
|
+
s.replace(/&/g, '&').replace(/</g, "<").replace(/>/g, ">").replace(/'/g, "'").replace(/"/g, """)
|
5
|
+
|
6
|
+
ns.autolink = (text) ->
|
7
|
+
text.replace(/(\bhttp:\/\/\S+(\/|\b))/gi, '<a href="$1" target="_blank">$1</a>')
|
8
|
+
|
9
|
+
ns.format = (text) ->
|
10
|
+
ns.autolink ns.escapeHTML text
|
11
|
+
|
12
|
+
ns.h = ns.escapeHTML
|
13
|
+
|
14
|
+
ns.formatTime = (s) ->
|
15
|
+
time = new Date(s)
|
16
|
+
period = ""
|
17
|
+
hour = time.getHours()
|
18
|
+
if hour is 0
|
19
|
+
period = "am"
|
20
|
+
hour = 12
|
21
|
+
else if hour < 12
|
22
|
+
period = "am"
|
23
|
+
else if hour is 12
|
24
|
+
period = "pm"
|
25
|
+
else if hour < 24
|
26
|
+
preiod = "pm"
|
27
|
+
hour -= 12
|
28
|
+
minutes = time.getMinutes()
|
29
|
+
minutesPrefix = if minutes < 10 then "0" else ""
|
30
|
+
"#{hour}:#{minutesPrefix}#{minutes} #{period}"
|
31
|
+
|
32
|
+
ns.attachUpdatingTimeAgo = (object, date) ->
|
33
|
+
existing = $(object).dataAttr "time-ago-interval"
|
34
|
+
clearInterval(parseInt(existing, 10)) if existing?
|
35
|
+
update = =>
|
36
|
+
object.html ns.timeAgoInWords(date)
|
37
|
+
update()
|
38
|
+
$(object).dataAttr "time-ago-interval", setInterval(update, 60000)
|
39
|
+
|
40
|
+
ns.truncate = (text, length) ->
|
41
|
+
length?= 100
|
42
|
+
suffix = if text.length > length then "…" else ""
|
43
|
+
text = "#{ns.h text.slice(0, length)}#{suffix}"
|
44
|
+
|
45
|
+
ns.timeAgoInWords = (date) ->
|
46
|
+
if $.browser.ie?
|
47
|
+
date = Date.parse date.replace /( \+)/," UTC$1"
|
48
|
+
else
|
49
|
+
date = Date.parse date
|
50
|
+
time = Number new Date(date)
|
51
|
+
now = Number new Date()
|
52
|
+
$.timeago.inWords(now - time)
|
@@ -0,0 +1,27 @@
|
|
1
|
+
YouthTree.withNS('CKEditor', function(ns) {
|
2
|
+
var currentEditorOptions;
|
3
|
+
window.CKEDITOR_BASEPATH = '/ckeditor/';
|
4
|
+
ns.editorSelector = '.ckeditor textarea';
|
5
|
+
ns.editorOptions = {
|
6
|
+
toolbar: 'youthtree',
|
7
|
+
width: '71%',
|
8
|
+
customConfig: false
|
9
|
+
};
|
10
|
+
ns.toolbar_layout = [['Source', '-', 'Templates'], ['Cut', 'Copy', 'Paste', 'PasteText', 'PasteFromWord', '-', 'SpellChecker', 'Scayt'], ['Undo', 'Redo', '-', 'Find', 'Replace', 'RemoveFormat'], '/', ['Bold', 'Italic', 'Underline', 'Strike'], ['NumberedList', 'BulletedList', 'Blockquote'], ['JustifyLeft', 'JustifyCenter', 'JustifyRight', 'JustifyBlock'], ['Link', 'Unlink', 'Anchor'], ['Image', 'Flash', 'Table', 'HorizontalRule'], '/', ['Styles', 'Format', 'Font', 'FontSize'], ['TextColor', 'BGColor'], ['Maximize', 'ShowBlocks']];
|
11
|
+
currentEditorOptions = function() {
|
12
|
+
var options;
|
13
|
+
options = $.extend({}, ns.editorOptions);
|
14
|
+
options.toolbar_youthtree = ns.toolbar_layout;
|
15
|
+
return options;
|
16
|
+
};
|
17
|
+
ns.makeEditor = function(jq) {
|
18
|
+
return jq.ckeditor(currentEditorOptions());
|
19
|
+
};
|
20
|
+
ns.destroyEditor = function(jq) {
|
21
|
+
var _ref, _ref2;
|
22
|
+
return (typeof (_ref2 = ((_ref = jq.ckeditorGet()))) === "undefined" || _ref2 === null) ? undefined : _ref2.destroy();
|
23
|
+
};
|
24
|
+
return (ns.setup = function() {
|
25
|
+
return ns.makeEditor($(ns.editorSelector));
|
26
|
+
});
|
27
|
+
});
|
@@ -0,0 +1,33 @@
|
|
1
|
+
var __bind = function(func, context) {
|
2
|
+
return function(){ return func.apply(context, arguments); };
|
3
|
+
};
|
4
|
+
YouthTree.withNS('ConvertableEditor', function(ns) {
|
5
|
+
ns.containerSelector = 'fieldset.inputs.convertable';
|
6
|
+
ns.editorSelector = 'textarea';
|
7
|
+
ns.formatSelector = 'select';
|
8
|
+
ns.showEditor = function(s) {
|
9
|
+
return YouthTree.CKEditor.makeEditor(s);
|
10
|
+
};
|
11
|
+
ns.hideEditor = function(s) {
|
12
|
+
return YouthTree.CKEditor.destroyEditor(s);
|
13
|
+
};
|
14
|
+
ns.shouldShowEditor = function(s) {
|
15
|
+
return s.find(ns.formatSelector).val() === "raw";
|
16
|
+
};
|
17
|
+
ns.toggleEditorOn = function(scope) {
|
18
|
+
var $scope;
|
19
|
+
ns.debug(scope);
|
20
|
+
$scope = $(scope);
|
21
|
+
return ns.shouldShowEditor($scope) ? ns.showEditor($scope.find(ns.editorSelector)) : ns.hideEditor($scope.find(ns.editorSelector));
|
22
|
+
};
|
23
|
+
ns.attachEvents = function() {
|
24
|
+
return $(ns.containerSelector).each(function() {
|
25
|
+
return $(this).find(ns.formatSelector).change(__bind(function() {
|
26
|
+
return ns.toggleEditorOn(this);
|
27
|
+
}, this));
|
28
|
+
});
|
29
|
+
};
|
30
|
+
return (ns.setup = function() {
|
31
|
+
return ns.attachEvents();
|
32
|
+
});
|
33
|
+
});
|
@@ -0,0 +1,35 @@
|
|
1
|
+
YouthTree.withNS('Disqus', function(ns) {
|
2
|
+
ns.collectionSelector = '#posts';
|
3
|
+
ns.currentIdentifier = function() {
|
4
|
+
return $.metaAttr("disqus-identifier");
|
5
|
+
};
|
6
|
+
ns.currentSite = function() {
|
7
|
+
return $.metaAttr("disqus-site");
|
8
|
+
};
|
9
|
+
ns.isDebug = function() {
|
10
|
+
return $.metaAttr("disqus-developer") === "true";
|
11
|
+
};
|
12
|
+
ns.configureDisqus = function() {
|
13
|
+
window.disqus_identifier = ns.currentIdentifier();
|
14
|
+
if (ns.isDebug()) {
|
15
|
+
return (window.disqus_developer = 1);
|
16
|
+
}
|
17
|
+
};
|
18
|
+
ns.addScripts = function() {
|
19
|
+
var script;
|
20
|
+
ns.configureDisqus();
|
21
|
+
script = $("<script />", {
|
22
|
+
type: "text/javascript",
|
23
|
+
async: true
|
24
|
+
});
|
25
|
+
if ($(ns.collectionSelector).size() > 0) {
|
26
|
+
script.attr("src", "http://disqus.com/forums/" + (ns.currentSite()) + "/count.js");
|
27
|
+
} else {
|
28
|
+
script.attr("src", "http://" + (ns.currentSite()) + ".disqus.com/embed.js");
|
29
|
+
}
|
30
|
+
return script.appendTo($("head"));
|
31
|
+
};
|
32
|
+
return (ns.setup = function() {
|
33
|
+
return ns.addScripts();
|
34
|
+
});
|
35
|
+
});
|
@@ -0,0 +1,66 @@
|
|
1
|
+
var __bind = function(func, context) {
|
2
|
+
return function(){ return func.apply(context, arguments); };
|
3
|
+
};
|
4
|
+
YouthTree.withNS('Flickr.Gallery', function(ns) {
|
5
|
+
var InnerFlickrGallery, flickr;
|
6
|
+
flickr = YouthTree.Flickr;
|
7
|
+
ns.navigationClass = 'flickr-gallery-navigation';
|
8
|
+
ns.containerClass = 'flickr-gallery';
|
9
|
+
InnerFlickrGallery = function(_arg, _arg2) {
|
10
|
+
this.container = _arg2;
|
11
|
+
this.name = _arg;
|
12
|
+
this.container.addClass(ns.containerClass);
|
13
|
+
return this;
|
14
|
+
};
|
15
|
+
InnerFlickrGallery.prototype.fetchPhotoset = function(photosetId, extraParams) {
|
16
|
+
var params;
|
17
|
+
params = {
|
18
|
+
photoset_id: photosetId,
|
19
|
+
extras: 'url_sq,url_m'
|
20
|
+
};
|
21
|
+
if (typeof extraParams !== "undefined" && extraParams !== null) {
|
22
|
+
$.extend(params, extraParams);
|
23
|
+
}
|
24
|
+
return flickr.apiCall('flickr.photosets.getPhotos', params, __bind(function(response) {
|
25
|
+
return this.process(response.photoset.photo);
|
26
|
+
}, this));
|
27
|
+
};
|
28
|
+
InnerFlickrGallery.prototype.fetchUserTagged = function(user, tag, extraParams) {
|
29
|
+
var params;
|
30
|
+
params = {
|
31
|
+
tags: tag,
|
32
|
+
user_id: user,
|
33
|
+
sort: 'interestingness-desc',
|
34
|
+
content_type: '1',
|
35
|
+
media: 'photos'
|
36
|
+
};
|
37
|
+
if (typeof extraParams !== "undefined" && extraParams !== null) {
|
38
|
+
$.extend(params, extraParams);
|
39
|
+
}
|
40
|
+
return flickr.apiCall('flickr.photos.search', params, __bind(function(response) {
|
41
|
+
return this.process(response.photos.photo);
|
42
|
+
}, this));
|
43
|
+
};
|
44
|
+
InnerFlickrGallery.prototype.process = function(photos) {
|
45
|
+
this.container.empty();
|
46
|
+
$.each(photos, __bind(function(i, item) {
|
47
|
+
var img, link;
|
48
|
+
img = $('<img/>').attr('src', item.url_sq);
|
49
|
+
link = $('<a></a>').attr('href', item.url_m).append(img);
|
50
|
+
return this.container.append(link);
|
51
|
+
}, this));
|
52
|
+
return YouthTree.Gallery.create(this.name, this.container.find('a'));
|
53
|
+
};
|
54
|
+
ns.fromPhotoset = function(name, container, photoset, extraParams) {
|
55
|
+
var flickr_gallery;
|
56
|
+
flickr_gallery = new InnerFlickrGallery(name, container);
|
57
|
+
flickr_gallery.fetchPhotoset(photoset, extraParams);
|
58
|
+
return flickr_gallery;
|
59
|
+
};
|
60
|
+
return (ns.fromUserTag = function(name, container, user, tag, extraParams) {
|
61
|
+
var flickr_gallery;
|
62
|
+
flickr_gallery = new InnerFlickrGallery(name, container);
|
63
|
+
flickr_gallery.fetchUserTagged(user, tag, extraParams);
|
64
|
+
return flickr_gallery;
|
65
|
+
});
|
66
|
+
});
|
@@ -0,0 +1,35 @@
|
|
1
|
+
YouthTree.withNS('Flickr', function(ns) {
|
2
|
+
ns.apiBaseURL = 'http://api.flickr.com/services/rest/';
|
3
|
+
ns.defaultOptions = {
|
4
|
+
format: 'json',
|
5
|
+
api_key: ''
|
6
|
+
};
|
7
|
+
ns.defaultErrorHandler = function(response) {
|
8
|
+
var _ref;
|
9
|
+
return (typeof (_ref = window.console) !== "undefined" && _ref !== null) ? ns.log("Error: " + (response.code) + " - " + (response.message)) : null;
|
10
|
+
};
|
11
|
+
ns.apiCall = function(name, options, callback, errback) {
|
12
|
+
var _ref, apiOptions;
|
13
|
+
if (!(typeof (_ref = ns.apiKey) !== "undefined" && _ref !== null)) {
|
14
|
+
return null;
|
15
|
+
}
|
16
|
+
errback = (typeof errback !== "undefined" && errback !== null) ? errback : ns.defaultErrorHandler;
|
17
|
+
apiOptions = {
|
18
|
+
method: name
|
19
|
+
};
|
20
|
+
$.extend(apiOptions, options, ns.defaultOptions);
|
21
|
+
return $.ajax({
|
22
|
+
url: ns.apiBaseURL,
|
23
|
+
dataType: 'jsonp',
|
24
|
+
jsonp: 'jsoncallback',
|
25
|
+
data: apiOptions,
|
26
|
+
success: function(data) {
|
27
|
+
return data.stat === 'ok' ? callback(data) : errback(data);
|
28
|
+
}
|
29
|
+
});
|
30
|
+
};
|
31
|
+
return (ns.setup = function() {
|
32
|
+
ns.apiKey = $.metaAttr('flickr-api-key');
|
33
|
+
return (ns.defaultOptions.api_key = ns.apiKey);
|
34
|
+
});
|
35
|
+
});
|
@@ -0,0 +1,64 @@
|
|
1
|
+
var __bind = function(func, context) {
|
2
|
+
return function(){ return func.apply(context, arguments); };
|
3
|
+
};
|
4
|
+
YouthTree.withNS('Util', function(ns) {
|
5
|
+
ns.escapeHTML = function(s) {
|
6
|
+
return s.replace(/&/g, '&').replace(/</g, "<").replace(/>/g, ">").replace(/'/g, "'").replace(/"/g, """);
|
7
|
+
};
|
8
|
+
ns.autolink = function(text) {
|
9
|
+
return text.replace(/(\bhttp:\/\/\S+(\/|\b))/gi, '<a href="$1" target="_blank">$1</a>');
|
10
|
+
};
|
11
|
+
ns.format = function(text) {
|
12
|
+
return ns.autolink(ns.escapeHTML(text));
|
13
|
+
};
|
14
|
+
ns.h = ns.escapeHTML;
|
15
|
+
ns.formatTime = function(s) {
|
16
|
+
var hour, minutes, minutesPrefix, period, preiod, time;
|
17
|
+
time = new Date(s);
|
18
|
+
period = "";
|
19
|
+
hour = time.getHours();
|
20
|
+
if (hour === 0) {
|
21
|
+
period = "am";
|
22
|
+
hour = 12;
|
23
|
+
} else if (hour < 12) {
|
24
|
+
period = "am";
|
25
|
+
} else if (hour === 12) {
|
26
|
+
period = "pm";
|
27
|
+
} else if (hour < 24) {
|
28
|
+
preiod = "pm";
|
29
|
+
hour -= 12;
|
30
|
+
}
|
31
|
+
minutes = time.getMinutes();
|
32
|
+
minutesPrefix = minutes < 10 ? "0" : "";
|
33
|
+
return "" + (hour) + ":" + (minutesPrefix) + (minutes) + " " + (period);
|
34
|
+
};
|
35
|
+
ns.attachUpdatingTimeAgo = function(object, date) {
|
36
|
+
var existing, update;
|
37
|
+
existing = $(object).dataAttr("time-ago-interval");
|
38
|
+
if (typeof existing !== "undefined" && existing !== null) {
|
39
|
+
clearInterval(parseInt(existing, 10));
|
40
|
+
}
|
41
|
+
update = __bind(function() {
|
42
|
+
return object.html(ns.timeAgoInWords(date));
|
43
|
+
}, this);
|
44
|
+
update();
|
45
|
+
return $(object).dataAttr("time-ago-interval", setInterval(update, 60000));
|
46
|
+
};
|
47
|
+
ns.truncate = function(text, length) {
|
48
|
+
var suffix;
|
49
|
+
length = (typeof length !== "undefined" && length !== null) ? length : 100;
|
50
|
+
suffix = text.length > length ? "…" : "";
|
51
|
+
return (text = ("" + (ns.h(text.slice(0, length))) + (suffix)));
|
52
|
+
};
|
53
|
+
return (ns.timeAgoInWords = function(date) {
|
54
|
+
var _ref, now, time;
|
55
|
+
if (typeof (_ref = $.browser.ie) !== "undefined" && _ref !== null) {
|
56
|
+
date = Date.parse(date.replace(/( \+)/, " UTC$1"));
|
57
|
+
} else {
|
58
|
+
date = Date.parse(date);
|
59
|
+
}
|
60
|
+
time = Number(new Date(date));
|
61
|
+
now = Number(new Date());
|
62
|
+
return $.timeago.inWords(now - time);
|
63
|
+
});
|
64
|
+
});
|
data/lib/youthtree-js.rb
CHANGED
@@ -1,8 +1,12 @@
|
|
1
1
|
class YouthTreeJS
|
2
|
-
VERSION = "0.
|
2
|
+
VERSION = "0.3.0".freeze
|
3
|
+
|
4
|
+
def self.coffeescripts_root
|
5
|
+
File.expand_path('../coffeescripts', File.dirname(__FILE__))
|
6
|
+
end
|
3
7
|
|
4
8
|
def self.register_framework!
|
5
|
-
Barista::Framework.register 'youthtree',
|
9
|
+
Barista::Framework.register 'youthtree', coffeescripts_root
|
6
10
|
end
|
7
11
|
|
8
12
|
register_framework! if defined? Barista::Framework
|
data/youthtree-js.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{youthtree-js}
|
8
|
-
s.version = "0.
|
8
|
+
s.version = "0.3.0"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Darcy Laycock"]
|
12
|
-
s.date = %q{2010-
|
12
|
+
s.date = %q{2010-11-29}
|
13
13
|
s.description = %q{Shared Javascript tools across YouthTree apps.}
|
14
14
|
s.email = %q{sutto@sutto.net}
|
15
15
|
s.extra_rdoc_files = [
|
@@ -17,16 +17,27 @@ Gem::Specification.new do |s|
|
|
17
17
|
]
|
18
18
|
s.files = [
|
19
19
|
"README.md",
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
20
|
+
"Rakefile",
|
21
|
+
"coffeescripts/youth_tree.coffee",
|
22
|
+
"coffeescripts/youth_tree/ck_editor.coffee",
|
23
|
+
"coffeescripts/youth_tree/convertable_editor.coffee",
|
24
|
+
"coffeescripts/youth_tree/disqus.coffee",
|
25
|
+
"coffeescripts/youth_tree/flickr.coffee",
|
26
|
+
"coffeescripts/youth_tree/flickr/gallery.coffee",
|
27
|
+
"coffeescripts/youth_tree/gallery.coffee",
|
28
|
+
"coffeescripts/youth_tree/util.coffee",
|
29
|
+
"javascripts/youth_tree.js",
|
30
|
+
"javascripts/youth_tree/ck_editor.js",
|
31
|
+
"javascripts/youth_tree/convertable_editor.js",
|
32
|
+
"javascripts/youth_tree/disqus.js",
|
33
|
+
"javascripts/youth_tree/flickr.js",
|
34
|
+
"javascripts/youth_tree/flickr/gallery.js",
|
35
|
+
"javascripts/youth_tree/gallery.js",
|
36
|
+
"javascripts/youth_tree/util.js",
|
37
|
+
"lib/youthtree-js.rb",
|
38
|
+
"youthtree-js.gemspec"
|
27
39
|
]
|
28
40
|
s.homepage = %q{http://github.com/YouthTree/youthtree-js}
|
29
|
-
s.rdoc_options = ["--charset=UTF-8"]
|
30
41
|
s.require_paths = ["lib"]
|
31
42
|
s.rubygems_version = %q{1.3.7}
|
32
43
|
s.summary = %q{Shared Javascript tools across YouthTree apps.}
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: youthtree-js
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 19
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
|
-
-
|
8
|
+
- 3
|
9
9
|
- 0
|
10
|
-
version: 0.
|
10
|
+
version: 0.3.0
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Darcy Laycock
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2010-
|
18
|
+
date: 2010-11-29 00:00:00 +08:00
|
19
19
|
default_executable:
|
20
20
|
dependencies: []
|
21
21
|
|
@@ -31,9 +31,21 @@ files:
|
|
31
31
|
- README.md
|
32
32
|
- Rakefile
|
33
33
|
- coffeescripts/youth_tree.coffee
|
34
|
+
- coffeescripts/youth_tree/ck_editor.coffee
|
35
|
+
- coffeescripts/youth_tree/convertable_editor.coffee
|
36
|
+
- coffeescripts/youth_tree/disqus.coffee
|
37
|
+
- coffeescripts/youth_tree/flickr.coffee
|
38
|
+
- coffeescripts/youth_tree/flickr/gallery.coffee
|
34
39
|
- coffeescripts/youth_tree/gallery.coffee
|
40
|
+
- coffeescripts/youth_tree/util.coffee
|
35
41
|
- javascripts/youth_tree.js
|
42
|
+
- javascripts/youth_tree/ck_editor.js
|
43
|
+
- javascripts/youth_tree/convertable_editor.js
|
44
|
+
- javascripts/youth_tree/disqus.js
|
45
|
+
- javascripts/youth_tree/flickr.js
|
46
|
+
- javascripts/youth_tree/flickr/gallery.js
|
36
47
|
- javascripts/youth_tree/gallery.js
|
48
|
+
- javascripts/youth_tree/util.js
|
37
49
|
- lib/youthtree-js.rb
|
38
50
|
- youthtree-js.gemspec
|
39
51
|
has_rdoc: true
|
@@ -41,8 +53,8 @@ homepage: http://github.com/YouthTree/youthtree-js
|
|
41
53
|
licenses: []
|
42
54
|
|
43
55
|
post_install_message:
|
44
|
-
rdoc_options:
|
45
|
-
|
56
|
+
rdoc_options: []
|
57
|
+
|
46
58
|
require_paths:
|
47
59
|
- lib
|
48
60
|
required_ruby_version: !ruby/object:Gem::Requirement
|