Mercurial > hg > webaudioevaluationtool
comparison core.js @ 1525:b92bdfcbf61c
Bug #1300: Boxes are resized with the window. On HD level displays (1920 wide) will have three columns
author | Nicholas Jillings <nickjillings@users.noreply.github.com> |
---|---|
date | Mon, 14 Sep 2015 17:18:33 +0100 |
parents | 9c1550a1de6e |
children | fb41d65cc89f |
comparison
equal
deleted
inserted
replaced
1524:9c1550a1de6e | 1525:b92bdfcbf61c |
---|---|
616 document.getElementsByTagName("head")[0].appendChild(css); | 616 document.getElementsByTagName("head")[0].appendChild(css); |
617 } | 617 } |
618 document.getElementsByTagName("head")[0].appendChild(interfaceJS); | 618 document.getElementsByTagName("head")[0].appendChild(interfaceJS); |
619 | 619 |
620 // Define window callbacks for interface | 620 // Define window callbacks for interface |
621 window.onresize = function(event){resizeWindow(event);}; | 621 window.onresize = function(event){interfaceContext.resizeWindow(event);}; |
622 } | 622 } |
623 | 623 |
624 function createProjectSave(destURL) { | 624 function createProjectSave(destURL) { |
625 // Save the data from interface into XML and send to destURL | 625 // Save the data from interface into XML and send to destURL |
626 // If destURL is null then download XML in client | 626 // If destURL is null then download XML in client |
1279 hold.appendChild(date); | 1279 hold.appendChild(date); |
1280 hold.appendChild(time); | 1280 hold.appendChild(time); |
1281 return hold | 1281 return hold |
1282 | 1282 |
1283 } | 1283 } |
1284 | |
1285 function testWaitIndicator() { | |
1286 if (audioEngineContext.checkAllReady() == false) { | |
1287 var hold = document.createElement("div"); | |
1288 hold.id = "testWaitIndicator"; | |
1289 hold.className = "indicator-box"; | |
1290 hold.style.zIndex = 3; | |
1291 var span = document.createElement("span"); | |
1292 span.textContent = "Please wait! Elements still loading"; | |
1293 hold.appendChild(span); | |
1294 var blank = document.createElement('div'); | |
1295 blank.className = 'testHalt'; | |
1296 blank.id = "testHaltBlank"; | |
1297 var body = document.getElementsByTagName('body')[0]; | |
1298 body.appendChild(hold); | |
1299 body.appendChild(blank); | |
1300 testWaitTimerIntervalHolder = setInterval(function(){ | |
1301 var ready = audioEngineContext.checkAllReady(); | |
1302 if (ready) { | |
1303 var elem = document.getElementById('testWaitIndicator'); | |
1304 var blank = document.getElementById('testHaltBlank'); | |
1305 var body = document.getElementsByTagName('body')[0]; | |
1306 body.removeChild(elem); | |
1307 body.removeChild(blank); | |
1308 clearInterval(testWaitTimerIntervalHolder); | |
1309 } | |
1310 },500,false); | |
1311 } | |
1312 } | |
1313 | |
1314 var testWaitTimerIntervalHolder = null; | |
1315 | 1284 |
1316 function Specification() { | 1285 function Specification() { |
1317 // Handles the decoding of the project specification XML into a simple JavaScript Object. | 1286 // Handles the decoding of the project specification XML into a simple JavaScript Object. |
1318 | 1287 |
1319 this.interfaceType; | 1288 this.interfaceType; |
1742 // Interface object MUST have an exportXMLDOM method which returns the various DOM levels | 1711 // Interface object MUST have an exportXMLDOM method which returns the various DOM levels |
1743 // For example, APE returns the slider position normalised in a <value> tag. | 1712 // For example, APE returns the slider position normalised in a <value> tag. |
1744 this.interfaceObjects = []; | 1713 this.interfaceObjects = []; |
1745 this.interfaceObject = function(){}; | 1714 this.interfaceObject = function(){}; |
1746 | 1715 |
1716 this.resizeWindow = function(event) | |
1717 { | |
1718 for(var i=0; i<this.commentBoxes.length; i++) | |
1719 {this.commentBoxes[i].resize();} | |
1720 for(var i=0; i<this.commentQuestions.length; i++) | |
1721 {this.commentQuestions[i].resize();} | |
1722 try | |
1723 { | |
1724 resizeWindow(event); | |
1725 } | |
1726 catch(err) | |
1727 { | |
1728 console.log("Warning - Interface does not have Resize option"); | |
1729 console.log(err); | |
1730 } | |
1731 }; | |
1732 | |
1747 this.commentBoxes = []; | 1733 this.commentBoxes = []; |
1748 this.elementCommentBox = function(audioObject) { | 1734 this.elementCommentBox = function(audioObject) { |
1749 var element = audioObject.specification; | 1735 var element = audioObject.specification; |
1750 this.audioObject = audioObject; | 1736 this.audioObject = audioObject; |
1751 this.id = audioObject.id; | 1737 this.id = audioObject.id; |
1752 var audioHolderObject = audioObject.specification.parent; | 1738 var audioHolderObject = audioObject.specification.parent; |
1753 // Create document objects to hold the comment boxes | 1739 // Create document objects to hold the comment boxes |
1754 this.trackComment = document.createElement('div'); | 1740 this.trackComment = document.createElement('div'); |
1755 this.trackComment.className = 'comment-div'; | 1741 this.trackComment.className = 'comment-div'; |
1756 this.trackComment.id = 'comment-div-'+audioObject.id; | 1742 this.trackComment.id = 'comment-div-'+audioObject.id; |
1757 var boxwidth = (window.innerWidth-100)/2; | |
1758 if (boxwidth >= 624) | |
1759 { | |
1760 boxwidth = 624; | |
1761 } | |
1762 else if (boxwidth < 400) | |
1763 { | |
1764 boxwidth = 400; | |
1765 } | |
1766 this.trackComment.style.width = boxwidth+"px"; | |
1767 // Create a string next to each comment asking for a comment | 1743 // Create a string next to each comment asking for a comment |
1768 this.trackString = document.createElement('span'); | 1744 this.trackString = document.createElement('span'); |
1769 this.trackString.innerHTML = audioHolderObject.commentBoxPrefix+' '+audioObject.id; | 1745 this.trackString.innerHTML = audioHolderObject.commentBoxPrefix+' '+audioObject.id; |
1770 // Create the HTML5 comment box 'textarea' | 1746 // Create the HTML5 comment box 'textarea' |
1771 this.trackCommentBox = document.createElement('textarea'); | 1747 this.trackCommentBox = document.createElement('textarea'); |
1772 this.trackCommentBox.rows = '4'; | 1748 this.trackCommentBox.rows = '4'; |
1773 this.trackCommentBox.cols = '100'; | 1749 this.trackCommentBox.cols = '100'; |
1774 this.trackCommentBox.name = 'trackComment'+audioObject.id; | 1750 this.trackCommentBox.name = 'trackComment'+audioObject.id; |
1775 this.trackCommentBox.className = 'trackComment'; | 1751 this.trackCommentBox.className = 'trackComment'; |
1776 this.trackCommentBox.style.width = boxwidth-6+"px"; | |
1777 var br = document.createElement('br'); | 1752 var br = document.createElement('br'); |
1778 // Add to the holder. | 1753 // Add to the holder. |
1779 this.trackComment.appendChild(this.trackString); | 1754 this.trackComment.appendChild(this.trackString); |
1780 this.trackComment.appendChild(br); | 1755 this.trackComment.appendChild(br); |
1781 this.trackComment.appendChild(this.trackCommentBox); | 1756 this.trackComment.appendChild(this.trackCommentBox); |
1791 root.appendChild(question); | 1766 root.appendChild(question); |
1792 root.appendChild(response); | 1767 root.appendChild(response); |
1793 } | 1768 } |
1794 return root; | 1769 return root; |
1795 }; | 1770 }; |
1771 this.resize = function() | |
1772 { | |
1773 var boxwidth = (window.innerWidth-100)/2; | |
1774 if (boxwidth >= 600) | |
1775 { | |
1776 boxwidth = 600; | |
1777 } | |
1778 else if (boxwidth < 400) | |
1779 { | |
1780 boxwidth = 400; | |
1781 } | |
1782 this.trackComment.style.width = boxwidth+"px"; | |
1783 this.trackCommentBox.style.width = boxwidth-6+"px"; | |
1784 }; | |
1785 this.resize(); | |
1796 }; | 1786 }; |
1797 | 1787 |
1798 this.commentQuestions = []; | 1788 this.commentQuestions = []; |
1799 | 1789 |
1800 this.commentBox = function(commentQuestion) { | 1790 this.commentBox = function(commentQuestion) { |
1801 this.specification = commentQuestion; | 1791 this.specification = commentQuestion; |
1802 // Create document objects to hold the comment boxes | 1792 // Create document objects to hold the comment boxes |
1803 this.holder = document.createElement('div'); | 1793 this.holder = document.createElement('div'); |
1804 this.holder.className = 'comment-div'; | 1794 this.holder.className = 'comment-div'; |
1805 var boxwidth = (window.innerWidth-100)/2; | |
1806 if (boxwidth >= 624) | |
1807 { | |
1808 boxwidth = 624; | |
1809 } | |
1810 else if (boxwidth < 400) | |
1811 { | |
1812 boxwidth = 400; | |
1813 } | |
1814 this.holder.style.width = boxwidth+"px"; | |
1815 // Create a string next to each comment asking for a comment | 1795 // Create a string next to each comment asking for a comment |
1816 this.string = document.createElement('span'); | 1796 this.string = document.createElement('span'); |
1817 this.string.innerHTML = commentQuestion.question; | 1797 this.string.innerHTML = commentQuestion.question; |
1818 // Create the HTML5 comment box 'textarea' | 1798 // Create the HTML5 comment box 'textarea' |
1819 this.textArea = document.createElement('textarea'); | 1799 this.textArea = document.createElement('textarea'); |
1820 this.textArea.rows = '4'; | 1800 this.textArea.rows = '4'; |
1821 this.textArea.cols = '100'; | 1801 this.textArea.cols = '100'; |
1822 this.textArea.className = 'trackComment'; | 1802 this.textArea.className = 'trackComment'; |
1823 this.textArea.style.width = boxwidth-6+"px"; | |
1824 var br = document.createElement('br'); | 1803 var br = document.createElement('br'); |
1825 // Add to the holder. | 1804 // Add to the holder. |
1826 this.holder.appendChild(this.string); | 1805 this.holder.appendChild(this.string); |
1827 this.holder.appendChild(br); | 1806 this.holder.appendChild(br); |
1828 this.holder.appendChild(this.textArea); | 1807 this.holder.appendChild(this.textArea); |
1834 root.textContent = this.textArea.value; | 1813 root.textContent = this.textArea.value; |
1835 console.log("Question: "+this.string.textContent); | 1814 console.log("Question: "+this.string.textContent); |
1836 console.log("Response: "+root.textContent); | 1815 console.log("Response: "+root.textContent); |
1837 return root; | 1816 return root; |
1838 }; | 1817 }; |
1818 this.resize = function() | |
1819 { | |
1820 var boxwidth = (window.innerWidth-100)/2; | |
1821 if (boxwidth >= 600) | |
1822 { | |
1823 boxwidth = 600; | |
1824 } | |
1825 else if (boxwidth < 400) | |
1826 { | |
1827 boxwidth = 400; | |
1828 } | |
1829 this.holder.style.width = boxwidth+"px"; | |
1830 this.textArea.style.width = boxwidth-6+"px"; | |
1831 }; | |
1832 this.resize(); | |
1839 }; | 1833 }; |
1840 | 1834 |
1841 this.radioBox = function(commentQuestion) { | 1835 this.radioBox = function(commentQuestion) { |
1842 this.specification = commentQuestion; | 1836 this.specification = commentQuestion; |
1843 // Create document objects to hold the comment boxes | 1837 // Create document objects to hold the comment boxes |
1844 this.holder = document.createElement('div'); | 1838 this.holder = document.createElement('div'); |
1845 this.holder.className = 'comment-div'; | 1839 this.holder.className = 'comment-div'; |
1846 var boxwidth = (window.innerWidth-100)/2; | |
1847 if (boxwidth >= 624) | |
1848 { | |
1849 boxwidth = 624; | |
1850 } | |
1851 else if (boxwidth < 400) | |
1852 { | |
1853 boxwidth = 400; | |
1854 } | |
1855 this.holder.style.width = boxwidth+"px"; | |
1856 // Create a string next to each comment asking for a comment | 1840 // Create a string next to each comment asking for a comment |
1857 this.string = document.createElement('span'); | 1841 this.string = document.createElement('span'); |
1858 this.string.innerHTML = commentQuestion.statement; | 1842 this.string.innerHTML = commentQuestion.statement; |
1859 var br = document.createElement('br'); | 1843 var br = document.createElement('br'); |
1860 // Add to the holder. | 1844 // Add to the holder. |
1868 this.span.style.marginLeft = '12px'; | 1852 this.span.style.marginLeft = '12px'; |
1869 this.span.align = 'center'; | 1853 this.span.align = 'center'; |
1870 this.span.style.marginTop = '15px'; | 1854 this.span.style.marginTop = '15px'; |
1871 | 1855 |
1872 var optCount = commentQuestion.options.length; | 1856 var optCount = commentQuestion.options.length; |
1873 var spanMargin = Math.floor(((boxwidth-20-(optCount*80))/(optCount))/2)+'px'; | |
1874 for (var i=0; i<optCount; i++) | 1857 for (var i=0; i<optCount; i++) |
1875 { | 1858 { |
1876 var div = document.createElement('div'); | 1859 var div = document.createElement('div'); |
1877 div.style.width = '80px'; | 1860 div.style.width = '80px'; |
1878 div.style.float = 'left'; | 1861 div.style.float = 'left'; |
1879 div.style.marginRight = spanMargin; | |
1880 div.style.marginLeft = spanMargin; | |
1881 var input = document.createElement('input'); | 1862 var input = document.createElement('input'); |
1882 input.type = 'radio'; | 1863 input.type = 'radio'; |
1883 input.name = commentQuestion.id; | 1864 input.name = commentQuestion.id; |
1884 input.setAttribute('setvalue',commentQuestion.options[i].name); | 1865 input.setAttribute('setvalue',commentQuestion.options[i].name); |
1885 input.className = 'comment-radio'; | 1866 input.className = 'comment-radio'; |
1888 | 1869 |
1889 | 1870 |
1890 div = document.createElement('div'); | 1871 div = document.createElement('div'); |
1891 div.style.width = '80px'; | 1872 div.style.width = '80px'; |
1892 div.style.float = 'left'; | 1873 div.style.float = 'left'; |
1893 div.style.marginRight = spanMargin; | |
1894 div.style.marginLeft = spanMargin; | |
1895 div.align = 'center'; | 1874 div.align = 'center'; |
1896 var span = document.createElement('span'); | 1875 var span = document.createElement('span'); |
1897 span.textContent = commentQuestion.options[i].text; | 1876 span.textContent = commentQuestion.options[i].text; |
1898 span.className = 'comment-radio-span'; | 1877 span.className = 'comment-radio-span'; |
1899 div.appendChild(span); | 1878 div.appendChild(span); |
1927 console.log('Response: '+response.textContent); | 1906 console.log('Response: '+response.textContent); |
1928 root.appendChild(question); | 1907 root.appendChild(question); |
1929 root.appendChild(response); | 1908 root.appendChild(response); |
1930 return root; | 1909 return root; |
1931 }; | 1910 }; |
1911 this.resize = function() | |
1912 { | |
1913 var boxwidth = (window.innerWidth-100)/2; | |
1914 if (boxwidth >= 600) | |
1915 { | |
1916 boxwidth = 600; | |
1917 } | |
1918 else if (boxwidth < 400) | |
1919 { | |
1920 boxwidth = 400; | |
1921 } | |
1922 this.holder.style.width = boxwidth+"px"; | |
1923 var text = this.holder.children[2]; | |
1924 var options = this.holder.children[3]; | |
1925 var optCount = options.children.length; | |
1926 var spanMargin = Math.floor(((boxwidth-20-(optCount*80))/(optCount))/2)+'px'; | |
1927 var options = options.firstChild; | |
1928 var text = text.firstChild; | |
1929 options.style.marginRight = spanMargin; | |
1930 options.style.marginLeft = spanMargin; | |
1931 text.style.marginRight = spanMargin; | |
1932 text.style.marginLeft = spanMargin; | |
1933 while(options.nextSibling != undefined) | |
1934 { | |
1935 options = options.nextSibling; | |
1936 text = text.nextSibling; | |
1937 options.style.marginRight = spanMargin; | |
1938 options.style.marginLeft = spanMargin; | |
1939 text.style.marginRight = spanMargin; | |
1940 text.style.marginLeft = spanMargin; | |
1941 } | |
1942 }; | |
1943 this.resize(); | |
1932 }; | 1944 }; |
1933 | 1945 |
1934 this.checkboxBox = function(commentQuestion) { | 1946 this.checkboxBox = function(commentQuestion) { |
1935 this.specification = commentQuestion; | 1947 this.specification = commentQuestion; |
1936 // Create document objects to hold the comment boxes | 1948 // Create document objects to hold the comment boxes |
1937 this.holder = document.createElement('div'); | 1949 this.holder = document.createElement('div'); |
1938 this.holder.className = 'comment-div'; | 1950 this.holder.className = 'comment-div'; |
1939 var boxwidth = (window.innerWidth-100)/2; | |
1940 if (boxwidth >= 624) | |
1941 { | |
1942 boxwidth = 624; | |
1943 } | |
1944 else if (boxwidth < 400) | |
1945 { | |
1946 boxwidth = 400; | |
1947 } | |
1948 this.holder.style.width = boxwidth+"px"; | |
1949 // Create a string next to each comment asking for a comment | 1951 // Create a string next to each comment asking for a comment |
1950 this.string = document.createElement('span'); | 1952 this.string = document.createElement('span'); |
1951 this.string.innerHTML = commentQuestion.statement; | 1953 this.string.innerHTML = commentQuestion.statement; |
1952 var br = document.createElement('br'); | 1954 var br = document.createElement('br'); |
1953 // Add to the holder. | 1955 // Add to the holder. |
1961 this.span.style.marginLeft = '12px'; | 1963 this.span.style.marginLeft = '12px'; |
1962 this.span.align = 'center'; | 1964 this.span.align = 'center'; |
1963 this.span.style.marginTop = '15px'; | 1965 this.span.style.marginTop = '15px'; |
1964 | 1966 |
1965 var optCount = commentQuestion.options.length; | 1967 var optCount = commentQuestion.options.length; |
1966 var spanMargin = Math.floor(((boxwidth-20-(optCount*80))/(optCount))/2)+'px'; | |
1967 for (var i=0; i<optCount; i++) | 1968 for (var i=0; i<optCount; i++) |
1968 { | 1969 { |
1969 var div = document.createElement('div'); | 1970 var div = document.createElement('div'); |
1970 div.style.width = '80px'; | 1971 div.style.width = '80px'; |
1971 div.style.float = 'left'; | 1972 div.style.float = 'left'; |
1972 div.style.marginRight = spanMargin; | |
1973 div.style.marginLeft = spanMargin; | |
1974 var input = document.createElement('input'); | 1973 var input = document.createElement('input'); |
1975 input.type = 'checkbox'; | 1974 input.type = 'checkbox'; |
1976 input.name = commentQuestion.id; | 1975 input.name = commentQuestion.id; |
1977 input.setAttribute('setvalue',commentQuestion.options[i].name); | 1976 input.setAttribute('setvalue',commentQuestion.options[i].name); |
1978 input.className = 'comment-radio'; | 1977 input.className = 'comment-radio'; |
1981 | 1980 |
1982 | 1981 |
1983 div = document.createElement('div'); | 1982 div = document.createElement('div'); |
1984 div.style.width = '80px'; | 1983 div.style.width = '80px'; |
1985 div.style.float = 'left'; | 1984 div.style.float = 'left'; |
1986 div.style.marginRight = spanMargin; | |
1987 div.style.marginLeft = spanMargin; | |
1988 div.align = 'center'; | 1985 div.align = 'center'; |
1989 var span = document.createElement('span'); | 1986 var span = document.createElement('span'); |
1990 span.textContent = commentQuestion.options[i].text; | 1987 span.textContent = commentQuestion.options[i].text; |
1991 span.className = 'comment-radio-span'; | 1988 span.className = 'comment-radio-span'; |
1992 div.appendChild(span); | 1989 div.appendChild(span); |
2011 root.appendChild(response); | 2008 root.appendChild(response); |
2012 console.log('Response '+response.getAttribute('name') +': '+response.textContent); | 2009 console.log('Response '+response.getAttribute('name') +': '+response.textContent); |
2013 } | 2010 } |
2014 return root; | 2011 return root; |
2015 }; | 2012 }; |
2013 this.resize = function() | |
2014 { | |
2015 var boxwidth = (window.innerWidth-100)/2; | |
2016 if (boxwidth >= 600) | |
2017 { | |
2018 boxwidth = 600; | |
2019 } | |
2020 else if (boxwidth < 400) | |
2021 { | |
2022 boxwidth = 400; | |
2023 } | |
2024 this.holder.style.width = boxwidth+"px"; | |
2025 var text = this.holder.children[2]; | |
2026 var options = this.holder.children[3]; | |
2027 var optCount = options.children.length; | |
2028 var spanMargin = Math.floor(((boxwidth-20-(optCount*80))/(optCount))/2)+'px'; | |
2029 var options = options.firstChild; | |
2030 var text = text.firstChild; | |
2031 options.style.marginRight = spanMargin; | |
2032 options.style.marginLeft = spanMargin; | |
2033 text.style.marginRight = spanMargin; | |
2034 text.style.marginLeft = spanMargin; | |
2035 while(options.nextSibling != undefined) | |
2036 { | |
2037 options = options.nextSibling; | |
2038 text = text.nextSibling; | |
2039 options.style.marginRight = spanMargin; | |
2040 options.style.marginLeft = spanMargin; | |
2041 text.style.marginRight = spanMargin; | |
2042 text.style.marginLeft = spanMargin; | |
2043 } | |
2044 }; | |
2045 this.resize(); | |
2016 }; | 2046 }; |
2017 | 2047 |
2018 this.createCommentBox = function(audioObject) { | 2048 this.createCommentBox = function(audioObject) { |
2019 var node = new this.elementCommentBox(audioObject); | 2049 var node = new this.elementCommentBox(audioObject); |
2020 this.commentBoxes.push(node); | 2050 this.commentBoxes.push(node); |