You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ponymail.apache.org by hu...@apache.org on 2016/09/02 07:44:18 UTC
[16/17] incubator-ponymail git commit: make sure comments make it to
JS
make sure comments make it to JS
Project: http://git-wip-us.apache.org/repos/asf/incubator-ponymail/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-ponymail/commit/22b3b8a0
Tree: http://git-wip-us.apache.org/repos/asf/incubator-ponymail/tree/22b3b8a0
Diff: http://git-wip-us.apache.org/repos/asf/incubator-ponymail/diff/22b3b8a0
Branch: refs/heads/coffee-and-cake
Commit: 22b3b8a0e662279a2db97db013eb68383d96f2d5
Parents: 4b68337
Author: Daniel Gruno <hu...@apache.org>
Authored: Fri Sep 2 09:30:49 2016 +0200
Committer: Daniel Gruno <hu...@apache.org>
Committed: Fri Sep 2 09:30:49 2016 +0200
----------------------------------------------------------------------
site/js/coffee/dom_utils.coffee | 40 ++++++++++++++------------
site/js/coffee/http_utils.coffee | 50 ++++++++++++++++-----------------
site/js/coffee/localstorage.coffee | 14 +++++----
site/js/coffee/misc.coffee | 7 ++++-
4 files changed, 62 insertions(+), 49 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-ponymail/blob/22b3b8a0/site/js/coffee/dom_utils.coffee
----------------------------------------------------------------------
diff --git a/site/js/coffee/dom_utils.coffee b/site/js/coffee/dom_utils.coffee
index 66dbe06..afd291e 100644
--- a/site/js/coffee/dom_utils.coffee
+++ b/site/js/coffee/dom_utils.coffee
@@ -19,17 +19,19 @@
# This is dom_utils.coffee: DOM handling utilities #
####################################################
+###*
# mk: DOM creator
# args:
# - type: HTML element type (div, table, p etc) to produce
# - params: hash of element params to add (class, style etc)
# - children: optional child or children objects to insert into the new element
# Example: mk('div', { class: "footer", style: {fontWeight: "bold"}}, "Some text inside a div")
+###
mk = (type, params, children) ->
- # create the raw element
+ ### create the raw element ###
r = document.createElement(type)
- # If params have been passed, set them
+ ### If params have been passed, set them ###
if params
for k, v of params
# Standard string value?
@@ -43,62 +45,64 @@ mk = (type, params, children) ->
for x,y of v
r[k][x] = y
- # If any children have been passed, add them to the element
+ ### If any children have been passed, add them to the element ###
if children
- # If string, convert to textNode using txt()
+ ### If string, convert to textNode using txt() ###
if typeof children is "string"
app(r, txt(children))
else
- # If children is an array of elems, iterate and add
+ ### If children is an array of elems, iterate and add ###
if isArray children
for k in children
- # String? Convert via txt() then
+ ### String? Convert via txt() then ###
if typeof k is "string"
app(r, txt(k))
- # Plain element, add normally
+ ### Plain element, add normally ###
else
app(r, k)
- # Just a single element, add it
+ ### Just a single element, add it ###
else
app(r, children)
return r
+###*
# App: Shortcut for document.appendChild with modifications
# - a: the element to add things to
# - b: one or more elements to add.
# Example: app(get('mydiv'), "Add some text to mydiv")
+###
app = (a,b) ->
- # If it's a list of elems, iterate
+ ### If it's a list of elems, iterate ###
if isArray b
for item in b
- # String? Convert to textNode first then
+ ### String? Convert to textNode first then ###
if typeof item is "string"
item = txt(item)
- # Otherwise just add it
+ ### Otherwise just add it ###
a.appendChild(item)
- # Otherwise, just add
+ ### Otherwise, just add ###
else
- # String? Convert first
+ ### String? Convert first ###
if typeof b is "string"
a.appendChild(txt(b))
- # Not a string, add normally
+ ### Not a string, add normally ###
return a.appendChild(b)
-# Set: shortcut for a.setAttribute(b,c)
+### Set: shortcut for a.setAttribute(b,c) ###
set = (a, b, c) ->
return a.setAttribute(b,c)
-# txt: shortcut for creating a text node
+### txt: shortcut for creating a text node ###
txt = (a) ->
return document.createTextNode(a)
-# Get: Shortcut for doc.getElementById
+### Get: Shortcut for doc.getElementById ###
get = (a) ->
return document.getElementById(a)
-# Cog: Loading panel for when waiting for a response
+### Cog: Loading panel for when waiting for a response ###
cog = (div, size = 200) ->
idiv = mk('div', { class: "icon", style: {
texAlign: 'center',
http://git-wip-us.apache.org/repos/asf/incubator-ponymail/blob/22b3b8a0/site/js/coffee/http_utils.coffee
----------------------------------------------------------------------
diff --git a/site/js/coffee/http_utils.coffee b/site/js/coffee/http_utils.coffee
index 91de289..4b5675e 100644
--- a/site/js/coffee/http_utils.coffee
+++ b/site/js/coffee/http_utils.coffee
@@ -47,7 +47,7 @@
class HTTPRequest
constructor: (@url, @args) ->
- # Set internal class data, determine request type
+ ### Set internal class data, determine request type ###
@state = @args.state
@method = if @args.data then 'POST' else 'GET'
@data = @args.data
@@ -57,17 +57,17 @@ class HTTPRequest
@snap = @args.snap || pm_snap
@nocreds = @args.nocreds || false
- # Construct request object
+ ### Construct request object ###
if window.XMLHttpRequest
@request = new XMLHttpRequest();
else
@request = new ActiveXObject("Microsoft.XMLHTTP");
- # Default to sending credentials
+ ### Default to sending credentials ###
if not @nocreds
@request.withCredentials = true
- # Determine what to send as data (if anything)
+ ### Determine what to send as data (if anything) ###
@rdata = null
if @method is 'POST'
if @datatype == 'json'
@@ -75,61 +75,61 @@ class HTTPRequest
else
@rdata = @formdata(@data)
- # If tasked with appending data to the URL, do so
+ ### If tasked with appending data to the URL, do so ###
if @getdata
tmp = @formdata(@getdata)
if tmp.length > 0
- # Do we have form data here aleady? if so, append the new
- # by adding an ampersand first
+ ### Do we have form data here aleady? if so, append the new ###
+ ### by adding an ampersand first ###
if @url.match(/\?/)
@url += "&" + tmp
- # No form data yet, add a ? and then the data
+ ### No form data yet, add a ? and then the data ###
else
@url += "?" + tmp
- # Use @method on URL
+ ### Use @method on URL ###
@request.open(@method, @url, true)
- # Send data
+ ### Send data ###
@request.send(@rdata)
- # Set onChange behavior
+ ### Set onChange behavior ###
@request.onreadystatechange = @onchange
- # all done!
+ ### all done! ###
return this
- # HTTPRequest state change calback
+ ### HTTPRequest state change calback ###
onchange: () ->
- # Internal Server Error: Try to call snap
+ ### Internal Server Error: Try to call snap ###
if @request.readyState == 4 and @request.status == 500
if @snap
@snap(@state)
- # 200 OK, everything is okay, try to parse JSON response
+ ### 200 OK, everything is okay, try to parse JSON response ###
if @request.readyState == 4 and @request.status == 200
if @callback
- # Try to parse as JSON and deal with cache objects, fall back to old style parse-and-pass
+ ### Try to parse as JSON and deal with cache objects, fall back to old style parse-and-pass ###
try
- # Parse JSON response
+ ### Parse JSON response ###
@response = JSON.parse(@request.responseText)
- # If loginRequired (rare!), redirect to oauth page
+ ### If loginRequired (rare!), redirect to oauth page ###
if @response && @response.loginRequired
location.href = "/oauth.html"
return
- # Otherwise, call the callback function
+ ### Otherwise, call the callback function ###
@callback(@response, @state);
- # JSON parse failed? Pass on the response as plain text then
+ ### JSON parse failed? Pass on the response as plain text then ###
catch e
@callback(@request.responseText, @state)
- # Standard form data joiner for POST data
+ ### Standard form data joiner for POST data ###
formdata: (kv) ->
ar = []
- # For each key/value pair
+ ### For each key/value pair ###
for k,v of kv
- # Only append if the value is non-empty
+ ### Only append if the value is non-empty ###
if v and v != ""
- # URI-Encode value and add to an array
+ ### URI-Encode value and add to an array ###
ar.push(k + "=" + encodeURIComponent(v))
- # Join the array with ampersands, so we get "foo=bar&foo2=baz"
+ ### Join the array with ampersands, so we get "foo=bar&foo2=baz" ###
return ar.join("&")
http://git-wip-us.apache.org/repos/asf/incubator-ponymail/blob/22b3b8a0/site/js/coffee/localstorage.coffee
----------------------------------------------------------------------
diff --git a/site/js/coffee/localstorage.coffee b/site/js/coffee/localstorage.coffee
index 874944e..bcd9128 100644
--- a/site/js/coffee/localstorage.coffee
+++ b/site/js/coffee/localstorage.coffee
@@ -15,8 +15,10 @@
limitations under the License.
###
+###*
# Init: Test if localStorage is available or not
# If not, fall back to plain global var storage (not effective, but meh)
+###
pm_storage_available = false
pm_storage_globvar = {}
try
@@ -27,23 +29,25 @@ catch e
pm_storage_available = false
+###*
# dbWrite: Store a key/val pair
# Example: dbWrite("ponies", "They are awesome!")
+###
dbWrite = (key, value) ->
- # Can we use localStorage?
+ ### Can we use localStorage? ###
if pm_storage_available
return window.localStorage.setItem(key, value)
- # Guess not, fall back to (ineffective) global var
+ ### Guess not, fall back to (ineffective) global var ###
else
pm_storage_globvar[key] = value
return true
-# dbRead: Given a key, read the corresponding value from storage
+### dbRead: Given a key, read the corresponding value from storage ###
dbRead = (key) ->
- # Do we have localStorage?
+ ### Do we have localStorage? ###
if pm_storage_available
return window.localStorage.getItem(key)
- # Nope, try global var
+ ### Nope, try global var ###
else
return pm_storage_globvar[key]
http://git-wip-us.apache.org/repos/asf/incubator-ponymail/blob/22b3b8a0/site/js/coffee/misc.coffee
----------------------------------------------------------------------
diff --git a/site/js/coffee/misc.coffee b/site/js/coffee/misc.coffee
index 6d187dd..8a6e5af 100644
--- a/site/js/coffee/misc.coffee
+++ b/site/js/coffee/misc.coffee
@@ -20,23 +20,28 @@
# This is misc.coffee: Miscellaneous utility functions #
########################################################
+###*
# Number prettification prototype:
# Converts 1234567 into 1,234,567 etc
+###
Number.prototype.pretty = (fix) ->
if (fix)
return String(this.toFixed(fix)).replace(/(\d)(?=(\d{3})+\.)/g, '$1,');
return String(this.toFixed(0)).replace(/(\d)(?=(\d{3})+$)/g, '$1,');
+###*
# Number padding
# usage: 123.pad(6) -> 000123
+###
Number.prototype.pad = (n) ->
str = String(this)
+ ### Do we need to pad? if so, do it using String.repeat ###
if str.length < n
str = "0".repeat(n-str.length) + str
return str
-# isArray: function to detect if an object is an array
+### isArray: function to detect if an object is an array ###
isArray = ( value ) ->
value and
typeof value is 'object' and