@@ -16,18 +16,22 @@ firetext.user = {};
1616firetext . parsers = { } ;
1717firetext . analytics = { } ;
1818
19+ // Config
20+ var version = '0.5' ;
21+ var serverURL = 'https://firetext-server.herokuapp.com' ;
22+
1923// Misc
2024firetext . initialized = new CustomEvent ( 'firetext.initialized' ) ;
2125firetext . isInitialized = false ;
2226var html = document . getElementsByTagName ( 'html' ) [ 0 ] , head = document . getElementsByTagName ( "head" ) [ 0 ] ;
2327var themeColor = document . getElementById ( "theme-color" ) ;
2428var loadSpinner , editor , toolbar , editWindow , editState , rawEditor , rawEditorElement , tempText , tabRaw , tabDesign , printButton , mainButtonConnectDropbox ;
2529var currentFileName , currentFileType , currentFileLocation , currentFileDirectory ;
26- var deviceType , fileChanged , saveTimeout , saving , urls = { } , version = '0.5' ;
30+ var deviceType , fileChanged , saveTimeout , saving , firetextVariables = { } , firetextVariablesInitialized = false ;
2731var bold , fontSelect , fontSizeSelect , italic , justifySelect , strikethrough , styleSelect ;
2832var underline , underlineCheckbox ;
2933var locationLegend , locationSelect , locationDevice , locationDropbox ;
30- var bugsenseInitialized = false , bugsenseKey = '' ;
34+ var bugsenseInitialized = false ;
3135var rate ;
3236var editorMessageProxy , editorURL ;
3337
@@ -113,17 +117,14 @@ firetext.init = function () {
113117 } ) ;
114118} ;
115119
116- function initModules ( callback ) {
117- // Initialize Bugsense
118- bugsenseInit ( ) ;
119-
120- // Fix menu before url request
121- fixMenu ( true ) ;
122-
120+ function initModules ( callback ) {
123121 // Initialize urls
124- initURLs ( function ( ) {
125- // Modify links in menu
126- fixMenu ( ) ;
122+ initVariables ( function ( ) {
123+ // Initialize Bugsense
124+ bugsenseInit ( ) ;
125+
126+ // Add extra links to menu
127+ addURLs ( ) ;
127128
128129 // Initialize cloud services
129130 cloud . init ( ) ;
@@ -334,70 +335,92 @@ function initListeners() {
334335 ) ;
335336}
336337
337- function initURLs ( callback ) {
338+ function initVariables ( callback ) {
338339 var xhr = new XMLHttpRequest ( ) ;
339- xhr . open ( 'post' , 'http://firetext.codexa.bugs3.com/' , true ) ;
340+ xhr . open ( 'post' , serverURL , true ) ;
340341 xhr . setRequestHeader ( "Content-type" , "application/x-www-form-urlencoded" ) ;
341342 xhr . onreadystatechange = function ( ) {
342343 if ( xhr . readyState == 4 && xhr . status == 200 ) {
343- urls = JSON . parse ( xhr . responseText ) ;
344+ firetextVariables = JSON . parse ( xhr . responseText ) ;
345+ firetextVariablesInitialized = true ;
346+ callback ( ) ;
344347 }
345348 }
346- xhr . addEventListener ( "loadend" , function ( ) {
347- callback ( ) ;
348- } ) ;
349- xhr . send ( 'request=urls&version=' + version ) ;
349+ xhr . send ( 'request=firetext_variables&version=' + version + '&locale=' + html . getAttribute ( 'lang' ) ) ;
350350}
351351
352- function fixMenu ( soft ) {
353- var tempElements = [ ] , tempLinks = [ ] ;
354- var urlNames = [ 'about' , 'support' , 'credits' , 'rate' ] ;
355-
356- // Find empty urls
357- urlNames . forEach ( function ( v ) {
358- if ( ! urls [ v ] ) {
359- tempElements = addMenuElementsToArray ( tempElements , document . querySelectorAll ( '[data-type="sidebar"] nav [data-click-location="' + v + '"]' ) ) ;
352+ function addURLs ( ) {
353+ // Create url array
354+ var urls = { } ;
355+ for ( var category in firetextVariables . urlCategories ) {
356+ urls [ firetextVariables . urlCategories [ category ] . id ] = {
357+ "name" : firetextVariables . urlCategories [ category ] . name ,
358+ "items" : { }
359+ } ;
360+ }
361+ urls [ "other" ] = {
362+ "name" : "Other" ,
363+ "items" : { }
364+ } ;
365+ for ( var url in firetextVariables . urls ) {
366+ var currentUrl = firetextVariables . urls [ url ] ;
367+ var category = urls [ currentUrl . category ] ? currentUrl . category : "other" ;
368+ urls [ category ] [ "items" ] [ url ] = {
369+ "name" : currentUrl . name ,
370+ "id" : currentUrl . id ,
371+ "url" : currentUrl . url
372+ } ;
373+ }
374+
375+ // Get url menus and clear old urls
376+ var urlMenus = document . getElementsByClassName ( "url-menu" ) ;
377+ var tempOldUrls = document . getElementsByClassName ( "remote-url" ) ;
378+ while ( tempOldUrls [ 0 ] ) tempOldUrls [ 0 ] . parentNode . removeChild ( tempOldUrls [ 0 ] ) ;
379+
380+ // Create DOM elements
381+ for ( var urlCategory in urls ) {
382+ var tempCategoryTitle = document . createElement ( "h2" ) ;
383+ tempCategoryTitle . classList . add ( "remote-url" ) ;
384+ if ( navigator . mozL10n . get ( urlCategory ) != "" ) {
385+ tempCategoryTitle . setAttribute ( "data-l10n-id" , urlCategory ) ;
386+ tempCategoryTitle . textContent = navigator . mozL10n . get ( urlCategory ) ;
360387 } else {
361- tempLinks = addMenuElementsToArray ( tempLinks , document . querySelectorAll ( '[data-type="sidebar"] nav [data-click-location="' + v + '"]' ) ) ;
362- for ( var i = 0 ; i < tempLinks . length ; i ++ ) {
363- tempLinks [ i ] . parentNode . classList . remove ( 'hidden-item' ) ;
364- }
388+ tempCategoryTitle . textContent = urls [ urlCategory ] . name ;
365389 }
366- } ) ;
367-
368- if ( soft === true ) {
369- for ( var i = 0 ; i < tempElements . length ; i ++ ) {
370- tempElements [ i ] . parentNode . classList . add ( 'hidden-item' ) ;
371- }
372- } else {
373- // Remove list items
374- for ( var i = 0 ; i < tempElements . length ; i ++ ) {
375- var tempParent = tempElements [ i ] . parentNode . parentNode ;
376- if ( tempParent ) {
377- tempParent . removeChild ( tempElements [ i ] . parentNode ) ;
378- }
379- }
380-
381- // Remove empty lists
382- var tempLists = document . querySelectorAll ( '[data-type="sidebar"] nav ul' ) ;
383- for ( var i = 0 ; i < tempLists . length ; i ++ ) {
384- if ( tempLists [ i ] . childElementCount == 0 ) {
385- if ( tempLists [ i ] . previousElementSibling ) {
386- tempLists [ i ] . parentNode . removeChild ( tempLists [ i ] . previousElementSibling ) ;
387- }
388- tempLists [ i ] . parentNode . removeChild ( tempLists [ i ] ) ;
390+
391+ var tempLinkContainer = document . createElement ( "ul" ) ;
392+ tempLinkContainer . classList . add ( "remote-url" ) ;
393+ for ( var thisUrl in urls [ urlCategory ] . items ) {
394+ // Generate link elements
395+ var thisUrlItem = urls [ urlCategory ] . items [ thisUrl ] ;
396+ var tempListItem = document . createElement ( "li" ) ;
397+ var tempLink = document . createElement ( "a" ) ;
398+ tempLink . href = "#" ;
399+ tempLink . setAttribute ( "data-click" , "browser" ) ;
400+ tempLink . setAttribute ( "data-click-location" , thisUrlItem . url ) ;
401+ tempLink . setAttribute ( "data-url-id" , thisUrlItem . id ) ;
402+ if ( navigator . mozL10n . get ( thisUrlItem . id ) != "" ) {
403+ tempLink . setAttribute ( "data-l10n-id" , thisUrlItem . id ) ;
404+ tempLink . textContent = navigator . mozL10n . get ( thisUrlItem . id ) ;
405+ } else {
406+ tempLink . textContent = thisUrlItem . name ;
389407 }
408+
409+ // Add link to list item
410+ tempListItem . appendChild ( tempLink ) ;
411+
412+ // Add to category container
413+ tempLinkContainer . appendChild ( tempListItem ) ;
390414 }
415+
416+ // Add category to url menus
417+ Array . prototype . filter . call ( urlMenus , function ( menu ) {
418+ menu . appendChild ( tempCategoryTitle . cloneNode ( true ) ) ;
419+ menu . appendChild ( tempLinkContainer . cloneNode ( true ) ) ;
420+ } ) ;
391421 }
392422}
393423
394- function addMenuElementsToArray ( array , elements ) {
395- for ( var i = 0 ; i < elements . length ; i ++ ) {
396- array . push ( elements [ i ] ) ;
397- }
398- return array ;
399- }
400-
401424
402425/* Add dialog
403426------------------------*/
@@ -450,10 +473,10 @@ function updateAddDialog() {
450473/* Bugsense
451474------------------------*/
452475function bugsenseInit ( ) {
453- if ( bugsenseKey ) {
476+ if ( firetextVariablesInitialized && firetextVariables . services . splunk . apiKey ) {
454477 if ( firetext . settings . get ( 'stats.enabled' ) != 'false' &&
455478 ! bugsenseInitialized ) {
456- Bugsense . initAndStartSession ( { appname : 'Firetext' , appVersion : version , apiKey : bugsenseKey } ) ;
479+ Bugsense . initAndStartSession ( { appname : 'Firetext' , appVersion : version , apiKey : firetextVariables . services . splunk . apiKey } ) ;
457480 bugsenseInitialized = true ;
458481 }
459482 }
@@ -1352,28 +1375,19 @@ function processActions(eventAttribute, target, event) {
13521375 } else {
13531376 editFullScreen ( ) ;
13541377 }
1355- } else if ( calledFunction == 'browser' ) {
1356- // Get location
1357- var browseLocation = '' ;
1358- if ( target . getAttribute ( eventAttribute + '-location' ) == 'about' ) {
1359- browseLocation = urls . about ;
1360- } else if ( target . getAttribute ( eventAttribute + '-location' ) == 'credits' ) {
1361- browseLocation = urls . credits ;
1362- } else if ( target . getAttribute ( eventAttribute + '-location' ) == 'rate' ) {
1363- // Launch rate activity if available
1378+ } else if ( calledFunction == 'browser' ) {
1379+ // Launch rate activity if available
1380+ if ( target . getAttribute ( "data-url-id" ) == 'rate-firetext' ) {
13641381 if ( window . MozActivity ) {
13651382 var activity = new MozActivity ( {
13661383 name : "marketplace-app-rating" ,
13671384 data : { slug : "firetext" }
13681385 } ) ;
13691386 return ;
13701387 }
1371- browseLocation = urls . rate ;
1372- } else if ( target . getAttribute ( eventAttribute + '-location' ) == 'support' ) {
1373- browseLocation = urls . support ;
1374- } else {
1375- browseLocation = target . getAttribute ( eventAttribute + '-location' ) ;
13761388 }
1389+
1390+ var browseLocation = target . getAttribute ( eventAttribute + '-location' ) ;
13771391
13781392 // Fix for empty locations
13791393 if ( ! browseLocation || browseLocation == '' ) {
0 commit comments