Skip to content

Commit

Permalink
fix mapbbcode-window, finish wizard
Browse files Browse the repository at this point in the history
  • Loading branch information
Zverik committed Dec 19, 2013
1 parent 26fb89a commit 89dbbf5
Show file tree
Hide file tree
Showing 6 changed files with 279 additions and 143 deletions.
170 changes: 170 additions & 0 deletions _includes/codegen.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,170 @@
<script type="text/javascript" src="/lib/proprietary/Bing.js"></script>
<script type="text/javascript" src="/lib/proprietary/Google.js"></script>
<script type="text/javascript" src="/lib/proprietary/Yandex.js"></script>
<script type="text/javascript" src="/lib/proprietary/2GIS.js"></script>
<script type="text/javascript" src="/lib/proprietary/Nokia.js"></script>
<script type="text/javascript" src="/lib/proprietary/Esri.js"></script>
<script type="text/javascript">
var mapbb, config, form = document.forms['f'];
L.DomEvent.on(window, 'load', function() {
mapbb = new MapBBCode().options;
config = new MapBBCodeConfig({ layers: ['OpenStreetMap'] });
config.bindLayerAdder({
select: 'layers',
button: 'layeradd',
keyBlock: 'bingkey',
keyTitle: 'bingtitle',
keyValue: 'keyvalue',
keyBlockDisplay: 'inline'
});
config.on('show change', update);
config.show('map');

// todo: add update() listener to all input fields
var fields = document.getElementsByTagName('input');
for( var i = 0; i < fields.length; i++ ) {
L.DomEvent.on(fields[i], fields[i].type == 'text' ? 'change' : 'click', update);
}
L.DomEvent.on(form.elements['lang'], 'change', update);
});

function value(name) {
var el = form.elements[name];
if( el.length && el.length > 1 ) {
// radio buttons
for( var i = 0; i < el.length; i++ )
if( el[i].checked || el[i].selected )
return el[i].value;
}
return el.type == 'checkbox' ? el.checked : el.value; // todo: value
}

