digital_opera 0.0.8 → 0.0.9

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ //= require ./digital_opera_namespace
2
+ //= require ./ellipsis
3
+ //= require ./events
4
+ //= require ./forms
5
+ //= require ./preload_images
6
+ //= require ./strings
7
+ //= require ./tables
@@ -0,0 +1 @@
1
+ window.digitalOpera = window.digitalOpera || {}
@@ -0,0 +1,28 @@
1
+ #= require jquery
2
+ #
3
+ # Animate an ellipsis witin elements with the attribute 'data-does="animate-ellipsis"'
4
+ # Frame 1 .
5
+ # Frame 2 ..
6
+ # Frame 3 ...
7
+ # Frame 4 .
8
+ # Etc..
9
+ ((d) ->
10
+ d.ellipsis = (el) ->
11
+ ele = $(el)
12
+ counter = 0
13
+ timer = setInterval () ->
14
+ counter++
15
+ counter = 0 if counter > 3
16
+ num = 0
17
+ arr = []
18
+ while num < counter
19
+ num++
20
+ arr.push '.'
21
+
22
+ ele.text arr.join('')
23
+ , 750
24
+
25
+ )(window.digitalOpera)
26
+
27
+ $('[data-does="animate-ellipsis"]').each (idx, ele) ->
28
+ window.digitalOpera(ele)
@@ -0,0 +1,16 @@
1
+ #= require jquery
2
+ #= require digital_opera/digital_opera_namespace
3
+
4
+ # @method isClickOutsideElement
5
+ # event [Event]
6
+ # element [DOM Element]
7
+ # Determines whether or not a click is outside of the element passed in
8
+ ((d) ->
9
+ d.isClickOutsideElement = (event, element) ->
10
+ target = $ event.target
11
+
12
+ if target[0] == element[0] || element.children(target).length > 0
13
+ return false
14
+ else
15
+ return true
16
+ )(window.digitalOpera)
@@ -0,0 +1,45 @@
1
+ #= require jquery
2
+ #= require digital_opera/digital_opera_namespace
3
+
4
+ ((d) ->
5
+ # @method parameterizeObject
6
+ # data [Object]
7
+ # Generate correctly formatted parameters for xhr2
8
+ #
9
+ # {
10
+ # id: 1234567890,
11
+ # person: {
12
+ # first_name: 'Grant',
13
+ # last_name : 'Klinsing',
14
+ # meta : {
15
+ # foo: 'bar',
16
+ # test: [100, 200]
17
+ # }
18
+ # }
19
+ # }
20
+ #
21
+ # Will become:
22
+ #
23
+ # id = 1234567890
24
+ # person[first_name] = 'Grant'
25
+ # person[last_name] = 'Klinsing'
26
+ # person[meta][foo] = 'bar'
27
+ # person[meta][test] = [100, 200]
28
+ d.parameterizeObject = (data) ->
29
+ obj = {}
30
+
31
+ accLoop = (key, val) ->
32
+ if $.isPlainObject val
33
+ for k, v of val
34
+ k = "#{key}[#{k}]"
35
+ accLoop(k, v)
36
+ else
37
+ obj[key] = val
38
+ return
39
+
40
+ for key, val of data
41
+ accLoop(key, val)
42
+
43
+ obj
44
+
45
+ )(window.digitalOpera)
@@ -0,0 +1,25 @@
1
+ #= require digital_opera/digital_opera_namespace
2
+
3
+ ((d) ->
4
+ # @method preloadImages
5
+ # urls [String, Array]
6
+ # callback [Function]
7
+ # callback fired when all images have loaded
8
+ d.preloadImages = (urls, callback) ->
9
+ urls = [urls] if typeof urls == 'string'
10
+ images = []
11
+ numLoaded = 0
12
+ increment = ->
13
+ numLoaded++
14
+ if callback? && numLoaded == urls.length
15
+ callback()
16
+ urls.map (url, i) ->
17
+ img = images[i]
18
+ img = new Image()
19
+ # we want to increment on each of these events
20
+ img.onload = increment
21
+ img.onerror = increment
22
+ img.src = url
23
+ img
24
+
25
+ )(window.digitalOpera)
@@ -0,0 +1,40 @@
1
+ #= require jquery
2
+ #= require digital_opera/digital_opera_namespace
3
+
4
+ ((d) ->
5
+ d.capitalize = (str) ->
6
+ str.charAt(0).toUpperCase() + str.slice(1)
7
+
8
+ # @method titleize
9
+ # str [String]
10
+ # Titleize a string
11
+ d.titleize = (str) ->
12
+ arr = str.split(' ')
13
+ newString = ''
14
+ for string in arr
15
+ arr[_i] = string.charAt(0).toUpperCase() + string.slice(1).toLowerCase()
16
+ arr.join(' ')
17
+
18
+ # @method formatJSONErrors
19
+ # str [String, Object]
20
+ # withKeys [Boolean]
21
+ # Takes a JSON object and convert it to a readable sentence
22
+ #
23
+ # Example:
24
+ # {email: ["must be at least 6 characters","must contain a number and a letter"]}
25
+ # will be translated to:
26
+ # ["email must be at least 6 characters and must contain a number and a letter"]
27
+ d.formatJSONErrors = (str, withKeys) ->
28
+ errors = if typeof str == 'string' then JSON.parse(str) else str
29
+ $.map errors, (val, key) ->
30
+ values = val.join(' and ')
31
+ str = d.capitalize "#{key} #{values}"
32
+
33
+ if withKeys?
34
+ obj = {}
35
+ obj[key] = str
36
+ obj
37
+ else
38
+ str
39
+
40
+ )(window.digitalOpera)
@@ -0,0 +1,28 @@
1
+ #= require jquery
2
+ #= require digital_opera/digital_opera_namespace
3
+
4
+ ((d) ->
5
+ $(document).on 'click', 'tr[data-href]', (e) ->
6
+ target = $(e.target)
7
+ currentTarget = $(e.currentTarget)
8
+
9
+ if target.is('a') == false && target.parents('a').length == 0 # check to make sure click isn't within a link
10
+ href = currentTarget.attr('data-href')
11
+ if currentTarget.attr('data-does') == 'open-window'
12
+ win = window.open(href, '_blank')
13
+ win.focus()
14
+ else
15
+ location = d.forTestingPurposes.getWindowLocation()
16
+ location = href
17
+
18
+ # this really sucks, but in order to test everything, we need to mock
19
+ # window.location since it can NOT be spied on. #lame
20
+ d.forTestingPurposes = (->
21
+ getWindowLocation = ->
22
+ return window.location;
23
+
24
+ return {
25
+ getWindowLocation: getWindowLocation
26
+ }
27
+ )();
28
+ )(window.digitalOpera)
@@ -1,3 +1,3 @@
1
1
  module DigitalOpera
