@@ -64,10 +64,45 @@ angular.module('hhUI', ['ui.sortable', 'firebase'])
64
64
return result ;
65
65
}
66
66
67
+ $scope . editing = null ;
68
+
67
69
// Get default mode for new tabs
68
70
settings . syntaxMode = getSyntax ( settings . syntax ) ;
69
71
settings . initialSyntaxMode = getSyntax ( settings . initialSyntax ) ;
70
72
73
+ $scope . hide = function ( key ) {
74
+ $scope . editing = null ;
75
+ $scope . focus ( key )
76
+ }
77
+
78
+ $scope . clicked = function ( event , key ) {
79
+ if ( event . which == 2 )
80
+ return $scope . close ( event , key ) ;
81
+
82
+ if ( key == $scope . tabStatus . focus )
83
+ $scope . editing = key ;
84
+ else
85
+ $scope . focus ( key )
86
+ }
87
+
88
+ $scope . downloadAll = function ( ) {
89
+ angular . forEach ( $scope . tabs , function ( value , key ) {
90
+ var title = ( value . title || "Untitled" ) + '' + value . syntax . ext
91
+ var content = window . aces [ value . id ] . getSession ( ) . getValue ( ) ;
92
+ $scope . download ( title , content )
93
+ } ) ;
94
+ }
95
+
96
+
97
+ $scope . download = function ( filename , text ) {
98
+ var pom = document . createElement ( 'a' ) ;
99
+ pom . setAttribute ( 'href' , 'data:text/plain;charset=utf-8,' + encodeURIComponent ( text ) ) ;
100
+ pom . setAttribute ( 'download' , filename ) ;
101
+ document . body . appendChild ( pom )
102
+ pom . click ( ) ;
103
+ document . body . removeChild ( pom )
104
+ }
105
+
71
106
72
107
$scope . syntax = function ( key , syntax ) {
73
108
var currentItem = $scope . tabs [ key ] ;
@@ -120,19 +155,19 @@ angular.module('hhUI', ['ui.sortable', 'firebase'])
120
155
} ) ;
121
156
}
122
157
123
-
124
-
125
158
// Initialize firebase connection
126
159
var ref = new Firebase ( $scope . settings . firebase )
127
160
$scope . tabStatus = $firebase ( ref . child ( 'status' ) ) . $asObject ( ) ;
128
161
$scope . tabs = $firebase ( ref . child ( 'tabs' ) ) . $asArray ( ) ;
129
162
163
+ //var xxx = $firebase(ref.child('tabs')).$asObject();
164
+ $firebase ( ref . child ( 'tabs' ) ) . $asObject ( ) . $bindTo ( $scope , "tabsData" ) ;
165
+
130
166
$scope . tabs . $loaded ( function ( ) {
131
167
if ( $scope . tabs . length == 0 )
132
168
$scope . add ( settings . initialSyntaxMode , settings . initialText ) ;
133
169
} ) ;
134
170
135
-
136
171
$scope . sortableOptions = {
137
172
containment : '#sortable-container' ,
138
173
//restrict move across columns. move only within column.
@@ -152,13 +187,12 @@ angular.module('hhUI', ['ui.sortable', 'firebase'])
152
187
153
188
$scope . focus ( diff . dest . index )
154
189
}
155
- } ;
190
+ }
156
191
157
192
} ]
158
193
}
159
194
} ] )
160
195
161
-
162
196
. directive ( 'hhFirepad' , [ function ( ) {
163
197
164
198
return {
@@ -207,4 +241,35 @@ angular.module('hhUI', ['ui.sortable', 'firebase'])
207
241
}
208
242
}
209
243
210
- } ] )
244
+ } ] )
245
+
246
+ . directive ( 'showFocus' , function ( $timeout ) {
247
+ return function ( scope , element , attrs ) {
248
+ scope . $watch ( attrs . showFocus ,
249
+ function ( newValue ) {
250
+ $timeout ( function ( ) {
251
+ newValue && element [ 0 ] . focus ( ) ;
252
+ } ) ;
253
+ } , true ) ;
254
+ } ;
255
+ } )
256
+
257
+ . directive ( 'ngEnter' , function ( ) {
258
+ return function ( scope , element , attrs ) {
259
+ element . bind ( "keydown keypress" , function ( event ) {
260
+ if ( event . which === 13 ) {
261
+ scope . $apply ( function ( ) {
262
+ scope . $eval ( attrs . ngEnter ) ;
263
+ } ) ;
264
+
265
+ event . preventDefault ( ) ;
266
+ }
267
+ } ) ;
268
+ } ;
269
+ } )
270
+
271
+ . filter ( 'titleDefault' , function ( ) {
272
+ return function ( input ) {
273
+ return input ? input : 'Untitled' ;
274
+ } ;
275
+ } )
0 commit comments