function quotes(str) {
return '"' + str.replace(/\\/g, '\\\\').replace(/"/g, '\\"') + '"';
}

function mapbbConfig() {
var res = {}, o = config.options, i,
std = 'defaultZoom,fullFromStart,fullViewHeight,viewWidth,viewHeight,editorHeight,windowWidth,windowHeight'.split(',');
if( !(o.layers.length == 1 && o.layers[0] == 'OpenStreetMap') )
res.layers = quotes(o.layers.join(','));
if( o.defaultPosition[0] != mapbb.defaultPosition[0] || o.defaultPosition[1] != mapbb.defaultPosition[1] )
res.defaultPosition = '[' + o.defaultPosition.join(', ') + ']';
for( i = 0; i < std.length; i++ ) {
var opt = std[i];
if( o[opt] != mapbb[opt] )
res[opt] = o[opt];
}

if( value('switcher') != mapbb.preferStandardLayerSwitcher )
res.preferStandardLayerSwitcher = value('switcher') ? 'true' : 'false';
if( value('outer') != mapbb.outerLinkTemplate )
res.outerLinkTemplate = quotes(value('outer'));
if( value('tags') != mapbb.allowedHTML )
res.allowedHTML = quotes(value('tags'));

if( value('upload') != mapbb.uploadButton )
res.uploadButton = value('upload') ? 'true' : 'false';
var shareurl = value('shareurl');
if( shareurl.length && shareurl.substring(shareurl.length - 1) != '/' )
shareurl += '/';
if( value('upload') && shareurl != mapbb.externalEndpoint )
res.externalEndpoint = quotes(shareurl);

return res;
}

function printOptions(res, indent) {
var indentStr = '', str = [];
if( indent )
while( indent-- > 0 )
indentStr += '\t';
for( var i in res )
if( res.hasOwnProperty(i) )
str.push(indentStr + '\t' + i + ': ' + (typeof res[i] === 'object' ? printOptions(res[i], (indent||0) + 1) : res[i]));
return str.length ? '{\n' + str.join(',\n') + '\n' + indentStr + '}' : '{}';
}

function findProprietary(layers) {
var res = {}, i, l;
for( i = 0; i < layers.length; i++ ) {
l = layers[i];
if( l == 'Bing' )
res.Bing = true;
else if( l.indexOf('Google') >= 0 )
res.Google = true;
else if( l.indexOf('Yandex') >= 0 )
res.Yandex = true;
else if( l.indexOf('2GIS') >= 0 )
res['2GIS'] = true;
else if( l.indexOf('Nokia') >= 0 )
res.Nokia = true;
else if( l.indexOf('Esri') >= 0 || l.indexOf('National G') >= 0 )
res.Esri = true;
}
var ar = [];
for( i in res )
ar.push(i);
return ar;
}

function update() {
form.elements['path'].disabled = document.getElementById('pathcdn1').checked;
form.elements['wpath'].disabled = value('wpathm');
form.elements['shareurl'].disabled = !value('upload');

var pathFixed = value('cdn') == '1' ? '//cdn.jsdelivr.net/mapbbcode/1.2.0/' : value('path');
if( pathFixed.length > 0 && pathFixed.substring(pathFixed.length - 1) !== '/' )
pathFixed += '/';
var bbcode = document.getElementById('example').checked ? '[map=14]57.7753,26.0316(Eesti); 57.7751,26.0204(Latvija);\n57.769,26.024 57.7719,26.0206 57.7742,26.0263 57.7815,26.0271[/map]' : false;
var str = '', i, mapbbcfg = mapbbConfig(), proprietary = findProprietary(config.options.layers);
mapbbcfg.windowPath = quotes(value('wpathm') == '1' ? pathFixed : value('wpath'));
if( value('loader') == '0' ) {
str += '<link rel="stylesheet" type="text/css" href="' + pathFixed + 'leaflet.css" />\n';
if( value('draw') )
str += '<link rel="stylesheet" type="text/css" href="' + pathFixed + 'leaflet.draw.css" />\n';
str += '<script type="text/javascript" src="' + pathFixed + 'leaflet.js"><' + '/script>\n';
if( value('draw') )
str += '<script type="text/javascript" src="' + pathFixed + 'leaflet.draw.js"><' + '/script>\n';
str += '<script type="text/javascript" src="' + pathFixed + 'mapbbcode.js"><' + '/script>\n';
if( !(config.options.layers.length == 1 && config.options.layers[0] == 'OpenStreetMap' ) )
str += '<script type="text/javascript" src="' + pathFixed + 'LayerList.js"><' + '/script>\n';
for( i = 0; i < proprietary.length; i++ )
str += '<script type="text/javascript" src="' + pathFixed + 'proprietary/' + proprietary[i] + '.js"><' + '/script>\n';
if( value('length') )
str += '<script type="text/javascript" src="' + pathFixed + 'Handler.Length.js"><' + '/script>\n';
if( value('lang') )
str += '<script type="text/javascript" src="' + pathFixed + 'lang/' + value('lang') + '.js"><' + '/script>\n';
if( bbcode )
str += '<div id="map"></div>\n';
str += '<script type="text/javascript">\nvar mapBB = new MapBBCode(' + printOptions(mapbbcfg) + ');\n';
if( bbcode )
str += 'mapBB.show("map", "' + bbcode.replace('\n', '" +\n\t"') + '");\n';
str += '<'+'/script>';
} else {
var lopt = { mapBBCodeOptions: mapbbcfg };
if( pathFixed !== 'mapbbcode/' )
lopt.path = quotes(pathFixed);
if( mapbbcfg.windowPath === quotes(pathFixed) )
delete mapbbcfg.windowPath;
if( value('lang') )
lopt.language = value('lang');
if( value('draw') )
lopt.draw = true;
if( value('length') )
lopt.addons = '["Handler.Length"]';
if( proprietary.length ) {
var p = [];
for( i = 0; i < proprietary.length; i++ )
p.push('"' + proprietary[i] + '"');
lopt.proprietary = '[' + p.join(', ') + ']';
}
str += '<script type="text/javascript" src="' + pathFixed + 'MapBBCodeLoader.min.js"><' + '/script>\n';
str += '<script type="text/javascript">mapBBCodeLoaderOptions.set(' + printOptions(lopt) + ');</' + '/script>';
if( bbcode )
str += '\n<div class="mapbbcode">' + bbcode + '</div>';
}
str = str.replace(/&/g, '&amp;').replace(/</g, '&lt;').replace(/>/g, '&gt;');
document.getElementById('code').innerHTML = str;
}
</script>
2 changes: 1 addition & 1 deletion lib/mapbbcode-window.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<script type="text/javascript" src="leaflet.draw.js"></script>
<script type="text/javascript" src="mapbbcode.js"></script>
<script type="text/javascript" src="LayerList.js"></script>
<script type="text/javascript" src="Bing.js"></script>
<script type="text/javascript" src="proprietary/Bing.js"></script>
<script type="text/javascript" src="Handler.Length.js"></script>
<style>html, body, #edit, .leaflet-container { margin: 0; height: 100%; }</style>
</head>
Expand Down
1 change: 1 addition & 0 deletions ru/toc.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ toc: true

Разработчикам:

* [Мастер настройки MapBBCode](wizard.html)
* [Руководство разработчика](../tutorial.html) (англ.)
* [Справочник по API](../api.html) (англ.)
* [Плагины для Leaflet](../leaflet.html) (англ.)
Expand Down
81 changes: 81 additions & 0 deletions ru/wizard.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
---
layout: guide
title: Мастер настройки MapBBCode
maplang: ru
---

<form action="#" name="f" onsubmit="javascript:return false;" style="margin-top: 1em;">
<div>
<input type="radio" name="loader" id="loader0" value="0" checked> <label for="loader0">Обычный MapBBCode</label>
<input type="radio" name="loader" id="loader1" value="1"> <label for="loader1">MapBBCode Loader</label>
</div>
<div>
<label for="path">Путь к библиотекам:</label>
<input type="radio" name="cdn" value="0" checked>
<input type="text" id="path" size="40" name="path" value="mapbbcode/">
<input type="radio" name="cdn" id="pathcdn1" value="1">
<label for="pathcdn1">CDN</label>
</div>
<div>
<label for="wpath">Путь к <code>mapbbcode-window.html</code>:</label>
<input type="text" id="wpath" size="30" name="wpath" value="mapbbcode/" disabled>
<input type="checkbox" id="wpathm" name="wpathm" checked> <label for="wpathm">рядом с MapBBCode</label>
</div>
<div>
<label for="lang">Язык:</label>
<select id="lang" size="1" name="lang">
<option value="">по умолчанию</option>
<option value="en">Английский</option>
<option value="ru">Русский</option>
</select>
</div>
<div>
<input type="checkbox" id="draw" name="draw">
<label for="draw">Добавить библиотеки для редактора</label>
</div>
<div>
<input type="checkbox" id="length" name="length">
<label for="length">Добавить модуль отображения длины линий</label>
</div>

<p>За описанием панели и настроек ниже обратитесь к <a href="admin.html">руководству администратора</a>.</p>

<div>
<select size="1" id="layers"></select> <input type="button" id="layeradd"/>
<span id="bingkey"><span id="bingtitle"></span> <input type="text" size="60" id="keyvalue"/></span>
</div>
<div id="map"></div>

<div style="margin-top: 1em;">
<input type="checkbox" id="switcher" name="switcher" checked>
<label for="switcher">Спрятать список слоёв за кнопкой</label>
</div>
<div>
<input type="checkbox" id="upload" name="upload">
<label for="upload">Позволить загрузку карт в MapBBCode Share</label>
</div>
<div>
<label for="shareurl">Адрес сервера MapBBCode Share:</label><br>
<input type="text" size="60" name="shareurl" id="shareurl" value="http://share.mapbbcode.org">
</div>
<div>
<label for="outer">Шаблон внешней ссылки, если нужна кнопка (параметры: {zoom}, {lat}, {lon}):</label><br>
<input type="text" size="60" name="outer" id="outer" value="">
</div>
<div>
<label for="tags">Допустимые HTML-теги во всплывающих панелях (регулярное выражение):</label><br>
<input type="text" size="60" name="tags" id="tags" value="[auib]|span|br|em|strong|tt">
</div>

</form>

<h2>Готовый код</h2>

<div>
<input type="checkbox" id="example" name="example">
<label for="example">Добавить пример карты</label>
</div>

<pre id="code"></pre>

{% include codegen.html %}
1 change: 1 addition & 0 deletions toc.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ On this website (please help us [translating](https://github.com/MapBBCode/mapbb

For developers:

* [Configuration Wizard](wizard.html)
* [Developer's Guide](tutorial.html)
* [API Reference](api.html)
* [Leaflet Plugins](leaflet.html)
Expand Down
Loading

0 comments on commit 89dbbf5

Please sign in to comment.