Skip to content

Interactive interface for browsing global, full-resolution satellite imagery

Added the PaletteSelector

Mike McGann13121614cbf7
diff --git a/build.xml b/build.xml
index feae3c94d..0553863e7 100644
--- a/build.xml
+++ b/build.xml
@@ -54,6 +54,8 @@
<arg value="${src.web.js.dir}"/>
<arg value="-i"/>
<arg value="doc/Topics"/>
+ <arg value="-i"/>
+ <arg value="test/lib"/>
<arg value="-o"/>
<arg value="HTML"/>
<arg value="${build.doc.dir}"/>
@@ -191,7 +193,18 @@
<arg value="test/jsTestDriver.conf"/>
</exec>
</target>
-
+
+ <target name="test-one">
+ <exec executable="java">
+ <arg value="-jar"/>
+ <arg value="${js-test-driver.jar.path}"/>
+ <arg value="--tests"/>
+ <arg value="${test}"/>
+ <arg value="--config"/>
+ <arg value="test/jsTestDriver.conf"/>
+ </exec>
+ </target>
+
<target name="dist" depends="clean,web,doc"
description="Generates distribution artifacts">
<tar destfile="${dist.dir}/worldview.tar.bz2"
diff --git a/css/ext/jquery.dd/dd.css b/css/ext/jquery.dd/dd.css
new file mode 100644
index 000000000..1057247e6
--- /dev/null
+++ b/css/ext/jquery.dd/dd.css
@@ -0,0 +1,64 @@
+.borderRadius{-moz-border-radius:5px; border-radius:5px; }
+.borderRadiusTp{-moz-border-radius:5px 5px 0 0; border-radius:5px 5px 0 0;}
+.borderRadiusBtm{-moz-border-radius:0 0 5px 5px ; border-radius:0 0 5px 5px;}
+
+.ddcommon {position:relative;display:-moz-inline-stack; zoom:1; display:inline-block; *display:inline; cursor:default;}
+.ddcommon ul{padding:0;margin:0;}
+.ddcommon ul li{list-style-type:none;}
+.borderRadiusTp ul li:last-child{-moz-border-radius:0 0 5px 5px ; border-radius:0 0 5px 5px;border-bottom:0 none #c3c3c3; }
+.borderRadiusBtm ul li:first-child{-moz-border-radius:5px 5px 0 0; border-radius:5px 5px 0 0 ;border-bottom:1 solid #c3c3c3; }
+
+.ddcommon .disabled img, .ddcommon .disabled span, .ddcommon.disabledAll{
+opacity: .5; /* standard: ff gt 1.5, opera, safari */
+-ms-filter:"alpha(opacity=50)"; /* ie 8 */
+filter:alpha(opacity=50); /* ie lt 7 */
+-khtml-opacity:.5; /* safari 1.x */
+-moz-opacity:.5; /* ff lt 1.5, netscape */
+color:#999999;
+}
+.ddcommon .clear{clear:both}
+.ddcommon .shadow{-moz-box-shadow:5px 5px 5px -5px #888888;-webkit-box-shadow:5px 5px 5px -5px #888888;box-shadow: 5px 5px 5px -5px #888888;}
+.ddcommon input.text{color:#7e7e7e;padding:0 0 0 0; position:absolute; background:#fff; display:block; width:98%; height:98%; left:2px; top:0; border:none;}
+.ddOutOfVision{position:relative; display:-moz-inline-stack; display:inline-block; zoom:1; *display:inline;}
+.borderRadius .shadow{-moz-box-shadow:5px 5px 5px -5px #888888;-webkit-box-shadow:5px 5px 5px -5px #888888;box-shadow: 5px 5px 5px -5px #888888;}
+.borderRadiusBtm .shadow{-moz-box-shadow:-5px -5px 5px -5px #888888;-webkit-box-shadow:-5px -5px 5px -5px #888888;box-shadow: -5px -5px 5px -5px #888888}
+.borderRadiusTp .border, .borderRadius .border{-moz-border-radius:0 0 5px 5px ; border-radius:0 0 5px 5px;}
+.borderRadiusBtm .border{-moz-border-radius:5px 5px 0 0; border-radius:5px 5px 0 0;}
+img.fnone{float:none !important}
+.ddcommon .divider{width:0; height:100%; position:absolute;}
+.ddcommon .arrow{display:inline-block; position:absolute; top:50%; right:4px;}
+.ddcommon .arrow:hover{background-position:0 100%;}
+.ddcommon .ddTitle{padding:0; position:relative; display:inline-block; width:100%}
+.ddcommon .ddTitle .ddTitleText{display:block;}
+.ddcommon .ddTitle .ddTitleText .ddTitleText{padding:0;}
+.ddcommon .ddTitle .description{display:block;}
+.ddcommon .ddTitle .ddTitleText img{position:relative; vertical-align:middle; float:left}
+.ddcommon .ddChild{position:absolute;display:none;width:100%;overflow-y:auto; overflow-x:hidden; zoom:1; z-index:9999}
+.ddcommon .ddChild li{clear:both;}
+.ddcommon .ddChild li .description{display:block;}
+.ddcommon .ddChild li img{border:0 none; position:relative;vertical-align:middle;float:left}
+.ddcommon .ddChild li.optgroup{padding:0;}
+.ddcommon .ddChild li.optgroup .optgroupTitle{padding:0 5px; font-weight:bold; font-style:italic}
+.ddcommon .ddChild li.optgroup ul li{padding:5px 5px 5px 15px}
+.ddcommon .noBorderTop{border-top:none 0 !important; padding:0; margin:0;}
+
+/*************** default theme **********************/
+.dd{border:1px solid #c3c3c3;}
+.dd .divider{border-left:1px solid #c3c3c3; border-right:1px solid #fff;; right:24px;}
+.dd .arrow{width:16px;height:16px; margin-top:-8px; background:url(../../../images/jquery.dd/skin1/dd_arrow.gif) no-repeat;}
+.dd .arrow:hover{background-position:0 100%;}
+.dd .ddTitle{color:#000;background:#e2e2e4 url(../../../images/jquery.dd/skin1/title-bg.gif) repeat-x left top;}
+.dd .ddTitle .ddTitleText{padding:5px 20px 5px 5px;}
+.dd .ddTitle .ddTitleText .ddTitleText{padding:0;}
+.dd .ddTitle .description{font-size:12px; color:#666}
+.dd .ddTitle .ddTitleText img{padding-right:5px;}
+.dd .ddChild{border:1px solid #c3c3c3; background-color:#fff; left:-1px;}
+.dd .ddChild li{padding:5px; background-color:#fff; border-bottom:1px solid #c3c3c3;}
+.dd .ddChild li .description{color:#666;}
+.dd .ddChild li .ddlabel{color:#333;}
+.dd .ddChild li.hover{background-color:#f2f2f2}
+.dd .ddChild li img{padding:0 6px 0 0;}
+.dd .ddChild li.optgroup{padding:0;}
+.dd .ddChild li.optgroup .optgroupTitle{padding:0 5px; font-weight:bold; font-style:italic}
+.dd .ddChild li.optgroup ul li{padding:5px 5px 5px 15px}
+.dd .ddChild li.selected{background-color:#d5d5d5; color:#000;}
diff --git a/css/ext/jquery.dd/skin2.css b/css/ext/jquery.dd/skin2.css
new file mode 100644
index 000000000..67ad160a8
--- /dev/null
+++ b/css/ext/jquery.dd/skin2.css
@@ -0,0 +1,20 @@
+.blue{border:1px solid #ddd;}
+.blue .divider{display:none}
+.blue .arrow{width:27px;height:27px; margin-top:-14px; background:url(../../../images/jquery.dd/skin2/dd_arrow.gif) no-repeat;}
+.blue .arrow:hover{background-position:0 100%;}
+.blue .ddTitle{color:#fff;background:#10bbe6 url(../../../images/jquery.dd/skin2/title-bg.gif) repeat-x left top;}
+.blue .ddTitle .ddTitleText{padding:10px 20px 10px 5px; font-weight:bold; font-size:16px;}
+.blue .ddTitle .ddTitleText .ddTitleText{padding:0;}
+.blue .ddTitle .description{font-size:12px; color:#666}
+.blue .ddTitle .ddTitleText img{padding-right:5px;}
+.blue .ddChild{border:1px solid #c3c3c3; background-color:#fff; left:-1px;}
+.blue .ddChild li{padding:5px; background-color:#fff; border-bottom:1px solid #c3c3c3;}
+.blue .ddChild li .description{color:#666;}
+.blue .ddChild li .ddlabel{color:#333;}
+.blue .ddChild li.hover{background-color:#66CCFF;}
+.blue .ddChild li img{padding:0 6px 0 0;}
+.blue .ddChild li.optgroup{padding:0;}
+.blue .ddChild li.optgroup .optgroupTitle{padding:0 5px; font-weight:bold; font-style:italic}
+.blue .ddChild li.optgroup ul li{padding:5px 5px 5px 15px}
+.blue .ddChild li.selected{background-color:#0d97ba;}
+.blue .ddChild li.selected .ddlabel{color:#fff;}
diff --git a/css/palette.css b/css/palette.css
index 02f941496..9f90855d3 100644
--- a/css/palette.css
+++ b/css/palette.css
@@ -4,17 +4,17 @@
border: 2px solid #aaaaaa;
}
-#palette-selector .dd-selected-image {
+#xpalette-selector .dd-selected-image {
margin-top: 14px;
margin-right: 10px;
border: 1px solid black;
}
-#palette-selector .dd-option-image {
+#xpalette-selector .dd-option-image {
border: 1px solid black;
margin-right: 10px;
}
-#palette-selector .dd-option-description {
+#xpalette-selector .dd-option-description {
margin-left: 75px;
}
diff --git a/dev/palette/selector/selector.html b/dev/palette/selector/selector.html
index 253537cbf..a25ab1387 100644
--- a/dev/palette/selector/selector.html
+++ b/dev/palette/selector/selector.html
@@ -2,27 +2,35 @@
<html>
<head>
<title>Palette Selector</title>
+ <link rel="stylesheet" type="text/css" href="../../../css/ext/jquery.dd/dd.css"/>
+ <link rel="stylesheet" type="text/css" href="../../../css/ext/jquery.dd/skin2.css"/>
<link rel="stylesheet" type="text/css" href="../../../css/palette.css"/>
<link rel="stylesheet" type="text/css" href="selector.css"/>
- <script type="text/javascript" src="../../../js/ext/jquery-1.9.1/jquery-1.9.1.js"></scrit>
+ <script type="text/javascript" src="../../../js/ext/jquery/jquery-1.6.4.js"></script>
<script type="text/javascript" src="../../../js/ext/handlebars-1.0.rc.2/handlebars.js"></script>
- <script type="text/javascript" src="../../../js/ext/ddSlick-2.0/jquery.ddslick.min.js"></script>
+ <script type="text/javascript" src="../../../js/ext/jquery.dd/jquery.dd.js"></script>
+
<script type="text/javascript" src="../../../js/component.js"></script>
<script type="text/javascript" src="../../../js/util.js"></script>
<script type="text/javascript" src="../../../js/Worldview.js"></script>
<script type="text/javascript" src="../../../js/Worldview/Visual.js"></script>
<script type="text/javascript" src="../../../js/Worldview/Visual/ColorRGBA.js"></script>
<script type="text/javascript" src="../../../js/Worldview/Visual/ColorHSL.js"></script>
- <script type="text/javascript" src="../../../js/Worldview/Visual/StopRGB.js"></script>
+ <script type="text/javascript" src="../../../js/Worldview/Visual/StopRGBA.js"></script>
<script type="text/javascript" src="../../../js/Worldview/Visual/Lookup.js"></script>
<script type="text/javascript" src="../../../js/Worldview/Visual/Palette.js"></script>
<script type="text/javascript" src="../../../js/Worldview/Visual/ColorBar.js"></script>
- <script type="text/javascript" src="../../../js/Worldview/Visual/StockPaletteSelector.js"></script>
+ <script type="text/javascript" src="../../../js/Worldview/Visual/PaletteSelector.js"></script>
<script type="text/javascript" src="selector.js"></script>
</head>
<body>
<h1>Palette Selector</h1>
- <div id="palette-selector"></div>
+ <div id="palette-selector"></div>
+ <br/>
+ <form action="">
+ Selected index: <input id="selected-index" type="text">
+ <input id="set-selected-index" type="submit">
+ </form>
</body>
</html>
\ No newline at end of file
diff --git a/dev/palette/selector/selector.js b/dev/palette/selector/selector.js
index 71d99c0c0..044540ad1 100644
--- a/dev/palette/selector/selector.js
+++ b/dev/palette/selector/selector.js
@@ -1,9 +1,28 @@
$(function() {
-
+
var ns = Worldview.Visual;
- ns.STOCK_PALETTE_ENDPOINT = "../../../data/palettes";
+ var onLoad = function(palettes) {
+ var paletteSelector = ns.PaletteSelector({
+ selector: "#palette-selector",
+ palettes: palettes
+ });
+
+ $("#set-selected-index").click(function() {
+ paletteSelector.select($("#selected-index").val());
+ return false;
+ });
+
+ paletteSelector.addSelectionListener(function(palette) {
+ console.log(palette);
+ });
+ }
+
+ var onError = function(cause) {
+ Worldview.error("Unable to load palettes from the server", cause);
+ }
- ns.StockPaletteSelector({selector: "#palette-selector"});
+ ns.stockPaletteEndpoint = "../../../data/palettes";
+ ns.loadStockPalettes(onLoad, onError);
});
diff --git a/doc/NaturalDocs/Menu.txt b/doc/NaturalDocs/Menu.txt
index bcae76d5d..43e57597e 100644
--- a/doc/NaturalDocs/Menu.txt
+++ b/doc/NaturalDocs/Menu.txt
@@ -69,6 +69,7 @@ Group: Code Reference {
File: ColorRGBA (/Users/jmcgann/Code/Aptana/worldview/js/Worldview/Visual/ColorRGBA.js)
File: Lookup (/Users/jmcgann/Code/Aptana/worldview/js/Worldview/Visual/Lookup.js)
File: Palette (/Users/jmcgann/Code/Aptana/worldview/js/Worldview/Visual/Palette.js)
+ File: PaletteSelector (/Users/jmcgann/Code/Aptana/worldview/js/Worldview/Visual/PaletteSelector.js)
File: StopRGBA (/Users/jmcgann/Code/Aptana/worldview/js/Worldview/Visual/StopRGBA.js)
} # Group: Visual
@@ -76,13 +77,16 @@ Group: Code Reference {
} # Group: Code Reference
+File: TestSuite (/Users/jmcgann/Code/Aptana/worldview/test/lib/TestSuite.js)
+File: TestSuite.Patcher (/Users/jmcgann/Code/Aptana/worldview/test/lib/TestSuite/Patcher.js)
+
Group: Index {
Index: Everything
Class Index: Classes
- Constant Index: Constants
Function Index: Functions
Property Index: Properties
+ Constant Index: Constants
} # Group: Index
@@ -90,3 +94,4 @@ Group: Index {
##### Do not change or remove these lines. #####
Data: 1(D3333a6GH63lE9`p\\30ufG3KItp\p37uHof/8G73l6)
Data: 1(h3333a6GH63lE9`p\\30ufG3KItp\p37uHof/8G73fu93LuI896)
+Data: 1(T3333a6GH63lE9`p\\30ufG3KItp\p37uHof/8G73tG6t3o8Y)
diff --git a/images/jquery.dd/icons/1273404841_tick_16.png b/images/jquery.dd/icons/1273404841_tick_16.png
new file mode 100644
index 000000000..6bd8724f6
Binary files /dev/null and b/images/jquery.dd/icons/1273404841_tick_16.png differ
diff --git a/images/jquery.dd/icons/Amex-56.png b/images/jquery.dd/icons/Amex-56.png
new file mode 100644
index 000000000..507ce6ed5
Binary files /dev/null and b/images/jquery.dd/icons/Amex-56.png differ
diff --git a/images/jquery.dd/icons/Cash-56.png b/images/jquery.dd/icons/Cash-56.png
new file mode 100644
index 000000000..abcd626b7
Binary files /dev/null and b/images/jquery.dd/icons/Cash-56.png differ
diff --git a/images/jquery.dd/icons/Discover-56.png b/images/jquery.dd/icons/Discover-56.png
new file mode 100644
index 000000000..e8bba289c
Binary files /dev/null and b/images/jquery.dd/icons/Discover-56.png differ
diff --git a/images/jquery.dd/icons/Mastercard-56.png b/images/jquery.dd/icons/Mastercard-56.png
new file mode 100644
index 000000000..9de8b0c56
Binary files /dev/null and b/images/jquery.dd/icons/Mastercard-56.png differ
diff --git a/images/jquery.dd/icons/Paypal-56.png b/images/jquery.dd/icons/Paypal-56.png
new file mode 100644
index 000000000..d678b8755
Binary files /dev/null and b/images/jquery.dd/icons/Paypal-56.png differ
diff --git a/images/jquery.dd/icons/Thumbs.db b/images/jquery.dd/icons/Thumbs.db
new file mode 100644
index 000000000..4cd3fa5bd
Binary files /dev/null and b/images/jquery.dd/icons/Thumbs.db differ
diff --git a/images/jquery.dd/icons/Visa-56.png b/images/jquery.dd/icons/Visa-56.png
new file mode 100644
index 000000000..7d58e6e83
Binary files /dev/null and b/images/jquery.dd/icons/Visa-56.png differ
diff --git a/images/jquery.dd/icons/blank.gif b/images/jquery.dd/icons/blank.gif
new file mode 100644
index 000000000..b14e32679
Binary files /dev/null and b/images/jquery.dd/icons/blank.gif differ
diff --git a/images/jquery.dd/icons/browser-chrome.png b/images/jquery.dd/icons/browser-chrome.png
new file mode 100644
index 000000000..017792cd0
Binary files /dev/null and b/images/jquery.dd/icons/browser-chrome.png differ
diff --git a/images/jquery.dd/icons/browser-firefox.png b/images/jquery.dd/icons/browser-firefox.png
new file mode 100644
index 000000000..ce83d7b7e
Binary files /dev/null and b/images/jquery.dd/icons/browser-firefox.png differ
diff --git a/images/jquery.dd/icons/browser-msie.png b/images/jquery.dd/icons/browser-msie.png
new file mode 100644
index 000000000..e305bf6c6
Binary files /dev/null and b/images/jquery.dd/icons/browser-msie.png differ
diff --git a/images/jquery.dd/icons/browser-opera.png b/images/jquery.dd/icons/browser-opera.png
new file mode 100644
index 000000000..0b2c08bc6
Binary files /dev/null and b/images/jquery.dd/icons/browser-opera.png differ
diff --git a/images/jquery.dd/icons/browser-safari.png b/images/jquery.dd/icons/browser-safari.png
new file mode 100644
index 000000000..d4bcbbd69
Binary files /dev/null and b/images/jquery.dd/icons/browser-safari.png differ
diff --git a/images/jquery.dd/icons/button-large.gif b/images/jquery.dd/icons/button-large.gif
new file mode 100644
index 000000000..2d1d8c42f
Binary files /dev/null and b/images/jquery.dd/icons/button-large.gif differ
diff --git a/images/jquery.dd/icons/demoaction.jpg b/images/jquery.dd/icons/demoaction.jpg
new file mode 100644
index 000000000..d8e3aee14
Binary files /dev/null and b/images/jquery.dd/icons/demoaction.jpg differ
diff --git a/images/jquery.dd/icons/enabled.gif b/images/jquery.dd/icons/enabled.gif
new file mode 100644
index 000000000..5f3c6e571
Binary files /dev/null and b/images/jquery.dd/icons/enabled.gif differ
diff --git a/images/jquery.dd/icons/flagssprite_small.png b/images/jquery.dd/icons/flagssprite_small.png
new file mode 100644
index 000000000..5da7b5f85
Binary files /dev/null and b/images/jquery.dd/icons/flagssprite_small.png differ
diff --git a/images/jquery.dd/icons/giftlelo_dot_com.jpg b/images/jquery.dd/icons/giftlelo_dot_com.jpg
new file mode 100644
index 000000000..8f0db8bd8
Binary files /dev/null and b/images/jquery.dd/icons/giftlelo_dot_com.jpg differ
diff --git a/images/jquery.dd/icons/icon-search.gif b/images/jquery.dd/icons/icon-search.gif
new file mode 100644
index 000000000..88da1c93c
Binary files /dev/null and b/images/jquery.dd/icons/icon-search.gif differ
diff --git a/images/jquery.dd/icons/icon_calendar.gif b/images/jquery.dd/icons/icon_calendar.gif
new file mode 100644
index 000000000..6150729f4
Binary files /dev/null and b/images/jquery.dd/icons/icon_calendar.gif differ
diff --git a/images/jquery.dd/icons/icon_cart.gif b/images/jquery.dd/icons/icon_cart.gif
new file mode 100644
index 000000000..2239fa118
Binary files /dev/null and b/images/jquery.dd/icons/icon_cart.gif differ
diff --git a/images/jquery.dd/icons/icon_cd.gif b/images/jquery.dd/icons/icon_cd.gif
new file mode 100644
index 000000000..4f839bc4e
Binary files /dev/null and b/images/jquery.dd/icons/icon_cd.gif differ
diff --git a/images/jquery.dd/icons/icon_email.gif b/images/jquery.dd/icons/icon_email.gif
new file mode 100644
index 000000000..b9aeff79f
Binary files /dev/null and b/images/jquery.dd/icons/icon_email.gif differ
diff --git a/images/jquery.dd/icons/icon_faq.gif b/images/jquery.dd/icons/icon_faq.gif
new file mode 100644
index 000000000..0b8a477dd
Binary files /dev/null and b/images/jquery.dd/icons/icon_faq.gif differ
diff --git a/images/jquery.dd/icons/icon_games.gif b/images/jquery.dd/icons/icon_games.gif
new file mode 100644
index 000000000..95e349c0b
Binary files /dev/null and b/images/jquery.dd/icons/icon_games.gif differ
diff --git a/images/jquery.dd/icons/icon_lockopen.gif b/images/jquery.dd/icons/icon_lockopen.gif
new file mode 100644
index 000000000..dc99d4e5a
Binary files /dev/null and b/images/jquery.dd/icons/icon_lockopen.gif differ
diff --git a/images/jquery.dd/icons/icon_music.gif b/images/jquery.dd/icons/icon_music.gif
new file mode 100644
index 000000000..6980e6035
Binary files /dev/null and b/images/jquery.dd/icons/icon_music.gif differ
diff --git a/images/jquery.dd/icons/icon_phone.gif b/images/jquery.dd/icons/icon_phone.gif
new file mode 100644
index 000000000..30ec13eae
Binary files /dev/null and b/images/jquery.dd/icons/icon_phone.gif differ
diff --git a/images/jquery.dd/icons/icon_sales.gif b/images/jquery.dd/icons/icon_sales.gif
new file mode 100644
index 000000000..9032e8360
Binary files /dev/null and b/images/jquery.dd/icons/icon_sales.gif differ
diff --git a/images/jquery.dd/icons/icon_secure.gif b/images/jquery.dd/icons/icon_secure.gif
new file mode 100644
index 000000000..d3b0aacea
Binary files /dev/null and b/images/jquery.dd/icons/icon_secure.gif differ
diff --git a/images/jquery.dd/icons/icon_video.gif b/images/jquery.dd/icons/icon_video.gif
new file mode 100644
index 000000000..3f2cdbfb5
Binary files /dev/null and b/images/jquery.dd/icons/icon_video.gif differ
diff --git a/images/jquery.dd/icons/jquery-msdropdown.gif b/images/jquery.dd/icons/jquery-msdropdown.gif
new file mode 100644
index 000000000..6653e2a89
Binary files /dev/null and b/images/jquery.dd/icons/jquery-msdropdown.gif differ
diff --git a/images/jquery.dd/icons/msDropDown.gif b/images/jquery.dd/icons/msDropDown.gif
new file mode 100644
index 000000000..0d1e8f5df
Binary files /dev/null and b/images/jquery.dd/icons/msDropDown.gif differ
diff --git a/images/jquery.dd/icons/preview.gif b/images/jquery.dd/icons/preview.gif
new file mode 100644
index 000000000..d98b0b504
Binary files /dev/null and b/images/jquery.dd/icons/preview.gif differ
diff --git a/images/jquery.dd/icons/sprite.gif b/images/jquery.dd/icons/sprite.gif
new file mode 100644
index 000000000..8dd49e68a
Binary files /dev/null and b/images/jquery.dd/icons/sprite.gif differ
diff --git a/images/jquery.dd/icons/sprite.jpg b/images/jquery.dd/icons/sprite.jpg
new file mode 100644
index 000000000..b5d692bef
Binary files /dev/null and b/images/jquery.dd/icons/sprite.jpg differ
diff --git a/images/jquery.dd/icons/tick.gif b/images/jquery.dd/icons/tick.gif
new file mode 100644
index 000000000..5865c2246
Binary files /dev/null and b/images/jquery.dd/icons/tick.gif differ
diff --git a/images/jquery.dd/skin1/dd_arrow.gif b/images/jquery.dd/skin1/dd_arrow.gif
new file mode 100644
index 000000000..b069f4782
Binary files /dev/null and b/images/jquery.dd/skin1/dd_arrow.gif differ
diff --git a/images/jquery.dd/skin1/title-bg.gif b/images/jquery.dd/skin1/title-bg.gif
new file mode 100644
index 000000000..7533667ec
Binary files /dev/null and b/images/jquery.dd/skin1/title-bg.gif differ
diff --git a/images/jquery.dd/skin2/dd_arrow.gif b/images/jquery.dd/skin2/dd_arrow.gif
new file mode 100644
index 000000000..a7619f99d
Binary files /dev/null and b/images/jquery.dd/skin2/dd_arrow.gif differ
diff --git a/images/jquery.dd/skin2/icon-ok.gif b/images/jquery.dd/skin2/icon-ok.gif
new file mode 100644
index 000000000..8323baaa6
Binary files /dev/null and b/images/jquery.dd/skin2/icon-ok.gif differ
diff --git a/images/jquery.dd/skin2/title-bg.gif b/images/jquery.dd/skin2/title-bg.gif
new file mode 100644
index 000000000..ac143954f
Binary files /dev/null and b/images/jquery.dd/skin2/title-bg.gif differ
diff --git a/js/Worldview.js b/js/Worldview.js
index 2dab168cb..24ff13e70 100644
--- a/js/Worldview.js
+++ b/js/Worldview.js
@@ -2,7 +2,33 @@
* Namespace: Worldview
*/
(function(ns) {
-
+
+ /**
+ * Constant: VERSION
+ * Release version string.
+ */
+ ns.VERSION = "0.4.0";
+
+ /**
+ * Function: namespace
+ * Defines a namespace under Worldview. Each argument is an object path
+ * delimited by periods. For each path item, an empty object is created if
+ * one does not yet exist. For example:
+ *
+ * (begin code)
+ * Worldview.namespace("foo.bar");
+ * (end code)
+ *
+ * If Worldview.foo does not exist, it wil be created with an empty object.
+ * If Worldview.foo.bar does not exist, it will be created with an empty
+ * object.
+ *
+ * Parameters:
+ * (varargs) - Object path as a string, delimited by periods
+ *
+ * Returns:
+ * The newly created namespace object.
+ */
ns.namespace = function() {
var obj;
for ( var i = 0; i < arguments.length; i++ ) {
@@ -14,7 +40,54 @@
}
}
return obj;
- }
-
+ };
+
+ /**
+ * Function: log
+ * Logs a message to the browser console.
+ *
+ * Parameters:
+ * message - The message to log to the console.
+ */
+ ns.log = function(message) {
+ console.log(message);
+ };
+
+ /**
+ * Function: error
+ * Worldview general error handler. The error is reported to the browser
+ * console and, if the JavaScript library with YAHOO.widget.Panel is
+ * found, opens a notification panel for the end user.
+ *
+ * Parameters:
+ * message - Error message to display to the user
+ * cause - Description of the error that does not need to be shown to
+ * the user, usually the message of the exception that was
+ * caught.
+ */
+ ns.error = function(message, cause) {
+ ns.log("ERROR: " + message);
+ if ( cause !== undefined ) {
+ ns.log("Cause: " + cause);
+ }
+
+ if ( window.YAHOO && window.YAHOO.widget &&
+ window.YAHOO.widget.Panel ) {
+ o = new YAHOO.widget.Panel("WVerror", {
+ width: "300px",
+ zIndex: 1020,
+ visible: false
+ });
+ o.setHeader('&nbsp;&nbsp;&nbsp;&nbsp;Warning');
+ o.setBody(message);
+ o.render(document.body);
+ o.show();
+ o.center();
+ o.hideEvent.subscribe(function(i) {
+ setTimeout(function() {o.destroy();}, 25);
+ });
+ }
+ };
+
})(window.Worldview = window.Worldview || {});
diff --git a/js/Worldview/Visual.js b/js/Worldview/Visual.js
index e60a727fd..25fbf83d1 100644
--- a/js/Worldview/Visual.js
+++ b/js/Worldview/Visual.js
@@ -28,11 +28,24 @@ $(function() {
//-------------------------------------------------------------------------
/**
- * Constant: CHECKERBOARD
+ * Property: checkerboard
* A canvas pattern of a gray checkerboard used to denote transparency.
*/
- ns.CHECKERBOARD = null;
+ ns.checkerboard = null;
+ /**
+ * Property: STOCK_PALETTE_ENDPOINT
+ * The relative URL to use when loading stock palette information.
+ */
+ ns.stockPaletteEndpoint = "data/palettes";
+
+ /**
+ * Property: stockPalettes
+ * An array of stock <Palettes> the user can choose from. This value is
+ * initially set to null. Call <loadStockPalettes> to set this value.
+ */
+ ns.stockPalettes = null;
+
/**
* Function: toLookup
* Converts a <Palette> to a <Lookup>. The lookup table is generated
@@ -93,7 +106,7 @@ $(function() {
var segmentDistance = (segmentLength !== 0) ?
(distance - begin.at) / segmentLength : 0;
- // Witin the cutoffs?
+ // Within the cutoffs?
if ( distance < min || distance > max ) {
lut.push(ns.ColorRGBA(0, 0, 0, 0));
} else if ( palette.type === "solid" ) {
@@ -273,6 +286,58 @@ $(function() {
Math.round(b * 255));
}
+ /**
+ * Function: loadStockPalettes
+ * Loads the stock <Palette> definitions from the web server. Palettes
+ * are loaded from the relative URL defined in <stockPaletteEndpoint> and
+ * are placed in <stockPalettes>. If palettes have already been loaded,
+ * this method only invokes the success callback.
+ *
+ * Parameters:
+ * - success: Callback executed after the palettes have been loaded. The
+ * callback should have no parameters. Obtain loaded palettes
+ * from <stockPalettes>.
+ * - error: Callback executed if there is an error loading the palettes.
+ * The callback should have two paraemters, the error message
+ * and the error status.
+ */
+ ns.loadStockPalettes = function(success, error) {
+
+ if ( ns.stockPalettes ) {
+ success();
+ return;
+ }
+
+ var palettesLoaded = function(palettes) {
+ // Generate images for the combo box selector.
+ var canvas = document.createElement("canvas");
+ canvas.width = 100;
+ canvas.height = 14;
+
+ for ( var i = 0; i < palettes.length; i ++ ) {
+ var palette = palettes[i];
+
+ ns.ColorBar({
+ canvas: canvas,
+ palette: palette
+ });
+ palette.image = canvas.toDataURL("image/png");
+ }
+ ns.stockPalettes = palettes;
+ success(palettes);
+ }
+
+ $.ajax({
+ url: ns.stockPaletteEndpoint,
+ dataType: "json",
+ success: palettesLoaded,
+ error: function(jqXHR, textStatus, errorThrown) {
+ error(errorThrown, textStatus);
+ }
+ });
+
+ }
+
//-------------------------------------------------------------------------
// Private
//-------------------------------------------------------------------------
@@ -295,7 +360,7 @@ $(function() {
g.fillRect(0, size, size, size);
g.fillRect(size, 0, size, size);
- ns.CHECKERBOARD = g.createPattern(canvas, "repeat");
+ ns.checkerboard = g.createPattern(canvas, "repeat");
}
// Static initialization
diff --git a/js/Worldview/Visual/ColorBar.js b/js/Worldview/Visual/ColorBar.js
index 479eb0478..66749f87d 100644
--- a/js/Worldview/Visual/ColorBar.js
+++ b/js/Worldview/Visual/ColorBar.js
@@ -57,9 +57,9 @@ Worldview.Visual.ColorBar = function(spec) {
* Property: background
*
* Canvas pattern to use as the background. If not specified,
- * <CHECKERBOARD> is used.
+ * <checkerboard> is used.
*/
- self.background = spec.background || ns.CHECKERBOARD;
+ self.background = spec.background || ns.checkerboard;
/**
* Property: bins
diff --git a/js/Worldview/Visual/Palette.js b/js/Worldview/Visual/Palette.js
index d573e02dd..61d5f2b15 100644
--- a/js/Worldview/Visual/Palette.js
+++ b/js/Worldview/Visual/Palette.js
@@ -44,17 +44,14 @@ Worldview.namespace("Visual");
* });
* (end code)
*
- */
-
+ * Constructor: Palette
+ * Creates a new instance.
+ *
+ * Parameters:
+ * spec - Accepts all properties as an associative array.
+ */
Worldview.Visual.Palette = function(spec) {
- /**
- * Constructor: Worldview.Visual.Palette
- * Creates a new instance.
- *
- * Parameters:
- * spec - Accepts all properties as an associative array.
- */
return {
/**
* Property: id
@@ -103,8 +100,8 @@ Worldview.Visual.Palette = function(spec) {
/**
* Property: stops
- * Array of color stops of type <Worldview.Visual.StopRGB>. If not
- * specified, this value is set to an emtpy array.
+ * Array of color stops of type <StopRGBA>. If not specified, this
+ * value is set to an emtpy array.
*/
stops: spec.stops || [],
};
diff --git a/js/Worldview/Visual/PaletteSelector.js b/js/Worldview/Visual/PaletteSelector.js
new file mode 100644
index 000000000..0210fb416
--- /dev/null
+++ b/js/Worldview/Visual/PaletteSelector.js
@@ -0,0 +1,125 @@
+/*
+ * NASA Worldview
+ *
+ * This code was originally developed at NASA/Goddard Space Flight Center for
+ * the Earth Science Data and Information System (ESDIS) project.
+ *
+ * Copyright (C) 2013 United States Government as represented by the
+ * Administrator of the National Aeronautics and Space Administration.
+ * All Rights Reserved.
+ */
+
+Worldview.namespace("Visual");
+
+/**
+ * Class: Worldview.Visual.PaletteSelector
+ * Combo box to select a color palette. This uses
+ * <msDropDown at http://www.marghoobsuleman.com/jquery-image-dropdownk> to
+ * render the combo box.
+ *
+ * Constructor: PaletteSelector
+ * Creates a new instance.
+ *
+ * Parameters:
+ * spec.selector - The jQuery selector of the container to render in.
+ * spec.palettes - Array of <Palettes> to display in the combo box.
+ */
+Worldview.Visual.PaletteSelector = function(spec) {
+
+ // This namespace
+ var ns = Worldview.Visual;
+
+ // Public exports
+ var self = {};
+
+ // The palettes to display in the combo box
+ var palettes = spec.palettes;
+
+ // Container to render in
+ var $container;
+
+ var dropDown;
+
+ // Listeners for selection events
+ var listeners = [];
+
+ //-------------------------------------------------------------------------
+ // Public
+ //-------------------------------------------------------------------------
+
+ var init = function() {
+ $container = $(spec.selector);
+ if ( $container.length === 0 ) {
+ throw "Container not found for PaletteSelector: " + spec.selector;
+ }
+
+ var items = [];
+ for ( var i = 0; i < palettes.length; i++ ) {
+ var palette = palettes[i];
+ var item = {
+ text: palette.name,
+ description: palette.description,
+ value: i,
+ image: palette.image
+ };
+ items.push(item);
+ }
+
+ dropDown = $container.msDropDown({
+ byJson: {
+ name: "Palettes",
+ data: items
+ }
+ }).data("dd");
+
+ $container.on("change", function() {
+ fireSelectionEvent(palettes[dropDown.selectedIndex]);
+ });
+ };
+
+ /**
+ * Method: select
+ * Selects an item in the selector by index. A selection event is fired
+ * after the value changes.
+ *
+ * Parameters:
+ * index - The index of the value to set.
+ */
+ self.select = function(index) {
+ dropDown.set("selectedIndex", index);
+
+ // Change event not fired on set, do it manually
+ fireSelectionEvent(palettes[dropDown.selectedIndex]);
+ }
+
+ /**
+ * Method: addSelectionListener
+ * Adds a listener for selection events.
+ *
+ * Parameters:
+ * listener - Function to call when an item is selected. The function is
+ * called with one parameter, the <Palette> that was selected. If no
+ * palette was selected, the passed in parameter is undefined.
+ */
+ self.addSelectionListener = function(listener) {
+ listeners.push(listener);
+ }
+
+ //-------------------------------------------------------------------------
+ // Private
+ //-------------------------------------------------------------------------
+
+ // Notifies all listeners on a selection event.
+ var fireSelectionEvent = function(item) {
+ for ( var i = 0; i < listeners.length; i++ ) {
+ var listener = listeners[i];
+ listener(item);
+ }
+ }
+
+ init();
+ return self;
+};
+
+
+
diff --git a/js/Worldview/Visual/StockPaletteSelector.js b/js/Worldview/Visual/StockPaletteSelector.js
deleted file mode 100644
index 310abc076..000000000
--- a/js/Worldview/Visual/StockPaletteSelector.js
+++ /dev/null
@@ -1,108 +0,0 @@
-/*
- * NASA Worldview
- *
- * This code was originally developed at NASA/Goddard Space Flight Center for
- * the Earth Science Data and Information System (ESDIS) project.
- *
- * Copyright (C) 2013 United States Government as represented by the
- * Administrator of the National Aeronautics and Space Administration.
- * All Rights Reserved.
- */
-
-Worldview.namespace("Visual");
-
-Worldview.Visual.StockPaletteSelector = function(spec) {
-
- // This namespace
- var ns = Worldview.Visual;
-
- // Public exports
- var self = {};
-
- var $container;
-
- var init = function() {
- $container = $(spec.selector);
- if ( !$container ) {
- throw new "No such container for StockPaletteSelector: " +
- $container;
- }
-
- $container.html("Loading...");
-
- ns.loadStockPalettes(palettesLoaded, serviceError);
- };
-
- var palettesLoaded = function() {
- var palettes = ns.STOCK_PALETTES;
- var items = [];
- for ( var i = 0; i < palettes.length; i++ ) {
- var palette = palettes[i];
- var item = {
- text: palette.name,
- description: palette.description,
- value: i,
- selected: i == 0,
- imageSrc: palette.image
- };
- items.push(item);
- }
- $container.ddslick({
- data: items,
- width: 300,
- imagePosition: "left",
- selectText: "Select a palette",
- onSelected: function(data) {
- console.log(data);
- }
- })
- };
-
- var serviceError = function(jqXHR, textStatus, errorThrown) {
- $container.html("ERROR: " + errorThrown);
- };
-
- init();
- return self;
-};
-
-
-Worldview.Visual.STOCK_PALETTE_ENDPOINT = "data/palettes";
-Worldview.Visual.STOCK_PALETTES = null;
-
-Worldview.Visual.loadStockPalettes = function(success, error) {
-
- var ns = Worldview.Visual;
-
- if ( Worldview.Visual.STOCK_PALETTES ) {
- success();
- return;
- }
-
- var palettesLoaded = function(palettes) {
- ns.STOCK_PALETTES = palettes;
-
- var canvas = document.createElement("canvas");
- canvas.width = 100;
- canvas.height = 14;
-
- for ( var i = 0; i < palettes.length; i ++ ) {
- var palette = palettes[i];
- ns.ColorBar({
- canvas: canvas,
- palette: palette
- });
- palette.image = canvas.toDataURL("image/png");
- }
-
- success();
- }
-
- $.ajax({
- url: ns.STOCK_PALETTE_ENDPOINT,
- dataType: "json",
- success: palettesLoaded,
- error: error
- });
-
-}
diff --git a/js/ext/ddSlick-2.0/jquery.ddslick.min.js b/js/ext/ddSlick-2.0/jquery.ddslick.min.js
deleted file mode 100644
index c4447079b..000000000
--- a/js/ext/ddSlick-2.0/jquery.ddslick.min.js
+++ /dev/null
@@ -1 +0,0 @@
-(function (a) { function g(a, b) { var c = a.data("ddslick"); var d = a.find(".dd-selected"), e = d.siblings(".dd-selected-value"), f = a.find(".dd-options"), g = d.siblings(".dd-pointer"), h = a.find(".dd-option").eq(b), k = h.closest("li"), l = c.settings, m = c.settings.data[b]; a.find(".dd-option").removeClass("dd-option-selected"); h.addClass("dd-option-selected"); c.selectedIndex = b; c.selectedItem = k; c.selectedData = m; if (l.showSelectedHTML) { d.html((m.imageSrc ? '<img class="dd-selected-image' + (l.imagePosition == "right" ? " dd-image-right" : "") + '" src="' + m.imageSrc + '" />' : "") + (m.text ? '<label class="dd-selected-text">' + m.text + "</label>" : "") + (m.description ? '<small class="dd-selected-description dd-desc' + (l.truncateDescription ? " dd-selected-description-truncated" : "") + '" >' + m.description + "</small>" : "")) } else d.html(m.text); e.val(m.value); c.original.val(m.value); a.data("ddslick", c); i(a); j(a); if (typeof l.onSelected == "function") { l.onSelected.call(this, c) } } function h(b) { var c = b.find(".dd-select"), d = c.siblings(".dd-options"), e = c.find(".dd-pointer"), f = d.is(":visible"); a(".dd-click-off-close").not(d).slideUp(50); a(".dd-pointer").removeClass("dd-pointer-up"); if (f) { d.slideUp("fast"); e.removeClass("dd-pointer-up") } else { d.slideDown("fast"); e.addClass("dd-pointer-up") } k(b) } function i(a) { a.find(".dd-options").slideUp(50); a.find(".dd-pointer").removeClass("dd-pointer-up").removeClass("dd-pointer-up") } function j(a) { var b = a.find(".dd-select").css("height"); var c = a.find(".dd-selected-description"); var d = a.find(".dd-selected-image"); if (c.length <= 0 && d.length > 0) { a.find(".dd-selected-text").css("lineHeight", b) } } function k(b) { b.find(".dd-option").each(function () { var c = a(this); var d = c.css("height"); var e = c.find(".dd-option-description"); var f = b.find(".dd-option-image"); if (e.length <= 0 && f.length > 0) { c.find(".dd-option-text").css("lineHeight", d) } }) } a.fn.ddslick = function (c) { if (b[c]) { return b[c].apply(this, Array.prototype.slice.call(arguments, 1)) } else if (typeof c === "object" || !c) { return b.init.apply(this, arguments) } else { a.error("Method " + c + " does not exists.") } }; var b = {}, c = { data: [], keepJSONItemsOnTop: false, width: 260, height: null, background: "#eee", selectText: "", defaultSelectedIndex: null, truncateDescription: true, imagePosition: "left", showSelectedHTML: true, clickOffToClose: true, onSelected: function () { } }, d = '<div class="dd-select"><input class="dd-selected-value" type="hidden" /><a class="dd-selected"></a><span class="dd-pointer dd-pointer-down"></span></div>', e = '<ul class="dd-options"></ul>', f = '<style id="css-ddslick" type="text/css">' + ".dd-select{ border-radius:2px; border:solid 1px #ccc; position:relative; cursor:pointer;}" + ".dd-desc { color:#aaa; display:block; overflow: hidden; font-weight:normal; line-height: 1.4em; }" + ".dd-selected{ overflow:hidden; display:block; padding:10px; font-weight:bold;}" + ".dd-pointer{ width:0; height:0; position:absolute; right:10px; top:50%; margin-top:-3px;}" + ".dd-pointer-down{ border:solid 5px transparent; border-top:solid 5px #000; }" + ".dd-pointer-up{border:solid 5px transparent !important; border-bottom:solid 5px #000 !important; margin-top:-8px;}" + ".dd-options{ border:solid 1px #ccc; border-top:none; list-style:none; box-shadow:0px 1px 5px #ddd; display:none; position:absolute; z-index:2000; margin:0; padding:0;background:#fff; overflow:auto;}" + ".dd-option{ padding:10px; display:block; border-bottom:solid 1px #ddd; overflow:hidden; text-decoration:none; color:#333; cursor:pointer;-webkit-transition: all 0.25s ease-in-out; -moz-transition: all 0.25s ease-in-out;-o-transition: all 0.25s ease-in-out;-ms-transition: all 0.25s ease-in-out; }" + ".dd-options > li:last-child > .dd-option{ border-bottom:none;}" + ".dd-option:hover{ background:#f3f3f3; color:#000;}" + ".dd-selected-description-truncated { text-overflow: ellipsis; white-space:nowrap; }" + ".dd-option-selected { background:#f6f6f6; }" + ".dd-option-image, .dd-selected-image { vertical-align:middle; float:left; margin-right:5px; max-width:64px;}" + ".dd-image-right { float:right; margin-right:15px; margin-left:5px;}" + ".dd-container{ position:relative;}​ .dd-selected-text { font-weight:bold}​</style>"; if (a("#css-ddslick").length <= 0) { a(f).appendTo("head") } b.init = function (b) { var b = a.extend({}, c, b); return this.each(function () { var c = a(this), f = c.data("ddslick"); if (!f) { var i = [], j = b.data; c.find("option").each(function () { var b = a(this), c = b.data(); i.push({ text: a.trim(b.text()), value: b.val(), selected: b.is(":selected"), description: c.description, imageSrc: c.imagesrc }) }); if (b.keepJSONItemsOnTop) a.merge(b.data, i); else b.data = a.merge(i, b.data); var k = c, l = a('<div id="' + c.attr("id") + '"></div>'); c.replaceWith(l); c = l; c.addClass("dd-container").append(d).append(e); var i = c.find(".dd-select"), m = c.find(".dd-options"); m.css({ width: b.width }); i.css({ width: b.width, background: b.background }); c.css({ width: b.width }); if (b.height != null) m.css({ height: b.height, overflow: "auto" }); a.each(b.data, function (a, c) { if (c.selected) b.defaultSelectedIndex = a; m.append("<li>" + '<a class="dd-option">' + (c.value ? ' <input class="dd-option-value" type="hidden" value="' + c.value + '" />' : "") + (c.imageSrc ? ' <img class="dd-option-image' + (b.imagePosition == "right" ? " dd-image-right" : "") + '" src="' + c.imageSrc + '" />' : "") + (c.text ? ' <label class="dd-option-text">' + c.text + "</label>" : "") + (c.description ? ' <small class="dd-option-description dd-desc">' + c.description + "</small>" : "") + "</a>" + "</li>") }); var n = { settings: b, original: k, selectedIndex: -1, selectedItem: null, selectedData: null }; c.data("ddslick", n); if (b.selectText.length > 0 && b.defaultSelectedIndex == null) { c.find(".dd-selected").html(b.selectText) } else { var o = b.defaultSelectedIndex != null && b.defaultSelectedIndex >= 0 && b.defaultSelectedIndex < b.data.length ? b.defaultSelectedIndex : 0; g(c, o) } c.find(".dd-select").on("click.ddslick", function () { h(c) }); c.find(".dd-option").on("click.ddslick", function () { g(c, a(this).closest("li").index()) }); if (b.clickOffToClose) { m.addClass("dd-click-off-close"); c.on("click.ddslick", function (a) { a.stopPropagation() }); a("body").on("click", function () { a(".dd-click-off-close").slideUp(50).siblings(".dd-select").find(".dd-pointer").removeClass("dd-pointer-up") }) } } }) }; b.select = function (b) { return this.each(function () { if (b.index) g(a(this), b.index) }) }; b.open = function () { return this.each(function () { var b = a(this), c = b.data("ddslick"); if (c) h(b) }) }; b.close = function () { return this.each(function () { var b = a(this), c = b.data("ddslick"); if (c) i(b) }) }; b.destroy = function () { return this.each(function () { var b = a(this), c = b.data("ddslick"); if (c) { var d = c.original; b.removeData("ddslick").unbind(".ddslick").replaceWith(d) } }) } })(jQuery)
\ No newline at end of file
diff --git a/js/ext/jquery.dd/jquery.dd.js b/js/ext/jquery.dd/jquery.dd.js
new file mode 100644
index 000000000..8448ad96b
--- /dev/null
+++ b/js/ext/jquery.dd/jquery.dd.js
@@ -0,0 +1,1482 @@
+// MSDropDown - jquery.dd.js
+// author: Marghoob Suleman - http://www.marghoobsuleman.com/
+// Date: 10 Nov, 2012
+// Version: 3.3
+// Revision: 22
+// web: www.marghoobsuleman.com
+/*
+// msDropDown is free jQuery Plugin: you can redistribute it and/or modify
+// it under the terms of the either the MIT License or the Gnu General Public License (GPL) Version 2
+*/
+var msBeautify = msBeautify || {};
+(function ($) {
+msBeautify = {
+ version: {msDropdown:'3.3'},
+ author: "Marghoob Suleman",
+ counter: 20,
+ debug: function (v) {
+ if (v !== false) {
+ $(".ddOutOfVision").css({height: 'auto', position: 'relative'});
+ } else {
+ $(".ddOutOfVision").css({height: '0px', position: 'absolute'});
+ }
+ },
+ oldDiv: '',
+ create: function (id, settings, type) {
+ type = type || "dropdown";
+ var data;
+ switch (type.toLowerCase()) {
+ case "dropdown":
+ case "select":
+ data = $(id).msDropdown(settings).data("dd");
+ break;
+ }
+ return data;
+ }
+};
+
+$.msDropDown = {};
+$.msDropdown = {};
+$.extend(true, $.msDropDown, msBeautify);
+$.extend(true, $.msDropdown, msBeautify);
+// make compatibiliy with old and new jquery
+if ($.fn.prop === undefined) {$.fn.prop = $.fn.attr;}
+if ($.fn.on === undefined) {$.fn.on = $.fn.bind;$.fn.off = $.fn.unbind;}
+if (typeof $.expr.createPseudo === 'function') {
+ //jQuery 1.8 or greater
+ $.expr[':'].Contains = $.expr.createPseudo(function (arg) {return function (elem) { return $(elem).text().toUpperCase().indexOf(arg.toUpperCase()) >= 0; }; });
+} else {
+ //lower version
+ $.expr[':'].Contains = function (a, i, m) {return $(a).text().toUpperCase().indexOf(m[3].toUpperCase()) >= 0; };
+}
+//dropdown class
+function dd(element, settings) {
+ var _settings = $.extend(true,{byJson: {data: null, selectedIndex: 0, name: null, size: 0, multiple: false, width: 250},
+ mainCSS: 'dd',
+ height: 120, //not using currently
+ visibleRows: 7,
+ rowHeight: 0,
+ showIcon: true,
+ zIndex: 9999,
+ useSprite: false,
+ animStyle: 'slideDown',
+ event:'click',
+ openDirection: 'auto', //auto || alwaysUp
+ jsonTitle: true,
+ style: '',
+ disabledOpacity: 0.7,
+ disabledOptionEvents: true,
+ childWidth:0,
+ enableCheckbox:false, //this needs to multiple or it will set element to multiple
+ checkboxNameSuffix:'_mscheck',
+ append:'',
+ prepend:'',
+ on: {create: null,open: null,close: null,add: null,remove: null,change: null,blur: null,click: null,dblclick: null,mousemove: null,mouseover: null,mouseout: null,focus: null,mousedown: null,mouseup: null}
+ }, settings);
+ var _this = this; //this class
+ var _holderId = {postElementHolder: '_msddHolder', postID: '_msdd', postTitleID: '_title',postTitleTextID: '_titleText', postChildID: '_child'};
+ var _styles = {dd:_settings.mainCSS, ddTitle: 'ddTitle', arrow: 'arrow arrowoff', ddChild: 'ddChild', ddTitleText: 'ddTitleText',disabled: 'disabled', enabled: 'enabled', ddOutOfVision: 'ddOutOfVision', borderTop: 'borderTop', noBorderTop: 'noBorderTop', selected: 'selected', divider: 'divider', optgroup: "optgroup", optgroupTitle: "optgroupTitle", description: "description", label: "ddlabel",hover: 'hover',disabledAll: 'disabledAll'};
+ var _styles_i = {li: '_msddli_',borderRadiusTp: 'borderRadiusTp',ddChildMore: 'border shadow',fnone: "fnone"};
+ var _isList = false, _isMultiple=false,_isDisabled=false, _cacheElement = {}, _element, _orginial = {}, _isOpen=false;
+ var DOWN_ARROW = 40, UP_ARROW = 38, LEFT_ARROW=37, RIGHT_ARROW=39, ESCAPE = 27, ENTER = 13, ALPHABETS_START = 47, SHIFT=16 , CONTROL = 17;
+ var _shiftHolded=false, _controlHolded=false,_lastTarget=null,_forcedTrigger=false, _oldSelected, _isCreated = false;
+ var _doc = document, _ua = window.navigator.userAgent, _isIE = _ua.match(/msie/i);
+ var msieversion = function()
+ {
+ var msie = _ua.indexOf("MSIE");
+ if ( msie > 0 ) { // If Internet Explorer, return version number
+ return parseInt (_ua.substring (msie+5, _ua.indexOf (".", msie)));
+ } else { // If another browser, return 0
+ return 0;
+ };
+ };
+ var _checkDataSetting = function() {
+ _settings.mainCSS = $("#"+_element).data("maincss") || _settings.mainCSS;
+ _settings.visibleRows = $("#"+_element).data("visiblerows") || _settings.visibleRows;
+ if($("#"+_element).data("showicon")==false) {_settings.showIcon = $("#"+_element).data("showicon");};
+ _settings.useSprite = $("#"+_element).data("usesprite") || _settings.useSprite;
+ _settings.animStyle = $("#"+_element).data("animstyle") || _settings.animStyle;
+ _settings.event = $("#"+_element).data("event") || _settings.event;
+ _settings.openDirection = $("#"+_element).data("opendirection") || _settings.openDirection;
+ _settings.jsonTitle = $("#"+_element).data("jsontitle") || _settings.jsonTitle;
+ _settings.disabledOpacity = $("#"+_element).data("disabledopacity") || _settings.disabledOpacity;
+ _settings.childWidth = $("#"+_element).data("childwidth") || _settings.childWidth;
+ _settings.enableCheckbox = $("#"+_element).data("enablecheckbox") || _settings.enableCheckbox;
+ _settings.checkboxNameSuffix = $("#"+_element).data("checkboxnamesuffix") || _settings.checkboxNameSuffix;
+ _settings.append = $("#"+_element).data("append") || _settings.append;
+ _settings.prepend = $("#"+_element).data("prepend") || _settings.prepend;
+ };
+ var getElement = function(ele) {
+ if (_cacheElement[ele] === undefined) {
+ _cacheElement[ele] = _doc.getElementById(ele);
+ }
+ return _cacheElement[ele];
+ };
+ var _getIndex = function(opt) {
+ var childid = _getPostID("postChildID");
+ return $("#"+childid + " li."+_styles_i.li).index(opt);
+ };
+ var _createByJson = function() {
+ if (_settings.byJson.data) {
+ var validData = ["description","image", "title"];
+ try {
+ if (!element.id) {
+ element.id = "dropdown"+msBeautify.counter;
+ };
+ _settings.byJson.data = eval(_settings.byJson.data);
+ //change element
+ var id = "msdropdown"+(msBeautify.counter++);
+ var obj = {};
+ obj.id = id;
+ obj.name = _settings.byJson.name || element.id; //its name
+ if (_settings.byJson.size>0) {
+ obj.size = _settings.byJson.size;
+ };
+ obj.multiple = _settings.byJson.multiple;
+ var oSelect = _createElement("select", obj);
+ for(var i=0;i<_settings.byJson.data.length;i++) {
+ var current = _settings.byJson.data[i];
+ var opt = new Option(current.text, current.value);
+ for(var p in current) {
+ if (p.toLowerCase() != 'text') {
+ var key = ($.inArray(p.toLowerCase(), validData)!=-1) ? "data-" : "";
+ opt.setAttribute(key+p, current[p]);
+ };
+ };
+ oSelect.options[i] = opt;
+ };
+ getElement(element.id).appendChild(oSelect);
+ oSelect.selectedIndex = _settings.byJson.selectedIndex;
+ $(oSelect).css({width: _settings.byJson.width+'px'});
+ //now change element for access other things
+ element = oSelect;
+ } catch(e) {
+ throw "There is an error in json data.";
+ };
+ };
+ };
+ var _construct = function() {
+ //set properties
+ _createByJson();
+ if (!element.id) {
+ element.id = "msdrpdd"+(msBeautify.counter++);
+ };
+ _element = element.id;
+ _this._element = _element;
+ _checkDataSetting();
+ _isDisabled = getElement(_element).disabled;
+ var useCheckbox = _settings.enableCheckbox;
+ if(Boolean(useCheckbox)===true) {
+ getElement(_element).multiple = true;
+ _settings.enableCheckbox = true;
+ };
+ _isList = (getElement(_element).size>1 || getElement(_element).multiple==true) ? true : false;
+ //trace("_isList "+_isList);
+ if (_isList) {_isMultiple = getElement(_element).multiple;};
+ _mergeAllProp();
+ //create layout
+ _createLayout();
+ //set ui prop
+ _updateProp("uiData", _getDataAndUI());
+ _updateProp("selectedOptions", $("#"+_element +" option:selected"));
+ var childid = _getPostID("postChildID");
+ _oldSelected = $("#" + childid + " li." + _styles.selected);
+
+ };
+ /********************************************************************************************/
+ var _getPostID = function (id) {
+ return _element+_holderId[id];
+ };
+ var _getInternalStyle = function(ele) {
+ var s = (ele.style === undefined) ? "" : ele.style.cssText;
+ return s;
+ };
+ var _parseOption = function(opt) {
+ var imagePath = '', title ='', description='', value=-1, text='', className='', imagecss = '';
+ if (opt !== undefined) {
+ var attrTitle = opt.title || "";
+ //data-title
+ if (attrTitle!="") {
+ var reg = /^\{.*\}$/;
+ var isJson = reg.test(attrTitle);
+ if (isJson && _settings.jsonTitle) {
+ var obj = eval("["+attrTitle+"]");
+ };
+ title = (isJson && _settings.jsonTitle) ? obj[0].title : title;
+ description = (isJson && _settings.jsonTitle) ? obj[0].description : description;
+ imagePath = (isJson && _settings.jsonTitle) ? obj[0].image : attrTitle;
+ imagecss = (isJson && _settings.jsonTitle) ? obj[0].imagecss : imagecss;
+ };
+
+ text = opt.text || '';
+ value = opt.value || '';
+ className = opt.className || "";
+ //ignore title attribute if playing with data tags
+ title = $(opt).prop("data-title") || $(opt).data("title") || (title || "");
+ description = $(opt).prop("data-description") || $(opt).data("description") || (description || "");
+ imagePath = $(opt).prop("data-image") || $(opt).data("image") || (imagePath || "");
+ imagecss = $(opt).prop("data-imagecss") || $(opt).data("imagecss") || (imagecss || "");
+
+ };
+ var o = {image: imagePath, title: title, description: description, value: value, text: text, className: className, imagecss:imagecss};
+ return o;
+ };
+ var _createElement = function(nm, attr, html) {
+ var tag = _doc.createElement(nm);
+ if (attr) {
+ for(var i in attr) {
+ switch(i) {
+ case "style":
+ tag.style.cssText = attr[i];
+ break;
+ default:
+ tag[i] = attr[i];
+ break;
+ };
+ };
+ };
+ if (html) {
+ tag.innerHTML = html;
+ };
+ return tag;
+ };
+ /********************************************************************************************/
+ /*********************** <layout> *************************************/
+ var _hideOriginal = function() {
+ var hidid = _getPostID("postElementHolder");
+ if ($("#"+hidid).length==0) {
+ var obj = {style: 'height: 0px;overflow: hidden;position: absolute;',className: _styles.ddOutOfVision};
+ obj.id = hidid;
+ var oDiv = _createElement("div", obj);
+ $("#"+_element).after(oDiv);
+ $("#"+_element).appendTo($("#"+hidid));
+ } else {
+ $("#"+hidid).css({height: 0,overflow: 'hidden',position: 'absolute'});
+ };
+ };
+ var _createWrapper = function () {
+ var obj = {
+ className: _styles.dd + " ddcommon borderRadius"
+ };
+ var styles = _getInternalStyle(getElement(_element));
+ var w = $("#" + _element).outerWidth();
+ obj.style = "width: " + w + "px;";
+ if (styles.length > 0) {
+ obj.style = obj.style + "" + styles;
+ };
+ obj.id = _getPostID("postID");
+ var oDiv = _createElement("div", obj);
+ return oDiv;
+ };
+ var _createTitle = function () {
+ var selectedOption;
+ if(getElement(_element).selectedIndex>=0) {
+ selectedOption = getElement(_element).options[getElement(_element).selectedIndex];
+ } else {
+ selectedOption = {value:'', text:''};
+ }
+ var spriteClass = "", selectedClass = "";
+ //check sprite
+ var useSprite = $("#"+_element).data("usesprite");
+ if(useSprite) { _settings.useSprite = useSprite; };
+ if (_settings.useSprite != false) {
+ spriteClass = " " + _settings.useSprite;
+ selectedClass = " " + selectedOption.className;
+ };
+ var oTitle = _createElement("div", {className: _styles.ddTitle + spriteClass + " " + _styles_i.borderRadiusTp});
+ //divider
+ var oDivider = _createElement("span", {className: _styles.divider});
+ //arrow
+ var oArrow = _createElement("span", {className: _styles.arrow});
+ //title Text
+ var titleid = _getPostID("postTitleID");
+ var oTitleText = _createElement("span", {className: _styles.ddTitleText + selectedClass, id: titleid});
+
+ var parsed = _parseOption(selectedOption);
+ var arrowPath = parsed.image;
+ var sText = parsed.text || "";
+ if (arrowPath != "" && _settings.showIcon) {
+ var oIcon = _createElement("img");
+ oIcon.src = arrowPath;
+ if(parsed.imagecss!="") {
+ oIcon.className = parsed.imagecss+" ";
+ };
+ };
+ var oTitleText_in = _createElement("span", {className: _styles.label}, sText);
+ oTitle.appendChild(oDivider);
+ oTitle.appendChild(oArrow);
+ if (oIcon) {
+ oTitleText.appendChild(oIcon);
+ };
+ oTitleText.appendChild(oTitleText_in);
+ oTitle.appendChild(oTitleText);
+ var oDescription = _createElement("span", {className: _styles.description}, parsed.description);
+ oTitleText.appendChild(oDescription);
+ return oTitle;
+ };
+ var _createFilterBox = function () {
+ var tid = _getPostID("postTitleTextID");
+ var sText = _createElement("input", {id: tid, type: 'text', value: '', autocomplete: 'off', className: 'text shadow borderRadius', style: 'display: none'});
+ return sText;
+ };
+ var _createChild = function (opt) {
+ var obj = {};
+ var styles = _getInternalStyle(opt);
+ if (styles.length > 0) {obj.style = styles; };
+ var css = (opt.disabled) ? _styles.disabled : _styles.enabled;
+ css = (opt.selected) ? (css + " " + _styles.selected) : css;
+ css = css + " " + _styles_i.li;
+ obj.className = css;
+ if (_settings.useSprite != false) {
+ obj.className = css + " " + opt.className;
+ };
+ var li = _createElement("li", obj);
+ var parsed = _parseOption(opt);
+ if (parsed.title != "") {
+ li.title = parsed.title;
+ };
+ var arrowPath = parsed.image;
+ if (arrowPath != "" && _settings.showIcon) {
+ var oIcon = _createElement("img");
+ oIcon.src = arrowPath;
+ if(parsed.imagecss!="") {
+ oIcon.className = parsed.imagecss+" ";
+ };
+ };
+ if (parsed.description != "") {
+ var oDescription = _createElement("span", {
+ className: _styles.description
+ }, parsed.description);
+ };
+ var sText = opt.text || "";
+ var oTitleText = _createElement("span", {
+ className: _styles.label
+ }, sText);
+ //checkbox
+ if(_settings.enableCheckbox===true) {
+ var chkbox = _createElement("input", {
+ type: 'checkbox', name:_element+_settings.checkboxNameSuffix+'[]', value:opt.value||""}); //this can be used for future
+ li.appendChild(chkbox);
+ if(_settings.enableCheckbox===true) {
+ chkbox.checked = (opt.selected) ? true : false;
+ };
+ };
+ if (oIcon) {
+ li.appendChild(oIcon);
+ };
+ li.appendChild(oTitleText);
+ if (oDescription) {
+ li.appendChild(oDescription);
+ } else {
+ if (oIcon) {
+ oIcon.className = oIcon.className+_styles_i.fnone;
+ };
+ };
+ var oClear = _createElement("div", {className: 'clear'});
+ li.appendChild(oClear);
+ return li;
+ };
+ var _createChildren = function () {
+ var childid = _getPostID("postChildID");
+ var obj = {className: _styles.ddChild + " ddchild_ " + _styles_i.ddChildMore, id: childid};
+ if (_isList == false) {
+ obj.style = "z-index: " + _settings.zIndex;
+ } else {
+ obj.style = "z-index:1";
+ };
+ var childWidth = $("#"+_element).data("childwidth") || _settings.childWidth;
+ if(childWidth) {
+ obj.style = (obj.style || "") + ";width:"+childWidth;
+ };
+ var oDiv = _createElement("div", obj);
+ var ul = _createElement("ul");
+ if (_settings.useSprite != false) {
+ ul.className = _settings.useSprite;
+ };
+ var allOptions = getElement(_element).children;
+ for (var i = 0; i < allOptions.length; i++) {
+ var current = allOptions[i];
+ var li;
+ if (current.nodeName.toLowerCase() == "optgroup") {
+ //create ul
+ li = _createElement("li", {className: _styles.optgroup});
+ var span = _createElement("span", {className: _styles.optgroupTitle}, current.label);
+ li.appendChild(span);
+ var optChildren = current.children;
+ var optul = _createElement("ul");
+ for (var j = 0; j < optChildren.length; j++) {
+ var opt_li = _createChild(optChildren[j]);
+ optul.appendChild(opt_li);
+ };
+ li.appendChild(optul);
+ } else {
+ li = _createChild(current);
+ };
+ ul.appendChild(li);
+ };
+ oDiv.appendChild(ul);
+ return oDiv;
+ };
+ var _childHeight = function (val) {
+ var childid = _getPostID("postChildID");
+ if (val) {
+ if (val == -1) { //auto
+ $("#"+childid).css({height: "auto", overflow: "auto"});
+ } else {
+ $("#"+childid).css("height", val+"px");
+ };
+ return false;
+ };
+ //else return height
+ var iHeight;
+ if (getElement(_element).options.length > _settings.visibleRows) {
+ var margin = parseInt($("#" + childid + " li:first").css("padding-bottom")) + parseInt($("#" + childid + " li:first").css("padding-top"));
+ if(_settings.rowHeight===0) {
+ $("#" + childid).css({visibility:'hidden',display:'block'}); //hack for first child
+ _settings.rowHeight = Math.round($("#" + childid + " li:first").height());
+ $("#" + childid).css({visibility:'visible'});
+ if(!_isList || _settings.enableCheckbox===true) {
+ $("#" + childid).css({display:'none'});
+ };
+ };
+ iHeight = ((_settings.rowHeight + margin) * _settings.visibleRows);
+ } else if (_isList) {
+ iHeight = $("#" + _element).height(); //get height from original element
+ };
+ return iHeight;
+ };
+ var _applyChildEvents = function () {
+ var childid = _getPostID("postChildID");
+ $("#" + childid).on("click", function (e) {
+ if (_isDisabled === true) return false;
+ //prevent body click
+ e.preventDefault();
+ e.stopPropagation();
+ if (_isList) {
+ _bind_on_events();
+ };
+ });
+ $("#" + childid + " li." + _styles.enabled).on("click", function (e) {
+ if(e.target.nodeName.toLowerCase() !== "input") {
+ _close(this);
+ };
+ });
+ $("#" + childid + " li." + _styles.enabled).on("mousedown", function (e) {
+ if (_isDisabled === true) return false;
+ _oldSelected = $("#" + childid + " li." + _styles.selected);
+ _lastTarget = this;
+ e.preventDefault();
+ e.stopPropagation();
+ //select current input
+ if(_settings.enableCheckbox===true) {
+ if(e.target.nodeName.toLowerCase() === "input") {
+ _controlHolded = true;
+ };
+ };
+ if (_isList === true) {
+ if (_isMultiple) {
+ if (_shiftHolded === true) {
+ $(this).addClass(_styles.selected);
+ var selected = $("#" + childid + " li." + _styles.selected);
+ var lastIndex = _getIndex(this);
+ if (selected.length > 1) {
+ var items = $("#" + childid + " li." + _styles_i.li);
+ var ind1 = _getIndex(selected[0]);
+ var ind2 = _getIndex(selected[1]);
+ if (lastIndex > ind2) {
+ ind1 = (lastIndex);
+ ind2 = ind2 + 1;
+ };
+ for (var i = Math.min(ind1, ind2); i <= Math.max(ind1, ind2); i++) {
+ var current = items[i];
+ if ($(current).hasClass(_styles.enabled)) {
+ $(current).addClass(_styles.selected);
+ };
+ };
+ };
+ } else if (_controlHolded === true) {
+ $(this).toggleClass(_styles.selected); //toggle
+ if(_settings.enableCheckbox===true) {
+ var checkbox = this.childNodes[0];
+ checkbox.checked = !checkbox.checked; //toggle
+ };
+ } else {
+ $("#" + childid + " li." + _styles.selected).removeClass(_styles.selected);
+ $("#" + childid + " input:checkbox").prop("checked", false);
+ $(this).addClass(_styles.selected);
+ if(_settings.enableCheckbox===true) {
+ this.childNodes[0].checked = true;
+ };
+ };
+ } else {
+ $("#" + childid + " li." + _styles.selected).removeClass(_styles.selected);
+ $(this).addClass(_styles.selected);
+ };
+ //fire event on mouseup
+ } else {
+ $("#" + childid + " li." + _styles.selected).removeClass(_styles.selected);
+ $(this).addClass(_styles.selected);
+ };
+ });
+ $("#" + childid + " li." + _styles.enabled).on("mouseenter", function (e) {
+ if (_isDisabled === true) return false;
+ e.preventDefault();
+ e.stopPropagation();
+ if (_lastTarget != null) {
+ if (_isMultiple) {
+ $(this).addClass(_styles.selected);
+ if(_settings.enableCheckbox===true) {
+ this.childNodes[0].checked = true;
+ };
+ };
+ };
+ });
+
+ $("#" + childid + " li." + _styles.enabled).on("mouseover", function (e) {
+ if (_isDisabled === true) return false;
+ $(this).addClass(_styles.hover);
+ });
+ $("#" + childid + " li." + _styles.enabled).on("mouseout", function (e) {
+ if (_isDisabled === true) return false;
+ $("#" + childid + " li." + _styles.hover).removeClass(_styles.hover);
+ });
+
+ $("#" + childid + " li." + _styles.enabled).on("mouseup", function (e) {
+ if (_isDisabled === true) return false;
+ e.preventDefault();
+ e.stopPropagation();
+ if(_settings.enableCheckbox===true) {
+ _controlHolded = false;
+ };
+ var selected = $("#" + childid + " li." + _styles.selected).length;
+ _forcedTrigger = (_oldSelected.length != selected || selected == 0) ? true : false;
+ _fireAfterItemClicked();
+ _unbind_on_events(); //remove old one
+ _bind_on_events();
+ _lastTarget = null;
+ });
+
+ /* options events */
+ if (_settings.disabledOptionEvents == false) {
+ $("#" + childid + " li." + _styles_i.li).on("click", function (e) {
+ if (_isDisabled === true) return false;
+ fireOptionEventIfExist(this, "click");
+ });
+ $("#" + childid + " li." + _styles_i.li).on("mouseenter", function (e) {
+ if (_isDisabled === true) return false;
+ fireOptionEventIfExist(this, "mouseenter");
+ });
+ $("#" + childid + " li." + _styles_i.li).on("mouseover", function (e) {
+ if (_isDisabled === true) return false;
+ fireOptionEventIfExist(this, "mouseover");
+ });
+ $("#" + childid + " li." + _styles_i.li).on("mouseout", function (e) {
+ if (_isDisabled === true) return false;
+ fireOptionEventIfExist(this, "mouseout");
+ });
+ $("#" + childid + " li." + _styles_i.li).on("mousedown", function (e) {
+ if (_isDisabled === true) return false;
+ fireOptionEventIfExist(this, "mousedown");
+ });
+ $("#" + childid + " li." + _styles_i.li).on("mouseup", function (e) {
+ if (_isDisabled === true) return false;
+ fireOptionEventIfExist(this, "mouseup");
+ });
+ };
+ };
+ var _removeChildEvents = function () {
+ var childid = _getPostID("postChildID");
+ $("#" + childid).off("click");
+ $("#" + childid + " li." + _styles.enabled).off("mouseenter");
+ $("#" + childid + " li." + _styles.enabled).off("click");
+ $("#" + childid + " li." + _styles.enabled).off("mouseover");
+ $("#" + childid + " li." + _styles.enabled).off("mouseout");
+ $("#" + childid + " li." + _styles.enabled).off("mousedown");
+ $("#" + childid + " li." + _styles.enabled).off("mouseup");
+ };
+ var _applyEvents = function () {
+ var id = _getPostID("postID");
+ var childid = _getPostID("postChildID");
+ $("#" + id).on(_settings.event, function (e) {
+ if (_isDisabled === true) return false;
+ fireEventIfExist("click");
+ //prevent body click
+ e.preventDefault();
+ e.stopPropagation();
+ _open(e);
+ });
+ _applyChildEvents();
+ $("#" + id).on("dblclick", on_dblclick);
+ $("#" + id).on("mousemove", on_mousemove);
+ $("#" + id).on("mouseenter", on_mouseover);
+ $("#" + id).on("mouseleave", on_mouseout);
+ $("#" + id).on("mousedown", on_mousedown);
+ $("#" + id).on("mouseup", on_mouseup);
+ };
+ //after create
+ var _fixedForList = function () {
+ var id = _getPostID("postID");
+ var childid = _getPostID("postChildID");
+ if (_isList === true && _settings.enableCheckbox===false) {
+ $("#" + id + " ." + _styles.ddTitle).hide();
+ $("#" + childid).css({display: 'block', position: 'relative'});
+ //_open();
+ } else {
+ if(_settings.enableCheckbox===false) {
+ _isMultiple = false; //set multiple off if this is not a list
+ };
+ $("#" + id + " ." + _styles.ddTitle).show();
+ $("#" + childid).css({display: 'none', position: 'absolute'});
+ //set value
+ var first = $("#" + childid + " li." + _styles.selected)[0];
+ $("#" + childid + " li." + _styles.selected).removeClass(_styles.selected);
+ var index = _getIndex($(first).addClass(_styles.selected));
+ _setValue(index);
+ };
+ _childHeight(_childHeight()); //get and set height
+ };
+ var _fixedForDisabled = function () {
+ var id = _getPostID("postID");
+ var opc = (_isDisabled == true) ? _settings.disabledOpacity : 1;
+ if (_isDisabled === true) {
+ $("#" + id).addClass(_styles.disabledAll);
+ } else {
+ $("#" + id).removeClass(_styles.disabledAll);
+ };
+ };
+ var _fixedSomeUI = function () {
+ //auto filter
+ var tid = _getPostID("postTitleTextID");
+ $("#" + tid).on("keyup", _applyFilters);
+ //if is list
+ _fixedForList();
+ _fixedForDisabled();
+ };
+ var _createLayout = function () {
+ var oDiv = _createWrapper();
+ var oTitle = _createTitle();
+ oDiv.appendChild(oTitle);
+ //auto filter box
+ var oFilterBox = _createFilterBox();
+ oDiv.appendChild(oFilterBox);
+
+ var oChildren = _createChildren();
+ oDiv.appendChild(oChildren);
+ $("#" + _element).after(oDiv);
+ _hideOriginal(); //hideOriginal
+ _fixedSomeUI();
+ _applyEvents();
+
+ var childid = _getPostID("postChildID");
+ //append
+ if(_settings.append!='') {
+ $("#" + childid).append(_settings.append);
+ };
+ //prepend
+ if(_settings.prepend!='') {
+ $("#" + childid).prepend(_settings.prepend);
+ };
+ if (typeof _settings.on.create == "function") {
+ _settings.on.create.apply(_this, arguments);
+ };
+ };
+ var _selectMutipleOptions = function (bySelected) {
+ var childid = _getPostID("postChildID");
+ var selected = bySelected || $("#" + childid + " li." + _styles.selected); //bySelected or by argument
+ for (var i = 0; i < selected.length; i++) {
+ var ind = _getIndex(selected[i]);
+ getElement(_element).options[ind].selected = "selected";
+ };
+ _setValue(selected);
+ };
+ var _fireAfterItemClicked = function () {
+ //console.log("_fireAfterItemClicked")
+ var childid = _getPostID("postChildID");
+ var selected = $("#" + childid + " li." + _styles.selected);
+ if (_isMultiple && (_shiftHolded || _controlHolded) || _forcedTrigger) {
+ getElement(_element).selectedIndex = -1; //reset old
+ };
+ var index;
+ if (selected.length == 0) {
+ index = -1;
+ } else if (selected.length > 1) {
+ //selected multiple
+ _selectMutipleOptions(selected);
+ //index = $("#" + childid + " li." + _styles.selected);
+
+ } else {
+ //if one selected
+ index = _getIndex($("#" + childid + " li." + _styles.selected));
+ };
+ if ((getElement(_element).selectedIndex != index || _forcedTrigger) && selected.length<=1) {
+ _forcedTrigger = false;
+ var evt = has_handler("change");
+ getElement(_element).selectedIndex = index;
+ _setValue(index);
+ //local
+ if (typeof _settings.on.change == "function") {
+ var d = _getDataAndUI();
+ _settings.on.change(d.data, d.ui);
+ };
+ $("#" + _element).trigger("change");
+ };
+ };
+ var _setValue = function (index, byvalue) {
+ if (index !== undefined) {
+ var selectedIndex, value, selectedText;
+ if (index == -1) {
+ selectedIndex = -1;
+ value = "";
+ selectedText = "";
+ _updateTitleUI(-1);
+ } else {
+ //by index or byvalue
+ if (typeof index != "object") {
+ var opt = getElement(_element).options[index];
+ getElement(_element).selectedIndex = index;
+ selectedIndex = index;
+ value = _parseOption(opt);
+ selectedText = (index >= 0) ? getElement(_element).options[index].text : "";
+ _updateTitleUI(undefined, value);
+ value = value.value; //for bottom
+ } else {
+ //this is multiple or by option
+ selectedIndex = (byvalue && byvalue.index) || getElement(_element).selectedIndex;
+ value = (byvalue && byvalue.value) || getElement(_element).value;
+ selectedText = (byvalue && byvalue.text) || getElement(_element).options[getElement(_element).selectedIndex].text || "";
+ _updateTitleUI(selectedIndex);
+ };
+ };
+ _updateProp("selectedIndex", selectedIndex);
+ _updateProp("value", value);
+ _updateProp("selectedText", selectedText);
+ _updateProp("children", getElement(_element).children);
+ _updateProp("uiData", _getDataAndUI());
+ _updateProp("selectedOptions", $("#" + _element + " option:selected"));
+ };
+ };
+ var has_handler = function (name) {
+ //True if a handler has been added in the html.
+ var evt = {byElement: false, byJQuery: false, hasEvent: false};
+ var obj = $("#" + _element);
+ //console.log(name)
+ try {
+ //console.log(obj.prop("on" + name) + " "+name);
+ if (obj.prop("on" + name) !== null) {
+ evt.hasEvent = true;
+ evt.byElement = true;
+ };
+ } catch(e) {
+ //console.log(e.message);
+ }
+ // True if a handler has been added using jQuery.
+ var evs;
+ if (typeof $._data == "function") { //1.8
+ evs = $._data(obj[0], "events");
+ } else {
+ evs = obj.data("events");
+ };
+ if (evs && evs[name]) {
+ evt.hasEvent = true;
+ evt.byJQuery = true;
+ };
+ return evt;
+ };
+ var _bind_on_events = function () {
+ _unbind_on_events();
+ $("body").on("click", _close);
+ //bind more events
+ $(document).on("keydown", on_keydown);
+ $(document).on("keyup", on_keyup);
+ //focus will work on this
+ };
+ var _unbind_on_events = function () {
+ $("body").off("click", _close);
+ //bind more events
+ $(document).off("keydown", on_keydown);
+ $(document).off("keyup", on_keyup);
+ };
+ var _applyFilters = function () {
+ var childid = _getPostID("postChildID");
+ var tid = _getPostID("postTitleTextID");
+ var sText = getElement(tid).value;
+ if (sText.length == 0) {
+ $("#" + childid + " li:hidden").show(); //show if hidden
+ _childHeight(_childHeight());
+ } else {
+ $("#" + childid + " li").hide();
+ $("#" + childid + " li:Contains('" + sText + "')").show();
+ if ($("#" + childid + " li:visible").length <= _settings.visibleRows) {
+ _childHeight(-1); //set autoheight
+ };
+ };
+ };
+ var _showFilterBox = function () {
+ var tid = _getPostID("postTitleTextID");
+ if ($("#" + tid + ":hidden").length > 0 && _controlHolded == false) {
+ $("#" + tid + ":hidden").show().val("");
+ getElement(tid).focus();
+ };
+ };
+ var _hideFilterBox = function () {
+ var tid = _getPostID("postTitleTextID");
+ if ($("#" + tid + ":visible").length > 0) {
+ $("#" + tid + ":visible").hide();
+ getElement(tid).blur();
+ };
+ };
+ var on_keydown = function (evt) {
+ var tid = _getPostID("postTitleTextID");
+ var childid = _getPostID("postChildID");
+ switch (evt.keyCode) {
+ case DOWN_ARROW:
+ case RIGHT_ARROW:
+ evt.preventDefault();
+ evt.stopPropagation();
+ //_hideFilterBox();
+ _next();
+ break;
+ case UP_ARROW:
+ case LEFT_ARROW:
+ evt.preventDefault();
+ evt.stopPropagation();
+ //_hideFilterBox();
+ _previous();
+ break;
+ case ESCAPE:
+ case ENTER:
+ evt.preventDefault();
+ evt.stopPropagation();
+ _close();
+ var selected = $("#" + childid + " li." + _styles.selected).length;
+ _forcedTrigger = (_oldSelected.length != selected || selected == 0) ? true : false;
+ _fireAfterItemClicked();
+ _unbind_on_events(); //remove old one
+ _lastTarget = null;
+ break;
+ case SHIFT:
+ _shiftHolded = true;
+ break;
+ case CONTROL:
+ _controlHolded = true;
+ break;
+ default:
+ if (evt.keyCode >= ALPHABETS_START && _isList === false) {
+ _showFilterBox();
+ };
+ break;
+ };
+ if (_isDisabled === true) return false;
+ fireEventIfExist("keydown");
+ };
+ var on_keyup = function (evt) {
+ switch (evt.keyCode) {
+ case SHIFT:
+ _shiftHolded = false;
+ break;
+ case CONTROL:
+ _controlHolded = false;
+ break;
+ };
+ if (_isDisabled === true) return false;
+ fireEventIfExist("keyup");
+ };
+ var on_dblclick = function (evt) {
+ if (_isDisabled === true) return false;
+ fireEventIfExist("dblclick");
+ };
+ var on_mousemove = function (evt) {
+ if (_isDisabled === true) return false;
+ fireEventIfExist("mousemove");
+ };
+
+ var on_mouseover = function (evt) {
+ if (_isDisabled === true) return false;
+ evt.preventDefault();
+ fireEventIfExist("mouseover");
+ };
+ var on_mouseout = function (evt) {
+ if (_isDisabled === true) return false;
+ evt.preventDefault();
+ fireEventIfExist("mouseout");
+ };
+ var on_mousedown = function (evt) {
+ if (_isDisabled === true) return false;
+ fireEventIfExist("mousedown");
+ };
+ var on_mouseup = function (evt) {
+ if (_isDisabled === true) return false;
+ fireEventIfExist("mouseup");
+ };
+ var option_has_handler = function (opt, name) {
+ //True if a handler has been added in the html.
+ var evt = {byElement: false, byJQuery: false, hasEvent: false};
+ if ($(opt).prop("on" + name) != undefined) {
+ evt.hasEvent = true;
+ evt.byElement = true;
+ };
+ // True if a handler has been added using jQuery.
+ var evs = $(opt).data("events");
+ if (evs && evs[name]) {
+ evt.hasEvent = true;
+ evt.byJQuery = true;
+ };
+ return evt;
+ };
+ var fireOptionEventIfExist = function (li, evt_n) {
+ if (_settings.disabledOptionEvents == false) {
+ var opt = getElement(_element).options[_getIndex(li)];
+ //check if original has some
+ if (option_has_handler(opt, evt_n).hasEvent === true) {
+ if (option_has_handler(opt, evt_n).byElement === true) {
+ opt["on" + evt_n]();
+ };
+ if (option_has_handler(opt, evt_n).byJQuery === true) {
+ switch (evt_n) {
+ case "keydown":
+ case "keyup":
+ //key down/up will check later
+ break;
+ default:
+ $(opt).trigger(evt_n);
+ break;
+ };
+ };
+ return false;
+ };
+ };
+ };
+ var fireEventIfExist = function (evt_n) {
+ //local
+ if (typeof _settings.on[evt_n] == "function") {
+ _settings.on[evt_n].apply(this, arguments);
+ };
+ //check if original has some
+ if (has_handler(evt_n).hasEvent === true) {
+ if (has_handler(evt_n).byElement === true) {
+ getElement(_element)["on" + evt_n]();
+ };
+ if (has_handler(evt_n).byJQuery === true) {
+ switch (evt_n) {
+ case "keydown":
+ case "keyup":
+ //key down/up will check later
+ break;
+ default:
+ $("#" + _element).trigger(evt_n);
+ break;
+ };
+ };
+ return false;
+ };
+ };
+ /******************************* navigation **********************************************/
+ var _scrollToIfNeeded = function (opt) {
+ var childid = _getPostID("postChildID");
+ //if scroll is needed
+ opt = (opt !== undefined) ? opt : $("#" + childid + " li." + _styles.selected);
+ if (opt.length > 0) {
+ var pos = parseInt(($(opt).position().top));
+ var ch = parseInt($("#" + childid).height());
+ if (pos > ch) {
+ var top = pos + $("#" + childid).scrollTop() - (ch/2);
+ $("#" + childid).animate({scrollTop:top}, 500);
+ };
+ };
+ };
+ var _next = function () {
+ var childid = _getPostID("postChildID");
+ var items = $("#" + childid + " li:visible." + _styles_i.li);
+ var selected = $("#" + childid + " li:visible." + _styles.selected);
+ selected = (selected.length==0) ? items[0] : selected;
+ var index = $("#" + childid + " li:visible." + _styles_i.li).index(selected);
+ if ((index < items.length - 1)) {
+ index = getNext(index);
+ if (index < items.length) { //check again - hack for last disabled
+ if (!_shiftHolded || !_isList || !_isMultiple) {
+ $("#" + childid + " ." + _styles.selected).removeClass(_styles.selected);
+ };
+ $(items[index]).addClass(_styles.selected);
+ _updateTitleUI(index);
+ if (_isList == true) {
+ _fireAfterItemClicked();
+ };
+ _scrollToIfNeeded($(items[index]));
+ };
+ if (!_isList) {
+ _adjustOpen();
+ };
+ };
+ function getNext(ind) {
+ ind = ind + 1;
+ if (ind > items.length) {
+ return ind;
+ };
+ if ($(items[ind]).hasClass(_styles.enabled) === true) {
+ return ind;
+ };
+ return ind = getNext(ind);
+ };
+ };
+ var _previous = function () {
+ var childid = _getPostID("postChildID");
+ var selected = $("#" + childid + " li:visible." + _styles.selected);
+ var items = $("#" + childid + " li:visible." + _styles_i.li);
+ var index = $("#" + childid + " li:visible." + _styles_i.li).index(selected[0]);
+ if (index >= 0) {
+ index = getPrev(index);
+ if (index >= 0) { //check again - hack for disabled
+ if (!_shiftHolded || !_isList || !_isMultiple) {
+ $("#" + childid + " ." + _styles.selected).removeClass(_styles.selected);
+ };
+ $(items[index]).addClass(_styles.selected);
+ _updateTitleUI(index);
+ if (_isList == true) {
+ _fireAfterItemClicked();
+ };
+ if (parseInt(($(items[index]).position().top + $(items[index]).height())) <= 0) {
+ var top = ($("#" + childid).scrollTop() - $("#" + childid).height()) - $(items[index]).height();
+ $("#" + childid).animate({scrollTop: top}, 500);
+ };
+ };
+ if (!_isList) {
+ _adjustOpen();
+ };
+ };
+
+ function getPrev(ind) {
+ ind = ind - 1;
+ if (ind < 0) {
+ return ind;
+ };
+ if ($(items[ind]).hasClass(_styles.enabled) === true) {
+ return ind;
+ };
+ return ind = getPrev(ind);
+ };
+ };
+ var _adjustOpen = function () {
+ var id = _getPostID("postID");
+ var childid = _getPostID("postChildID");
+ var pos = $("#" + id).offset();
+ var mH = $("#" + id).height();
+ var wH = $(window).height();
+ var st = $(window).scrollTop();
+ var cH = $("#" + childid).height();
+ var top = $("#" + id).height(); //this close so its title height
+ if ((wH + st) < Math.floor(cH + mH + pos.top) || _settings.openDirection.toLowerCase() == 'alwaysup') {
+ top = cH;
+ $("#" + childid).css({top: "-" + top + "px", display: 'block', zIndex: _settings.zIndex});
+ $("#" + id).removeClass("borderRadius borderRadiusTp").addClass("borderRadiusBtm");
+ var top = $("#" + childid).offset().top;
+ if (top < -10) {
+ $("#" + childid).css({top: (parseInt($("#" + childid).css("top")) - top + 20 + st) + "px", zIndex: _settings.zIndex});
+ $("#" + id).removeClass("borderRadiusBtm borderRadiusTp").addClass("borderRadius");
+ };
+ } else {
+ $("#" + childid).css({top: top + "px", zIndex: _settings.zIndex});
+ $("#" + id).removeClass("borderRadius borderRadiusBtm").addClass("borderRadiusTp");
+ };
+ //hack for ie zindex
+ //i hate ie :D
+ if(_isIE) {
+ if(msieversion()<=7) {
+ $('div.ddcommon').css("zIndex", _settings.zIndex-10);
+ $("#" + id).css("zIndex", _settings.zIndex+5);
+ };
+ };
+ };
+ var _open = function (e) {
+ if (_isDisabled === true) return false;
+ var id = _getPostID("postID");
+ var childid = _getPostID("postChildID");
+ if (!_isOpen) {
+ _isOpen = true;
+ if (msBeautify.oldDiv != '') {
+ $("#" + msBeautify.oldDiv).css({display: "none"}); //hide all
+ };
+ msBeautify.oldDiv = childid;
+ $("#" + childid + " li:hidden").show(); //show if hidden
+ _adjustOpen();
+ var animStyle = _settings.animStyle;
+ if(animStyle=="" || animStyle=="none") {
+ $("#" + childid).css({display:"block"});
+ _scrollToIfNeeded();
+ if (typeof _settings.on.open == "function") {
+ var d = _getDataAndUI();
+ _settings.on.open(d.data, d.ui);
+ };
+ } else {
+ $("#" + childid)[animStyle]("fast", function () {
+ _scrollToIfNeeded();
+ if (typeof _settings.on.open == "function") {
+ var d = _getDataAndUI();
+ _settings.on.open(d.data, d.ui);
+ };
+ });
+ };
+ _bind_on_events();
+ } else {
+ if(_settings.event!=='mouseover') {
+ _close();
+ };
+ };
+ };
+ var _close = function (e) {
+ _isOpen = false;
+ var id = _getPostID("postID");
+ var childid = _getPostID("postChildID");
+ if (_isList === false || _settings.enableCheckbox===true) {
+ $("#" + childid).css({display: "none"});
+ $("#" + id).removeClass("borderRadiusTp borderRadiusBtm").addClass("borderRadius");
+ };
+ _unbind_on_events();
+ if (typeof _settings.on.close == "function") {
+ var d = _getDataAndUI();
+ _settings.on.close(d.data, d.ui);
+ };
+ //rest some old stuff
+ _hideFilterBox();
+ _childHeight(_childHeight()); //its needed after filter applied
+ $("#" + childid).css({zIndex:1})
+ };
+ /*********************** </layout> *************************************/
+ var _mergeAllProp = function () {
+ try {
+ _orginial = $.extend(true, {}, getElement(_element));
+ for (var i in _orginial) {
+ if (typeof _orginial[i] != "function") {
+ _this[i] = _orginial[i]; //properties
+ };
+ };
+ } catch(e) {
+ //silent
+ };
+ _this.selectedText = (getElement(_element).selectedIndex >= 0) ? getElement(_element).options[getElement(_element).selectedIndex].text : "";
+ _this.version = msBeautify.version.msDropdown;
+ _this.author = msBeautify.author;
+ };
+ var _getDataAndUIByOption = function (opt) {
+ if (opt != null && typeof opt != "undefined") {
+ var childid = _getPostID("postChildID");
+ var data = _parseOption(opt);
+ var ui = $("#" + childid + " li." + _styles_i.li + ":eq(" + (opt.index) + ")");
+ return {data: data, ui: ui, option: opt, index: opt.index};
+ };
+ return null;
+ };
+ var _getDataAndUI = function () {
+ var childid = _getPostID("postChildID");
+ var ele = getElement(_element);
+ var data, ui, option, index;
+ if (ele.selectedIndex == -1) {
+ data = null;
+ ui = null;
+ option = null;
+ index = -1;
+ } else {
+ ui = $("#" + childid + " li." + _styles.selected);
+ if (ui.length > 1) {
+ var d = [], op = [], ind = [];
+ for (var i = 0; i < ui.length; i++) {
+ var pd = _getIndex(ui[i]);
+ d.push(pd);
+ op.push(ele.options[pd]);
+ };
+ data = d;
+ option = op;
+ index = d;
+ } else {
+ option = ele.options[ele.selectedIndex];
+ data = _parseOption(option);
+ index = ele.selectedIndex;
+ };
+ };
+ return {data: data, ui: ui, index: index, option: option};
+ };
+ var _updateTitleUI = function (index, byvalue) {
+ var titleid = _getPostID("postTitleID");
+ var value = {};
+ if (index == -1) {
+ value.text = "&nbsp;";
+ value.className = "";
+ value.description = "";
+ value.image = "";
+ } else if (typeof index != "undefined") {
+ var opt = getElement(_element).options[index];
+ value = _parseOption(opt);
+ } else {
+ value = byvalue;
+ };
+ //update title and current
+ $("#" + titleid).find("." + _styles.label).html(value.text);
+ getElement(titleid).className = _styles.ddTitleText + " " + value.className;
+ //update desction
+ if (value.description != "") {
+ $("#" + titleid).find("." + _styles.description).html(value.description).show();
+ } else {
+ $("#" + titleid).find("." + _styles.description).html("").hide();
+ };
+ //update icon
+ var img = $("#" + titleid).find("img");
+ if (img.length > 0) {
+ $(img).remove();
+ };
+ if (value.image != "" && _settings.showIcon) {
+ img = _createElement("img", {src: value.image});
+ $("#" + titleid).prepend(img);
+ if(value.imagecss!="") {
+ img.className = value.imagecss+" ";
+ };
+ if (value.description == "") {
+ img.className = img.className+_styles_i.fnone;
+ };
+ };
+ };
+ var _updateProp = function (p, v) {
+ _this[p] = v;
+ };
+ var _updateUI = function (a, opt, i) { //action, index, opt
+ var childid = _getPostID("postChildID");
+ var wasSelected = false;
+ switch (a) {
+ case "add":
+ var li = _createChild(opt || getElement(_element).options[i]);
+ var index;
+ if (arguments.length == 3) {
+ index = i;
+ } else {
+ index = $("#" + childid + " li." + _styles_i.li).length - 1;
+ };
+ if (index < 0 || !index) {
+ $("#" + childid + " ul").append(li);
+ } else {
+ var at = $("#" + childid + " li." + _styles_i.li)[index];
+ $(at).before(li);
+ };
+ _removeChildEvents();
+ _applyChildEvents();
+ if (_settings.on.add != null) {
+ _settings.on.add.apply(this, arguments);
+ };
+ break;
+ case "remove":
+ wasSelected = $($("#" + childid + " li." + _styles_i.li)[i]).hasClass(_styles.selected);
+ $("#" + childid + " li." + _styles_i.li + ":eq(" + i + ")").remove();
+ var items = $("#" + childid + " li." + _styles.enabled);
+ if (wasSelected == true) {
+ if (items.length > 0) {
+ $(items[0]).addClass(_styles.selected);
+ var ind = $("#" + childid + " li." + _styles_i.li).index(items[0]);
+ _setValue(ind);
+ };
+ };
+ if (items.length == 0) {
+ _setValue(-1);
+ };
+ if ($("#" + childid + " li." + _styles_i.li).length < _settings.visibleRows && !_isList) {
+ _childHeight(-1); //set autoheight
+ };
+ if (_settings.on.remove != null) {
+ _settings.on.remove.apply(this, arguments);
+ };
+ break;
+ };
+ };
+ /************************** public methods/events **********************/
+ this.act = function () {
+ var action = arguments[0];
+ Array.prototype.shift.call(arguments);
+ switch (action) {
+ case "add":
+ _this.add.apply(this, arguments);
+ break;
+ case "remove":
+ _this.remove.apply(this, arguments);
+ break;
+ default:
+ try {
+ getElement(_element)[action].apply(getElement(_element), arguments);
+ } catch (e) {
+ //there is some error.
+ };
+ break;
+ };
+ };
+
+ this.add = function () {
+ var text, value, title, image, description;
+ var obj = arguments[0];
+ if (typeof obj == "string") {
+ text = obj;
+ value = text;
+ opt = new Option(text, value);
+ } else {
+ text = obj.text || '';
+ value = obj.value || text;
+ title = obj.title || '';
+ image = obj.image || '';
+ description = obj.description || '';
+ //image:imagePath, title:title, description:description, value:opt.value, text:opt.text, className:opt.className||""
+ opt = new Option(text, value);
+ $(opt).data("description", description);
+ $(opt).data("image", image);
+ $(opt).data("title", title);
+ };
+ arguments[0] = opt; //this option
+ getElement(_element).add.apply(getElement(_element), arguments);
+ _updateProp("children", getElement(_element)["children"]);
+ _updateProp("length", getElement(_element).length);
+ _updateUI("add", opt, arguments[1]);
+ };
+ this.remove = function (i) {
+ getElement(_element).remove(i);
+ _updateProp("children", getElement(_element)["children"]);
+ _updateProp("length", getElement(_element).length);
+ _updateUI("remove", undefined, i);
+ };
+ this.set = function (prop, val) {
+ if (typeof prop == "undefined" || typeof val == "undefined") return false;
+ prop = prop.toString();
+ try {
+ _updateProp(prop, val);
+ } catch (e) {/*this is ready only */};
+
+ switch (prop) {
+ case "size":
+ getElement(_element)[prop] = val;
+ if (val == 0) {
+ getElement(_element).multiple = false; //if size is zero multiple should be false
+ };
+ _isList = (getElement(_element).size > 1 || getElement(_element).multiple == true) ? true : false;
+ _fixedForList();
+ break;
+ case "multiple":
+ getElement(_element)[prop] = val;
+ _isList = (getElement(_element).size > 1 || getElement(_element).multiple == true) ? true : false;
+ _isMultiple = getElement(_element).multiple;
+ _fixedForList();
+ _updateProp(prop, val);
+ break;
+ case "disabled":
+ getElement(_element)[prop] = val;
+ _isDisabled = val;
+ _fixedForDisabled();
+ break;
+ case "selectedIndex":
+ case "value":
+ getElement(_element)[prop] = val;
+ var childid = _getPostID("postChildID");
+ $("#" + childid + " li." + _styles_i.li).removeClass(_styles.selected);
+ $($("#" + childid + " li." + _styles_i.li)[getElement(_element).selectedIndex]).addClass(_styles.selected);
+ _setValue(getElement(_element).selectedIndex);
+ break;
+ case "length":
+ var childid = _getPostID("postChildID");
+ if (val < getElement(_element).length) {
+ getElement(_element)[prop] = val;
+ if (val == 0) {
+ $("#" + childid + " li." + _styles_i.li).remove();
+ _setValue(-1);
+ } else {
+ $("#" + childid + " li." + _styles_i.li + ":gt(" + (val - 1) + ")").remove();
+ if ($("#" + childid + " li." + _styles.selected).length == 0) {
+ $("#" + childid + " li." + _styles.enabled + ":eq(0)").addClass(_styles.selected);
+ };
+ };
+ _updateProp(prop, val);
+ _updateProp("children", getElement(_element)["children"]);
+ };
+ break;
+ case "id":
+ //please i need this. so preventing to change it. will work on this later
+ break;
+ default:
+ //check if this is not a readonly properties
+ try {
+ getElement(_element)[prop] = val;
+ _updateProp(prop, val);
+ } catch (e) {
+ //silent
+ };
+ break;
+ }
+ };
+ this.get = function (prop) {
+ return _this[prop] || getElement(_element)[prop]; //return if local else from original
+ };
+ this.visible = function (val) {
+ var id = _getPostID("postID");
+ if (val === true) {
+ $("#" + id).show();
+ } else if (val === false) {
+ $("#" + id).hide();
+ } else {
+ return ($("#" + id).css("display")=="none") ? false : true;
+ };
+ };
+ this.debug = function (v) {
+ msBeautify.debug(v);
+ };
+ this.close = function () {
+ _close();
+ };
+ this.open = function () {
+ _open();
+ };
+ this.showRows = function (r) {
+ if (typeof r == "undefined" || r == 0) {
+ return false;
+ };
+ _settings.visibleRows = r;
+ _childHeight(_childHeight());
+ };
+ this.visibleRows = this.showRows;
+ this.on = function (type, fn) {
+ $("#" + _element).on(type, fn);
+ };
+ this.off = function (type, fn) {
+ $("#" + _element).off(type, fn);
+ };
+ this.addMyEvent = this.on;
+ this.getData = function () {
+ return _getDataAndUI()
+ };
+ this.namedItem = function () {
+ var opt = getElement(_element).namedItem.apply(getElement(_element), arguments);
+ return _getDataAndUIByOption(opt);
+ };
+ this.item = function () {
+ var opt = getElement(_element).item.apply(getElement(_element), arguments);
+ return _getDataAndUIByOption(opt);
+ };
+ //v 3.2
+ this.setIndexByValue = function(val) {
+ this.set("value", val);
+ };
+ this.destroy = function () {
+ var hidid = _getPostID("postElementHolder");
+ var id = _getPostID("postID");
+ $("#" + id + ", #" + id + " *").off();
+ $("#" + id).remove();
+ $("#" + _element).parent().replaceWith($("#" + _element));
+ $("#" + _element).data("dd", null);
+ };
+ //Create msDropDown
+ _construct();
+};
+//bind in jquery
+$.fn.extend({
+ msDropDown: function(settings)
+ {
+ return this.each(function()
+ {
+ if (!$(this).data('dd')){
+ var mydropdown = new dd(this, settings);
+ $(this).data('dd', mydropdown);
+ };
+ });
+ }
+});
+$.fn.msDropdown = $.fn.msDropDown; //make a copy
+})(jQuery);
\ No newline at end of file
diff --git a/test/Worldview/TestSuite/testPatcher.js b/test/Worldview/TestSuite/testPatcher.js
new file mode 100644
index 000000000..86e2f3983
--- /dev/null
+++ b/test/Worldview/TestSuite/testPatcher.js
@@ -0,0 +1,41 @@
+/*
+ * NASA Worldview
+ *
+ * This code was originally developed at NASA/Goddard Space Flight Center for
+ * the Earth Science Data and Information System (ESDIS) project.
+ *
+ * Copyright (C) 2013 United States Government as represented by the
+ * Administrator of the National Aeronautics and Space Administration.
+ * All Rights Reserved.
+ */
+
+TestCase("TestSuite.Patcher", {
+
+ setUp: function() {
+ Worldview.foo = "FOO";
+ },
+
+ tearDown: function() {
+ delete Worldview.foo;
+ },
+
+ // Check to see if a patch and undo are successful
+ testPatch: function() {
+ var patcher = TestSuite.Patcher();
+ patcher.apply("Worldview.foo", "BAR");
+ assertEquals("BAR", Worldview.foo);
+ patcher.undo();
+ assertEquals("FOO", Worldview.foo);
+ },
+
+ // Make sure when double patched, it returns to the original value
+ testPatchMultiple: function() {
+ var patcher = TestSuite.Patcher();
+ patcher.apply("Worldview.foo", "one");
+ patcher.apply("Worldview.foo", "two");
+ assertEquals("two", Worldview.foo);
+ patcher.undo();
+ assertEquals("FOO", Worldview.foo);
+ }
+});
+
diff --git a/test/Worldview/Visual/testColorBar.js b/test/Worldview/Visual/testColorBar.js
index e5a8d9b82..f65062579 100644
--- a/test/Worldview/Visual/testColorBar.js
+++ b/test/Worldview/Visual/testColorBar.js
@@ -8,7 +8,7 @@
* Administrator of the National Aeronautics and Space Administration.
* All Rights Reserved.
*/
-TestCase("Visual.ColorBar", {
+TestCase("Worldview.Visual.ColorBar", {
// This namespace
ns: null,
diff --git a/test/Worldview/Visual/testColorHSL.js b/test/Worldview/Visual/testColorHSL.js
index b91e8363f..fed85d5ac 100644
--- a/test/Worldview/Visual/testColorHSL.js
+++ b/test/Worldview/Visual/testColorHSL.js
@@ -8,7 +8,7 @@
* Administrator of the National Aeronautics and Space Administration.
* All Rights Reserved.
*/
-TestCase("Visual.ColorHSL", {
+TestCase("Worldview.Visual.ColorHSL", {
ns: null,
diff --git a/test/Worldview/Visual/testColorRGBA.js b/test/Worldview/Visual/testColorRGBA.js
index 0f14180a5..8cfe3ea0c 100644
--- a/test/Worldview/Visual/testColorRGBA.js
+++ b/test/Worldview/Visual/testColorRGBA.js
@@ -8,7 +8,7 @@
* Administrator of the National Aeronautics and Space Administration.
* All Rights Reserved.
*/
-TestCase("Visual.ColorRGBA", {
+TestCase("Worldview.Visual.ColorRGBA", {
ns: null,
diff --git a/test/Worldview/Visual/testPaletteSelector.js b/test/Worldview/Visual/testPaletteSelector.js
new file mode 100644
index 000000000..eb2c15ad5
--- /dev/null
+++ b/test/Worldview/Visual/testPaletteSelector.js
@@ -0,0 +1,84 @@
+/*
+ * NASA Worldview
+ *
+ * This code was originally developed at NASA/Goddard Space Flight Center for
+ * the Earth Science Data and Information System (ESDIS) project.
+ *
+ * Copyright (C) 2013 United States Government as represented by the
+ * Administrator of the National Aeronautics and Space Administration.
+ * All Rights Reserved.
+ */
+
+TestCase("Worldview.Visual.PaletteSelector", {
+
+ // This namespace
+ ns: null,
+
+ // Array of palettes
+ palettes: null,
+
+ setUp: function() {
+ ns = Worldview.Visual;
+
+ $(document.body).append("<div id='--test-palette-selector'></div>");
+
+ palettes = [{
+ id: "0",
+ name: "First",
+ stops: []
+ }, {
+ id: "1",
+ name: "Second",
+ stops: []
+ }];
+ },
+
+ // Make sure the object can be created
+ testValid: function() {
+ var selector = ns.PaletteSelector({
+ selector: "#--test-palette-selector",
+ palettes: palettes
+ });
+ },
+
+ // Check that an exception is raised if the container does not exist
+ testNoContainer: function() {
+ assertException(function() {
+ ns.PaletteSelector({
+ selector: "#foo",
+ palettes: palettes
+ });
+ });
+ },
+
+ // Check that an event is fired when selection is made and that it is
+ // the correct value.
+ testSelection: function() {
+ var selected;
+ var selector = ns.PaletteSelector({
+ selector: "#--test-palette-selector",
+ palettes: palettes
+ });
+ selector.addSelectionListener(function(item) {
+ selected = item;
+ });
+ selector.select(1);
+ assertEquals("Second", selected.name);
+ },
+
+ // Check that the event contains an undefined palette if the selection
+ // is out of bounds.
+ testSelectionOOB: function() {
+ var selected;
+ var selector = ns.PaletteSelector({
+ selector: "#--test-palette-selector",
+ palettes: palettes
+ });
+ selector.addSelectionListener(function(item) {
+ selected = item;
+ });
+ selector.select(100);
+ assertUndefined(selected);
+ }
+
+});
diff --git a/test/Worldview/Visual/testStopRGBA.js b/test/Worldview/Visual/testStopRGBA.js
index 9aca6acb0..d730c2e71 100644
--- a/test/Worldview/Visual/testStopRGBA.js
+++ b/test/Worldview/Visual/testStopRGBA.js
@@ -8,7 +8,7 @@
* Administrator of the National Aeronautics and Space Administration.
* All Rights Reserved.
*/
-TestCase("Visual.StopRGBA", {
+TestCase("Worldview.Visual.StopRGBA", {
ns: null,
diff --git a/test/Worldview/Visual/testToLookup.js b/test/Worldview/Visual/testToLookup.js
index ab86355f2..8b24f8650 100644
--- a/test/Worldview/Visual/testToLookup.js
+++ b/test/Worldview/Visual/testToLookup.js
@@ -8,7 +8,7 @@
* Administrator of the National Aeronautics and Space Administration.
* All Rights Reserved.
*/
-TestCase("Visual.toLookup", {
+TestCase("Worldview.Visual.toLookup", {
ns: null,
diff --git a/test/Worldview/Visual/testVisual.js b/test/Worldview/Visual/testVisual.js
index 0f4f50cf9..ca42ddffc 100644
--- a/test/Worldview/Visual/testVisual.js
+++ b/test/Worldview/Visual/testVisual.js
@@ -8,7 +8,7 @@
* Administrator of the National Aeronautics and Space Administration.
* All Rights Reserved.
*/
-TestCase("Visual", {
+TestCase("Worldview.Visual", {
ns: null,
@@ -18,8 +18,8 @@ TestCase("Visual", {
// Ensure the checkerboard got assigned to a value during initialization
testCheckerboard: function() {
- assertNotUndefined(ns.CHECKERBOARD);
- assertNotNull(ns.CHECKERBOARD);
+ assertNotUndefined(ns.checkerboard);
+ assertNotNull(ns.checkerboard);
},
// Check that a percentage of zero is at the beginning.
diff --git a/test/Worldview/testWorldview.js b/test/Worldview/testWorldview.js
new file mode 100644
index 000000000..e1746a3bf
--- /dev/null
+++ b/test/Worldview/testWorldview.js
@@ -0,0 +1,109 @@
+/*
+ * NASA Worldview
+ *
+ * This code was originally developed at NASA/Goddard Space Flight Center for
+ * the Earth Science Data and Information System (ESDIS) project.
+ *
+ * Copyright (C) 2013 United States Government as represented by the
+ * Administrator of the National Aeronautics and Space Administration.
+ * All Rights Reserved.
+ */
+
+TestCase("Worldview.namespace", {
+
+ tearDown: function() {
+ if ( Worldview.test) {
+ delete Worldview.test;
+ }
+ },
+
+ // Check that the namespace object gets created
+ testNamespace: function() {
+ assertUndefined(Worldview.test);
+ Worldview.namespace("test");
+ assertNotUndefined(Worldview.test);
+ },
+
+ // Check that all namespace objects get created
+ testNamespaceNesting: function() {
+ Worldview.namespace("test.one.two");
+ assertNotUndefined(Worldview.test);
+ assertNotUndefined(Worldview.test.one);
+ assertNotUndefined(Worldview.test.one.two);
+ },
+
+ // Check that a namespace object does not get clobbered when called agian.
+ testNamespaceNoClobber: function() {
+ Worldview.namespace("test");
+ Worldview.test.foo = "foo";
+ Worldview.namespace("test.baz");
+ assertEquals("foo", Worldview.test.foo);
+ }
+
+});
+
+TestCase("Worldview.error", {
+
+ patcher: null,
+ mockPanel: null,
+
+ setUp: function() {
+ // Mock out the panel that is displayed on an error
+ var mockPanelConstructor = mockFunction();
+ mockPanel = mock(YAHOO.widget.Panel);
+ mockPanel.hideEvent = {
+ subscribe: function() {}
+ };
+ when(mockPanelConstructor)(anything())
+ .thenReturn(mockPanel);
+
+ patcher = TestSuite.Patcher();
+ patcher.apply("Worldview.log", mockFunction());
+ patcher.apply("YAHOO.widget.Panel", mockPanelConstructor);
+ },
+
+ tearDown: function() {
+ patcher.undo();
+ },
+
+ // Check that error gets written to console
+ testErrorConsole: function() {
+ Worldview.error("This is an error");
+ verify(Worldview.log)("ERROR: This is an error");
+ },
+
+ // Check that error text gets placed in the dialog
+ testErrorPanel: function() {
+ Worldview.error("This is an error");
+ verify(mockPanel).setBody("This is an error");
+ },
+
+ // Check that error with cause is written to console
+ testErrorWithCause: function() {
+ Worldview.error("This is an error", "with a cause");
+ verify(Worldview.log)("ERROR: This is an error");
+ verify(Worldview.log)("Cause: with a cause");
+ },
+
+ // Check that the cause is not placed in the dialog
+ testErrorDialogNoCause: function() {
+ Worldview.error("This is an error", "with a cause");
+ verify(mockPanel).setBody("This is an error");
+ }
+
+});
+
+TestCase("Worldview.error.withoutYahoo", {
+
+ setUp: function() {
+ patcher.apply("Worldview.log", mockFunction());
+ patcher.apply("YAHOO", {});
+ },
+
+ // Make sure function still works without Yahoo.
+ testErrorConsole: function() {
+ Worldview.error("This is an error");
+ verify(Worldview.log)("ERROR: This is an error");
+ }
+
+});
diff --git a/test/jshamcrest.js b/test/ext/jshamcrest.js
similarity index 100%
rename from test/jshamcrest.js
rename to test/ext/jshamcrest.js
diff --git a/test/jsmockito-1.0.4.js b/test/ext/jsmockito-1.0.4.js
similarity index 100%
rename from test/jsmockito-1.0.4.js
rename to test/ext/jsmockito-1.0.4.js
diff --git a/test/harness.js b/test/harness.js
deleted file mode 100644
index e853f2cb1..000000000
--- a/test/harness.js
+++ /dev/null
@@ -1,24 +0,0 @@
-/*
- * NASA Worldview
- *
- * This code was originally developed at NASA/Goddard Space Flight Center for
- * the Earth Science Data and Information System (ESDIS) project.
- *
- * Copyright (C) 2013 United States Government as represented by the
- * Administrator of the National Aeronautics and Space Administration.
- * All Rights Reserved.
- */
-
-/*
- * Inform JsMockito that JsTestDriver is being used so it will know when
- * to clean up the mock objects.
- */
-JsHamcrest.Integration.JsTestDriver();
-JsMockito.Integration.JsTestDriver();
-
-/**
- * Required elements that must appear in the document
- */
-$(function() {
- $(document.body).append("<div id='map'></div>");
-});
\ No newline at end of file
diff --git a/test/jsTestDriver.conf b/test/jsTestDriver.conf
index 2c9323ec6..8fbf2dd42 100644
--- a/test/jsTestDriver.conf
+++ b/test/jsTestDriver.conf
@@ -2,17 +2,18 @@ server: http://localhost:8811
load:
- ../js/ext/jquery/jquery-1.6.4.js
- - jshamcrest.js
- - jsmockito-1.0.4.js
- - harness.js
+ - ext/jshamcrest.js
+ - ext/jsmockito-1.0.4.js
+ - lib/*.js
+ - lib/TestSuite/*.js
- ../js/ext/yui/yahoo-min.js
- ../js/ext/yui/event-min.js
- ../js/ext/jqueryui-1.8.16/jquery-ui.min.js
- - ../js/ext/jquery/jquery.mobile-1.0rc2.js
- ../js/ext/yui/combo-event-dragdrop-container-min.js
- ../js/ext/openlayers-2.12/OpenLayers.debug.js
- ../js/ext/datejs/date.js
- ../js/ext/jcrop/jcrop.js
+ - ../js/ext/jquery.dd/jquery.dd.js
- ../js/OpenLayers/Tile/Canvas.js
- ../js/component.js
- ../js/registry.js
@@ -36,6 +37,7 @@ test:
- OpenLayers/Tile/*.js
- Worldview/*.js
- Worldview/Visual/*.js
+ - Worldview/TestSuite/*.js
timeout: 30
\ No newline at end of file