Javascript library methods

The library has a number of methods that can be used.

Getting values

getLanguage()
‌Returns the currently selected language, in lowercase. Output can be null or a string.
‌E.g. "en-gb"

getLoadedLanguagesList() ‌
‌Returns all currently loaded translation languages as an array of strings. This can, for example, be useful if you want to offer a way for people to switch between languages on the fly using a dropdown. 
‌E.g. ["en-gb","nl","de"]

getLoadedLanguagesData()
‌This returns the complete languages object. This includes the special 'code' language which is used internally as a look-up table to generate shortcodes, so you may want to filter that out.
‌E.g. main_label.getLoadedLanguagesData()

getLabelData()
‌Returns the currently set label data as an object.
‌‌E.g. main_label.getLabelData()

getShortCode()
‌Returns the shortcode for the label. This includes all the settings. On top of this the title, description and the information in the action segment of the label are provided as well (using base64 encoding).
‌E.g. en-gb2YABCRAOB3D4ABCD5PUIA6STP7PAVG211122Z-TRGVtbyBsYWJlbA==-

getShorterCode()
‌This returns the shortcode, but without the title, description and data from the action section.
‌E.g. en-gb2YABOAB3F4ABCD5PMASF6TSL7PS211105Z

Setting values

The methods below won't actually generate a new label. If you want the HTML to be updated you will need to follow the command with a second command to generate().

setTarget( id )
‌Set the name of the element into which the generated label HTML will be placed. This can be the ID of a single element, or a classname. It will try to detect the string as an ID first, and if that can't be found, it will search for elements of that class. By default this is already set to 'privacylabel-container'.
‌If the provided parameter is a string, then it will return true. If it's something else, it will return false.
E.g. main_label.setTarget('privacylabel-holder');

setDebug( boolean )
‌Enables debug output to the browser's javascript console. This give a lot more insight into what the library is doing. Can be set to true or false. 
‌If the provided parameter is a boolean, then it will return true. If it's something else, it will return false.
e.g. main_label.setDebug(true);

setAllowWebsiteLink( boolean )
‌Clicking on the privacy label icon in the label will normally open the privacy label website. The same goes the the 'read more' links in the built-in explanations at the top of each section. In some cases there may be a legal requirement to disable these links. In that case you can use this method. It can be set to true or false. By default it's set to true.
‌‌If the provided parameter is a boolean, then it will return true. If it's something else, it will return false.
E.g. main_label.setAllowWebsiteLink(false);

setLanguage( string )
‌Selects the language that a label should be generated in. It accepts a string. Most international ISO language codes are two letters. By default the value is null.
‌‌If the provided parameter is a string, then it will return true. If it's something else, it will return false.
E.g. main_label.setLanguage('de');

setAutoDownloadLanguages( boolean )
‌By enabling this, any missing translation data will automatically be downloaded from privacylabel.org.
‌‌‌If the provided parameter is a boolean, then it will return true. If it's something else, it will return false.
E.g. main_label.setAutoDownloadLanguages(true);

setAutoDownloadSource( url )
‌The auto-download feature normally downloads missing languages from https://www.privacylabel.org/languages/json/ . The missing language code is appended to that url, and then a get-request it made. For example, it French is missing, it will request the translation at this location: https://www.privacylabel.org/languages/json/fr . 
‌This method allows you to set your own server as the source of translation files. 
E.g. main_label.setAutoDownloadSource('https://www.example.org/privacylabel_languages.php?language=');<br>‌</i><br>‌</p> <h4 class="element" id="element_1637333875801">Loading data</h4> <p class="element lipsum" id="element_1636139210256" style="visibility: visible;"><b>loadShortCode( code )</b><br>‌Generates label data from a shortcode string.<br>‌<i>E.g. main_label.loadShortCode('en-gb2YABOAB3F4ABCD5PMASF6TSL7PS211105Z');

loadLabelObject( object )
‌Parses a javascript object that contains label data. For example, a parsed JSON file.
E.g. main_label.loadLabelObject(privacylabel_data);

loadLanguageObject( object )
‌‌Parses a javascript object that contains one or more translations. For example, a parsed JSON file. 
I‌t returns the number of new languages that were loaded (as an integer).
‌‌E.g. main_label.loadLabelObject(privacylabel_languages);

loadLabelJson( url ) ‌
‌Downoads new label data JSON from a URL, parses it, and passes it to the loadLabelObject() method. ‌This method returns a promise. If the file was downloaded, parsed and loaded succesfully, then the promise is resolved. If any of these steps fail, the promise is rejected. ‌
E.g. ‌
‌main_label.loadLabelJson('https://www.privacylabel.org/label/demo_label.json') 
‌.then(function(outcome){ console.log(outcome); }) 
‌‌.catch(function(e){ console.log("Error: " + e); })

loadLanguageJson( url ) ‌
‌Downloads new language data from a URL, and passes it to the loadLanguageData() method. This data is needed to translate the label between various languages. The file can contain one or several languages. If the language is already loaded, it will be skipped. 
‌‌This method returns a promise. If the file was downloaded, parsed and loaded succesfully, then the promise is resolved. If any of these steps fail, the promise is rejected. The method also returns the number of new languages that were loaded (as an integer). ‌
‌E.g. 
main_label.loadLanguageJson('https://www.privacylabel.org/languages/json/en-gb') 
‌.then(function(outcome){ console.log(outcome); }) ‌‌
‌.catch(function(e){ console.log("Error: " + e); })

Starting

generate()
‌Generates HTML from the label data. To work, the label data, desired language, and target element all need to be set. By default the target is set to 'privacylabel-container', and if no language is set, it will at this point set itself to 'en-gb'. 
‌It returns a promise. If any of the three requirements are set to null, then it throws an error. If a translation is missing, and auto-download is set to true, then it will first attempt to download and load the missing language file. If the HTML was generated succesfully, then the promise is resolved.