2
- VERSION = "0.0.8"
2
+ VERSION = "0.0.9"
3
3
  end
@@ -0,0 +1,62 @@
1
+ <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
2
+ "http://www.w3.org/TR/html4/loose.dtd">
3
+ <html>
4
+ <head>
5
+ <title>Jasmine Spec Runner</title>
6
+
7
+ <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
8
+ <link rel="shortcut icon" type="image/png" href="lib/jasmine-1.3.1/jasmine_favicon.png">
9
+ <link rel="stylesheet" type="text/css" href="lib/jasmine-1.3.1/jasmine.css">
10
+ <script type="text/javascript" src="lib/jasmine-1.3.1/jasmine.js"></script>
11
+ <script type="text/javascript" src="lib/jasmine-1.3.1/jasmine-html.js"></script>
12
+
13
+ <!-- include source files here... -->
14
+ <script type="text/javascript" src="src/digital_opera.js"></script>
15
+
16
+ <!-- include spec files here... -->
17
+ <script type="text/javascript" src="spec/SpecHelper.js"></script>
18
+
19
+ <!--[specFiles]-->
20
+ <script type="text/javascript" src="spec/digital_opera_namespace_spec.js"></script>
21
+ <script type="text/javascript" src="spec/ellipsis_spec.js"></script>
22
+ <script type="text/javascript" src="spec/events_spec.js"></script>
23
+ <script type="text/javascript" src="spec/forms_spec.js"></script>
24
+ <script type="text/javascript" src="spec/preload_images_spec.js"></script>
25
+ <script type="text/javascript" src="spec/strings_spec.js"></script>
26
+ <script type="text/javascript" src="spec/tables_spec.js"></script>
27
+ <!--[/specFiles]-->
28
+
29
+ <script type="text/javascript">
30
+ (function() {
31
+ var jasmineEnv = jasmine.getEnv();
32
+ jasmineEnv.updateInterval = 1000;
33
+
34
+ var htmlReporter = new jasmine.HtmlReporter();
35
+
36
+ jasmineEnv.addReporter(htmlReporter);
37
+
38
+ jasmineEnv.specFilter = function(spec) {
39
+ return htmlReporter.specFilter(spec);
40
+ };
41
+
42
+ var currentWindowOnload = window.onload;
43
+
44
+ window.onload = function() {
45
+ if (currentWindowOnload) {
46
+ currentWindowOnload();
47
+ }
48
+ execJasmine();
49
+ };
50
+
51
+ function execJasmine() {
52
+ jasmineEnv.execute();
53
+ }
54
+
55
+ })();
56
+ </script>
57
+
58
+ </head>
59
+
60
+ <body>
61
+ </body>
62
+ </html>
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2008-2011 Pivotal Labs
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.