added themes deprecated or deleted at Hackathon 2016 in Berlin as they were at the 3.5 release
This commit is contained in:
parent
c39a9c812b
commit
aa199e931f
1344 changed files with 164625 additions and 0 deletions
2885
diabook/js/OpenLayers.js
Normal file
2885
diabook/js/OpenLayers.js
Normal file
File diff suppressed because one or more lines are too long
31
diabook/js/README
Normal file
31
diabook/js/README
Normal file
|
@ -0,0 +1,31 @@
|
|||
jQuery Resize Plugin Demo
|
||||
|
||||
Version: v2.1.1
|
||||
Author: Adeel Ejaz (http://adeelejaz.com/)
|
||||
License: Dual licensed under MIT and GPL licenses.
|
||||
|
||||
Introduction
|
||||
aeImageResize is a jQuery plugin to dynamically resize the images without distorting the proportions.
|
||||
|
||||
Usage:
|
||||
.aeImageResize( height, width )
|
||||
|
||||
height
|
||||
An integer representing the maximum height for the image.
|
||||
|
||||
width
|
||||
An integer representing the maximum width for the image.
|
||||
|
||||
Example
|
||||
$(function() {
|
||||
$( ".resizeme" ).aeImageResize({ height: 250, width: 250 });
|
||||
});
|
||||
|
||||
_______________________________________________________________________________________________
|
||||
|
||||
http://javascriptly.com/examples/jquery-grab-bag/autogrow-textarea.html
|
||||
|
||||
_______________________________________________________________________________________________
|
||||
|
||||
http://jquery.malsup.com/
|
||||
http://jquery.malsup.com/twitter/
|
13
diabook/js/jquery-ui.min.js
vendored
Normal file
13
diabook/js/jquery-ui.min.js
vendored
Normal file
File diff suppressed because one or more lines are too long
69
diabook/js/jquery.ae.image.resize.js
Normal file
69
diabook/js/jquery.ae.image.resize.js
Normal file
|
@ -0,0 +1,69 @@
|
|||
(function( $ ) {
|
||||
|
||||
$.fn.aeImageResize = function( params ) {
|
||||
|
||||
var aspectRatio = 0
|
||||
// Nasty I know but it's done only once, so not too bad I guess
|
||||
// Alternate suggestions welcome :)
|
||||
, isIE6 = $.browser.msie && (6 == ~~ $.browser.version)
|
||||
;
|
||||
|
||||
// We cannot do much unless we have one of these
|
||||
if ( !params.height && !params.width ) {
|
||||
return this;
|
||||
}
|
||||
|
||||
// Calculate aspect ratio now, if possible
|
||||
if ( params.height && params.width ) {
|
||||
aspectRatio = params.width / params.height;
|
||||
}
|
||||
|
||||
// Attach handler to load
|
||||
// Handler is executed just once per element
|
||||
// Load event required for Webkit browsers
|
||||
return this.one( "load", function() {
|
||||
|
||||
// Remove all attributes and CSS rules
|
||||
this.removeAttribute( "height" );
|
||||
this.removeAttribute( "width" );
|
||||
this.style.height = this.style.width = "";
|
||||
|
||||
var imgHeight = this.height
|
||||
, imgWidth = this.width
|
||||
, imgAspectRatio = imgWidth / imgHeight
|
||||
, bxHeight = params.height
|
||||
, bxWidth = params.width
|
||||
, bxAspectRatio = aspectRatio;
|
||||
|
||||
// Work the magic!
|
||||
// If one parameter is missing, we just force calculate it
|
||||
if ( !bxAspectRatio ) {
|
||||
if ( bxHeight ) {
|
||||
bxAspectRatio = imgAspectRatio + 1;
|
||||
} else {
|
||||
bxAspectRatio = imgAspectRatio - 1;
|
||||
}
|
||||
}
|
||||
|
||||
// Only resize the images that need resizing
|
||||
if ( (bxHeight && imgHeight > bxHeight) || (bxWidth && imgWidth > bxWidth) ) {
|
||||
|
||||
if ( imgAspectRatio > bxAspectRatio ) {
|
||||
bxHeight = ~~ ( imgHeight / imgWidth * bxWidth );
|
||||
} else {
|
||||
bxWidth = ~~ ( imgWidth / imgHeight * bxHeight );
|
||||
}
|
||||
|
||||
this.height = bxHeight;
|
||||
this.width = bxWidth;
|
||||
}
|
||||
})
|
||||
.each(function() {
|
||||
|
||||
// Trigger load event (for Gecko and MSIE)
|
||||
if ( this.complete || isIE6 ) {
|
||||
$( this ).trigger( "load" );
|
||||
}
|
||||
});
|
||||
};
|
||||
})( jQuery );
|
1
diabook/js/jquery.ae.image.resize.min.js
vendored
Normal file
1
diabook/js/jquery.ae.image.resize.min.js
vendored
Normal file
|
@ -0,0 +1 @@
|
|||
(function(d){d.fn.aeImageResize=function(a){var i=0,j=d.browser.msie&&6==~~d.browser.version;if(!a.height&&!a.width)return this;if(a.height&&a.width)i=a.width/a.height;return this.one("load",function(){this.removeAttribute("height");this.removeAttribute("width");this.style.height=this.style.width="";var e=this.height,f=this.width,g=f/e,b=a.height,c=a.width,h=i;h||(h=b?g+1:g-1);if(b&&e>b||c&&f>c){if(g>h)b=~~(e/f*c);else c=~~(f/e*b);this.height=b;this.width=c}}).each(function(){if(this.complete||j)d(this).trigger("load")})}})(jQuery);
|
46
diabook/js/jquery.autogrow.textarea.js
Normal file
46
diabook/js/jquery.autogrow.textarea.js
Normal file
|
@ -0,0 +1,46 @@
|
|||
(function($) {
|
||||
|
||||
/*
|
||||
* Auto-growing textareas; technique ripped from Facebook
|
||||
*/
|
||||
$.fn.autogrow = function(options) {
|
||||
|
||||
this.filter('textarea').each(function() {
|
||||
|
||||
var $this = $(this),
|
||||
minHeight = $this.height(),
|
||||
lineHeight = $this.css('lineHeight');
|
||||
|
||||
var shadow = $('<div></div>').css({
|
||||
position: 'absolute',
|
||||
top: -10000,
|
||||
left: -10000,
|
||||
width: $(this).width(),
|
||||
fontSize: $this.css('fontSize'),
|
||||
fontFamily: $this.css('fontFamily'),
|
||||
lineHeight: $this.css('lineHeight'),
|
||||
resize: 'none'
|
||||
}).appendTo(document.body);
|
||||
|
||||
var update = function() {
|
||||
|
||||
var val = this.value.replace(/</g, '<')
|
||||
.replace(/>/g, '>')
|
||||
.replace(/&/g, '&')
|
||||
.replace(/\n/g, '<br/>');
|
||||
|
||||
shadow.html(val);
|
||||
$(this).css('height', Math.max(shadow.height() + 20, minHeight));
|
||||
}
|
||||
|
||||
$(this).change(update).keyup(update).keydown(update);
|
||||
|
||||
update.apply(this);
|
||||
|
||||
});
|
||||
|
||||
return this;
|
||||
|
||||
}
|
||||
|
||||
})(jQuery);
|
47
diabook/js/jquery.cookie.js
Normal file
47
diabook/js/jquery.cookie.js
Normal file
|
@ -0,0 +1,47 @@
|
|||
/*!
|
||||
* jQuery Cookie Plugin
|
||||
* https://github.com/carhartl/jquery-cookie
|
||||
*
|
||||
* Copyright 2011, Klaus Hartl
|
||||
* Dual licensed under the MIT or GPL Version 2 licenses.
|
||||
* http://www.opensource.org/licenses/mit-license.php
|
||||
* http://www.opensource.org/licenses/GPL-2.0
|
||||
*/
|
||||
(function($) {
|
||||
$.cookie = function(key, value, options) {
|
||||
|
||||
// key and at least value given, set cookie...
|
||||
if (arguments.length > 1 && (!/Object/.test(Object.prototype.toString.call(value)) || value === null || value === undefined)) {
|
||||
options = $.extend({}, options);
|
||||
|
||||
if (value === null || value === undefined) {
|
||||
options.expires = -1;
|
||||
}
|
||||
|
||||
if (typeof options.expires === 'number') {
|
||||
var days = options.expires, t = options.expires = new Date();
|
||||
t.setDate(t.getDate() + days);
|
||||
}
|
||||
|
||||
value = String(value);
|
||||
|
||||
return (document.cookie = [
|
||||
encodeURIComponent(key), '=', options.raw ? value : encodeURIComponent(value),
|
||||
options.expires ? '; expires=' + options.expires.toUTCString() : '', // use expires attribute, max-age is not supported by IE
|
||||
options.path ? '; path=' + options.path : '',
|
||||
options.domain ? '; domain=' + options.domain : '',
|
||||
options.secure ? '; secure' : ''
|
||||
].join(''));
|
||||
}
|
||||
|
||||
// key and possibly options given, get cookie...
|
||||
options = value || {};
|
||||
var decode = options.raw ? function(s) { return s; } : decodeURIComponent;
|
||||
|
||||
var pairs = document.cookie.split('; ');
|
||||
for (var i = 0, pair; pair = pairs[i] && pairs[i].split('='); i++) {
|
||||
if (decode(pair[0]) === key) return decode(pair[1] || ''); // IE saves cookies with empty string as "c; ", e.g. without "=" as opposed to EOMB, thus pair[1] may be undefined
|
||||
}
|
||||
return null;
|
||||
};
|
||||
})(jQuery);
|
1485
diabook/js/jquery.mapquery.core.js
Normal file
1485
diabook/js/jquery.mapquery.core.js
Normal file
File diff suppressed because it is too large
Load diff
87
diabook/js/jquery.mapquery.legend.js
Normal file
87
diabook/js/jquery.mapquery.legend.js
Normal file
|
@ -0,0 +1,87 @@
|
|||
/* Copyright (c) 2011 by MapQuery Contributors (see AUTHORS for
|
||||
* full list of contributors). Published under the MIT license.
|
||||
* See https://github.com/mapquery/mapquery/blob/master/LICENSE for the
|
||||
* full text of the license. */
|
||||
|
||||
/**
|
||||
#jquery.mapquery.legend.js
|
||||
A plugin on mapquery.core to add a legend to a layer. It will check if the layer
|
||||
is within a valid extent and zoom range. And if not will return an error message.
|
||||
*/
|
||||
|
||||
(function($, MQ) {
|
||||
$.extend( $.fn.mapQuery.defaults.layer.all, {
|
||||
legend: {
|
||||
url: '',
|
||||
msg: ''
|
||||
}
|
||||
});
|
||||
//possible error messages to display in the legend
|
||||
LEGEND_ERRORS= ['E_ZOOMOUT', 'E_ZOOMIN', 'E_OUTSIDEBOX'];
|
||||
$.extend(MQ.Layer.prototype, {
|
||||
/**
|
||||
###**layer**.`legend([options])`
|
||||
_version added 0.1_
|
||||
####**Description**: get/set the legend of a layer
|
||||
|
||||
**options** url:url the url to the legend image
|
||||
|
||||
>Returns: {url:url, msg:'E\_ZOOMOUT' | 'E\_ZOOMIN' | 'E\_OUTSIDEBOX' | ''}
|
||||
|
||||
|
||||
The `.legend()` function allows us to attach a legend image to a layer. It will
|
||||
also check if the layer is not visible due to wrong extent or zoom level.
|
||||
It will return an error message which can be used to notify the user.
|
||||
|
||||
|
||||
var legend = layer.legend(); //get the current legend
|
||||
//set the legend url to legendimage.png
|
||||
layer.legend({url:'legendimage.png'})
|
||||
|
||||
*/
|
||||
//get/set the legend object
|
||||
legend: function(options) {
|
||||
//get the legend object
|
||||
var center = this.map.center();
|
||||
if (arguments.length===0) {
|
||||
this._checkZoom(center);
|
||||
//if zoom = ok, check box
|
||||
if(this.options.legend.msg==''){
|
||||
this._checkBox(center);
|
||||
}
|
||||
return this.options.legend;
|
||||
}
|
||||
//set the legend url
|
||||
if (options.url!==undefined) {
|
||||
this.options.legend.url = options.url;
|
||||
return this.options.legend;
|
||||
}
|
||||
},
|
||||
//Check if the layer has a maximum box set and if the current box
|
||||
//is outside these settings, set the legend.msg accordingly
|
||||
_checkBox: function(center){
|
||||
var maxExtent = this.options.maxExtent;
|
||||
if(maxExtent!==undefined) {
|
||||
var mapBounds = new OpenLayers.Bounds(
|
||||
center.box[0],center.box[1],center.box[2],center.box[3]);
|
||||
var layerBounds = new OpenLayers.Bounds(
|
||||
maxExtent[0],maxExtent[1],maxExtent[2],maxExtent[3]);
|
||||
var inside = layerBounds.containsBounds(mapBounds, true);
|
||||
this.options.legend.msg = inside?'':LEGEND_ERRORS[2];
|
||||
}
|
||||
},
|
||||
//Check if the layer has a minimum or maximum zoom set and if the
|
||||
//current zoom is outside these settings, set the legend.msg accordingly
|
||||
_checkZoom: function(center){
|
||||
var zoom = center.zoom;
|
||||
var maxZoom = this.options.maxZoom;
|
||||
var minZoom = this.options.minZoom;
|
||||
this.options.legend.msg=(
|
||||
maxZoom!==undefined&&maxZoom<zoom)? LEGEND_ERRORS[0]:'';
|
||||
this.options.legend.msg=(
|
||||
minZoom!==undefined&&minZoom>zoom)? LEGEND_ERRORS[1]:'';
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
})(jQuery, $.MapQuery);
|
310
diabook/js/jquery.mapquery.mqLayerManager.js
Normal file
310
diabook/js/jquery.mapquery.mqLayerManager.js
Normal file
|
@ -0,0 +1,310 @@
|
|||
/* Copyright (c) 2011 by MapQuery Contributors (see AUTHORS for
|
||||
* full list of contributors). Published under the MIT license.
|
||||
* See https://github.com/mapquery/mapquery/blob/master/LICENSE for the
|
||||
* full text of the license. */
|
||||
|
||||
/**
|
||||
#jquery.mapquery.mqLayerManager.js
|
||||
The file containing the mqLayerManager Widget
|
||||
|
||||
### *$('selector')*.`mqLayerManager([options])`
|
||||
_version added 0.1_
|
||||
####**Description**: create a widget to manage layers
|
||||
|
||||
+ **options**:
|
||||
- **map**: the mapquery instance
|
||||
- **title**: Title that will be displayed at the top of the
|
||||
layer manager (default: Layer Manager)
|
||||
|
||||
|
||||
>Returns: widget
|
||||
|
||||
>Requires: jquery.mapquery.legend.js
|
||||
|
||||
|
||||
The mqLayerManager allows us to control the order, opacity and visibility
|
||||
of layers. We can also remove layers. It also shows the legend of the layer if
|
||||
available and the error messages provided by the legend plugin. It listens to
|
||||
layerchange event for order, transparancy and opacity changes. It listens to
|
||||
addlayer and removelayer events to keep track which layers are on the map.
|
||||
|
||||
|
||||
$('#layermanager').mqLayerManager({map:'#map'});
|
||||
|
||||
|
||||
*/
|
||||
(function($) {
|
||||
$.template('mqLayerManager',
|
||||
'<div class="mq-layermanager ui-widget-content ">'+
|
||||
'</div>');
|
||||
|
||||
$.template('mqLayerManagerElement',
|
||||
'<div class="mq-layermanager-element ui-widget-content ui-corner-all" id="mq-layermanager-element-${id}">'+
|
||||
'<div class="mq-layermanager-element-header ui-dialog-titlebar ui-widget-header ui-corner-all ui-helper-clearfix">'+
|
||||
'<span class="mq-layermanager-label ui-dialog-title">${label}</span>'+
|
||||
'<a class="ui-dialog-titlebar-close ui-corner-all" href="#" role="button">'+
|
||||
'<span class="ui-icon ui-icon-closethick">close</span></a></div>'+
|
||||
'<div class="mq-layermanager-element-content">'+
|
||||
'<div class="mq-layermanager-element-visibility">'+
|
||||
'<input type="checkbox" class="mq-layermanager-element-vischeckbox" id="${id}-visibility" {{if visible}}checked="${visible}"{{/if}} />'+
|
||||
'<div class="mq-layermanager-element-slider-container">'+
|
||||
'<div class="mq-layermanager-element-slider"></div></div>'+
|
||||
'</div>'+
|
||||
'<div class="mq-layermanager-element-legend">'+
|
||||
'{{if imgUrl}}'+
|
||||
'<img src="${imgUrl}" style="opacity:${opacity}"/>'+
|
||||
'{{/if}}'+
|
||||
'{{if errMsg}}'+
|
||||
'${errMsg}'+
|
||||
'{{/if}}'+
|
||||
'</div>'+
|
||||
'</div>'+
|
||||
'</div>');
|
||||
|
||||
$.widget("mapQuery.mqLayerManager", {
|
||||
options: {
|
||||
// The MapQuery instance
|
||||
map: undefined,
|
||||
|
||||
// Title that will be displayed at the top of the popup
|
||||
title: "Layer Manager"
|
||||
},
|
||||
_create: function() {
|
||||
var map;
|
||||
var zoom;
|
||||
var numzoomlevels;
|
||||
var self = this;
|
||||
var element = this.element;
|
||||
|
||||
//get the mapquery object
|
||||
map = $(this.options.map).data('mapQuery');
|
||||
|
||||
this.element.addClass('ui-widget ui-helper-clearfix ' +
|
||||
'ui-corner-all');
|
||||
|
||||
var lmElement = $.tmpl('mqLayerManager').appendTo(element);
|
||||
element.find('.ui-icon-closethick').button();
|
||||
|
||||
lmElement.sortable({
|
||||
axis:'y',
|
||||
handle: '.mq-layermanager-element-header',
|
||||
update: function(event, ui) {
|
||||
var layerNodes = ui.item.siblings().andSelf();
|
||||
var num = layerNodes.length-1;
|
||||
layerNodes.each(function(i) {
|
||||
var layer = $(this).data('layer');
|
||||
var pos = num-i;
|
||||
self._position(layer, pos);
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
//these layers are already added to the map as such won't trigger
|
||||
//and event, we call the draw function directly
|
||||
$.each(map.layers().reverse(), function(){
|
||||
self._layerAdded(lmElement, this);
|
||||
});
|
||||
|
||||
element.delegate('.mq-layermanager-element-vischeckbox',
|
||||
'change',function() {
|
||||
var checkbox = $(this);
|
||||
var element = checkbox.parents('.mq-layermanager-element');
|
||||
var layer = element.data('layer');
|
||||
var self = element.data('self');
|
||||
self._visible(layer,checkbox.is(':checked'));
|
||||
});
|
||||
|
||||
element.delegate('.ui-icon-closethick', 'click', function() {
|
||||
var control = $(this).parents('.mq-layermanager-element');
|
||||
self._remove(control.data('layer'));
|
||||
});
|
||||
|
||||
//binding events
|
||||
map.bind("addlayer",
|
||||
{widget:self,control:lmElement},
|
||||
self._onLayerAdd);
|
||||
|
||||
map.bind("removelayer",
|
||||
{widget:self,control:lmElement},
|
||||
self._onLayerRemove);
|
||||
|
||||
map.bind("changelayer",
|
||||
{widget:self,map:map,control:lmElement},
|
||||
self._onLayerChange);
|
||||
|
||||
map.bind("moveend",
|
||||
{widget:self,map:map,control:lmElement},
|
||||
self._onMoveEnd);
|
||||
},
|
||||
_destroy: function() {
|
||||
this.element.removeClass(' ui-widget ui-helper-clearfix ' +
|
||||
'ui-corner-all')
|
||||
.empty();
|
||||
},
|
||||
//functions that actually change things on the map
|
||||
//call these from within the widget to do stuff on the map
|
||||
//their actions will trigger events on the map and in return
|
||||
//will trigger the _layer* functions
|
||||
_add: function(map,layer) {
|
||||
map.layers(layer);
|
||||
},
|
||||
|
||||
_remove: function(layer) {
|
||||
layer.remove();
|
||||
},
|
||||
|
||||
_position: function(layer, pos) {
|
||||
layer.position(pos);
|
||||
},
|
||||
|
||||
_visible: function(layer, vis) {
|
||||
layer.visible(vis);
|
||||
},
|
||||
|
||||
_opacity: function(layer,opac) {
|
||||
layer.opacity(opac);
|
||||
},
|
||||
|
||||
//functions that change the widget
|
||||
_layerAdded: function(widget, layer) {
|
||||
var self = this;
|
||||
var error = layer.legend().msg;
|
||||
var url;
|
||||
switch(error){
|
||||
case '':
|
||||
url =layer.legend().url;
|
||||
if(url==''){error='No legend for this layer';}
|
||||
break;
|
||||
case 'E_ZOOMOUT':
|
||||
error = 'Please zoom out to see this layer';
|
||||
break;
|
||||
case 'E_ZOOMIN':
|
||||
error = 'Please zoom in to see this layer';
|
||||
break;
|
||||
case 'E_OUTSIDEBOX':
|
||||
error = 'This layer is outside the current view';
|
||||
break;
|
||||
}
|
||||
|
||||
var layerElement = $.tmpl('mqLayerManagerElement',{
|
||||
id: layer.id,
|
||||
label: layer.label,
|
||||
position: layer.position(),
|
||||
visible: layer.visible(),
|
||||
imgUrl: url,
|
||||
opacity: layer.visible()?layer.opacity():0,
|
||||
errMsg: error
|
||||
})
|
||||
// save layer layer in the DOM, so we can easily
|
||||
// hide/show/delete the layer with live events
|
||||
.data('layer', layer)
|
||||
.data('self',self)
|
||||
.prependTo(widget);
|
||||
|
||||
$(".mq-layermanager-element-slider", layerElement).slider({
|
||||
max: 100,
|
||||
step: 1,
|
||||
value: layer.visible()?layer.opacity()*100:0,
|
||||
slide: function(event, ui) {
|
||||
var layer = layerElement.data('layer');
|
||||
var self = layerElement.data('self');
|
||||
self._opacity(layer,ui.value/100);
|
||||
},
|
||||
//using the slide event to check for the checkbox often gives errors.
|
||||
change: function(event, ui) {
|
||||
var layer = layerElement.data('layer');
|
||||
var self = layerElement.data('self');
|
||||
if(ui.value>=0.01) {
|
||||
if(!layer.visible()){layer.visible(true);}
|
||||
}
|
||||
if(ui.value<0.01) {
|
||||
if(layer.visible()){layer.visible(false);}
|
||||
}
|
||||
}
|
||||
});
|
||||
},
|
||||
|
||||
_layerRemoved: function(widget, id) {
|
||||
var control = $("#mq-layermanager-element-"+id);
|
||||
control.fadeOut(function() {
|
||||
$(this).remove();
|
||||
});
|
||||
},
|
||||
|
||||
_layerPosition: function(widget, layer) {
|
||||
var layerNodes = widget.element.find('.mq-layermanager-element');
|
||||
var num = layerNodes.length-1;
|
||||
var tmpNodes = [];
|
||||
tmpNodes.length = layerNodes.length;
|
||||
layerNodes.each(function() {
|
||||
var layer = $(this).data('layer');
|
||||
var pos = num-layer.position();
|
||||
tmpNodes[pos]= this;
|
||||
});
|
||||
for (i=0;i<tmpNodes.length;i++) {
|
||||
layerNodes.parent().append(tmpNodes[i]);
|
||||
}
|
||||
},
|
||||
|
||||
_layerVisible: function(widget, layer) {
|
||||
var layerElement =
|
||||
widget.element.find('#mq-layermanager-element-'+layer.id);
|
||||
var checkbox =
|
||||
layerElement.find('.mq-layermanager-element-vischeckbox');
|
||||
checkbox[0].checked = layer.visible();
|
||||
//update the opacity slider as well
|
||||
var slider = layerElement.find('.mq-layermanager-element-slider');
|
||||
var value = layer.visible()?layer.opacity()*100: 0;
|
||||
slider.slider('value',value);
|
||||
|
||||
//update legend image
|
||||
layerElement.find('.mq-layermanager-element-legend img').css(
|
||||
{visibility:layer.visible()?true:'hidden'});
|
||||
},
|
||||
|
||||
_layerOpacity: function(widget, layer) {
|
||||
var layerElement = widget.element.find(
|
||||
'#mq-layermanager-element-'+layer.id);
|
||||
var slider = layerElement.find(
|
||||
'.mq-layermanager-element-slider');
|
||||
slider.slider('value',layer.opacity()*100);
|
||||
//update legend image
|
||||
layerElement.find(
|
||||
'.mq-layermanager-element-legend img').css(
|
||||
{opacity:layer.opacity()});
|
||||
},
|
||||
|
||||
_moveEnd: function (widget,lmElement,map) {
|
||||
lmElement.empty();
|
||||
$.each(map.layers().reverse(), function(){
|
||||
widget._layerAdded(lmElement, this);
|
||||
});
|
||||
},
|
||||
|
||||
//functions bind to the map events
|
||||
_onLayerAdd: function(evt, layer) {
|
||||
evt.data.widget._layerAdded(evt.data.control,layer);
|
||||
},
|
||||
|
||||
_onLayerRemove: function(evt, layer) {
|
||||
evt.data.widget._layerRemoved(evt.data.control,layer.id);
|
||||
},
|
||||
|
||||
_onLayerChange: function(evt, layer, property) {
|
||||
switch(property) {
|
||||
case 'opacity':
|
||||
evt.data.widget._layerOpacity(evt.data.widget,layer);
|
||||
break;
|
||||
case 'position':
|
||||
evt.data.widget._layerPosition(evt.data.widget,layer);
|
||||
break;
|
||||
case 'visibility':
|
||||
evt.data.widget._layerVisible(evt.data.widget,layer);
|
||||
break;
|
||||
}
|
||||
},
|
||||
_onMoveEnd: function(evt) {
|
||||
evt.data.widget._moveEnd(evt.data.widget,evt.data.control,evt.data.map);
|
||||
}
|
||||
});
|
||||
})(jQuery);
|
92
diabook/js/jquery.mapquery.mqMousePosition.js
Normal file
92
diabook/js/jquery.mapquery.mqMousePosition.js
Normal file
|
@ -0,0 +1,92 @@
|
|||
/* Copyright (c) 2011 by MapQuery Contributors (see AUTHORS for
|
||||
* full list of contributors). Published under the MIT license.
|
||||
* See https://github.com/mapquery/mapquery/blob/master/LICENSE for the
|
||||
* full text of the license. */
|
||||
|
||||
/**
|
||||
#jquery.mapquery.mqMousePosition.js
|
||||
The file containing the mqMousePosition Widget
|
||||
|
||||
### *$('selector')*.`mqMousePosition([options])`
|
||||
_version added 0.1_
|
||||
####**Description**: create a widget to show the location under the mouse pointer
|
||||
|
||||
+ **options**
|
||||
- **map**: the mapquery instance
|
||||
- **precision**: the number of decimals (default 2)
|
||||
- **x**: the label for the x-coordinate (default x)
|
||||
- **y**: the label for the y-coordinate (default y)
|
||||
|
||||
|
||||
>Returns: widget
|
||||
|
||||
|
||||
The mqMousePosition allows us to show the coordinates under the mouse pointer
|
||||
|
||||
|
||||
$('#mousepointer').mqMousePointer({
|
||||
map: '#map'
|
||||
});
|
||||
|
||||
*/
|
||||
(function($) {
|
||||
$.template('mqMousePosition',
|
||||
'<div class="mq-mouseposition ui-widget ui-helper-clearfix ">'+
|
||||
'<span class="ui-widget-content ui-helper-clearfix ui-corner-all ui-corner-all">'+
|
||||
'<div id="mq-mouseposition-x" class="mq-mouseposition-coordinate">'+
|
||||
'</div><div id="mq-mouseposition-y" class="mq-mouseposition-coordinate">'+
|
||||
'</div></div></span>');
|
||||
|
||||
$.widget("mapQuery.mqMousePosition", {
|
||||
options: {
|
||||
// The MapQuery instance
|
||||
map: undefined,
|
||||
|
||||
// The number of decimals for the coordinates
|
||||
// default: 2
|
||||
// TODO: JCB20110630 use dynamic precision based on the pixel
|
||||
// resolution, no need to configure precision
|
||||
precision: 2,
|
||||
|
||||
// The label of the x-value
|
||||
// default: 'x'
|
||||
x: 'x',
|
||||
// The label of the y-value
|
||||
// default: 'y'
|
||||
y: 'y'
|
||||
|
||||
},
|
||||
_create: function() {
|
||||
//get the mapquery object
|
||||
this.map = $(this.options.map).data('mapQuery');
|
||||
|
||||
this.map.element.bind('mousemove', {widget: this}, this._onMousemove);
|
||||
$.tmpl('mqMousePosition', {}).appendTo(this.element);
|
||||
|
||||
},
|
||||
_destroy: function() {
|
||||
this.element.removeClass('ui-widget ui-helper-clearfix ' +
|
||||
'ui-corner-all')
|
||||
.empty();
|
||||
},
|
||||
_onMousemove: function(evt) {
|
||||
var self = evt.data.widget;
|
||||
var x = evt.pageX;
|
||||
var y = evt.pageY;
|
||||
var mapProjection = new OpenLayers.Projection(self.map.projection);
|
||||
var displayProjection = new OpenLayers.Projection(
|
||||
self.map.displayProjection);
|
||||
var pos = self.map.olMap.getLonLatFromLayerPx(
|
||||
new OpenLayers.Pixel(x, y));
|
||||
//if the coordinates should be displayed in something else,
|
||||
//set them via the map displayProjection option
|
||||
if(!mapProjection.equals(self.map.displayProjection)) {
|
||||
pos = pos.transform(mapProjection, displayProjection);
|
||||
}
|
||||
$("#id_diabook_ELPosX", document.element).val(
|
||||
self.options.x + pos.lon.toFixed(self.options.precision));
|
||||
$("#id_diabook_ELPosY", document.element).val(
|
||||
self.options.y + pos.lat.toFixed(self.options.precision));
|
||||
}
|
||||
});
|
||||
})(jQuery);
|
85
diabook/js/jquery.mapquery.mqZoomSlider.js
Normal file
85
diabook/js/jquery.mapquery.mqZoomSlider.js
Normal file
|
@ -0,0 +1,85 @@
|
|||
/* Copyright (c) 2011 by MapQuery Contributors (see AUTHORS for
|
||||
* full list of contributors). Published under the MIT license.
|
||||
* See https://github.com/mapquery/mapquery/blob/master/LICENSE for the
|
||||
* full text of the license. */
|
||||
|
||||
|
||||
/**
|
||||
#jquery.mapquery.mqZoomSlider.js
|
||||
The file containing the mqZoomSlider Widget
|
||||
|
||||
### *$('selector')*.`mqZoomSlider([options])`
|
||||
_version added 0.1_
|
||||
####**Description**: create a widget to show a zoom slider
|
||||
|
||||
+ **options**:
|
||||
- **map**: the mapquery instance
|
||||
|
||||
>Returns: widget
|
||||
|
||||
|
||||
The mqZoomSlider widget allows us to display a vertical zoom slider.
|
||||
|
||||
|
||||
$('#zoomslider').mqZoomSlider({
|
||||
map: '#map'
|
||||
});
|
||||
|
||||
*/
|
||||
(function($) {
|
||||
$.template('mqZoomSlider',
|
||||
'<div class="mq-zoomslider ui-widget ui-helper-clearfix ">'+
|
||||
'<div class="mq-zoomslider-slider"></div>'+
|
||||
'</div>');
|
||||
|
||||
$.widget("mapQuery.mqZoomSlider", {
|
||||
options: {
|
||||
// The MapQuery instance
|
||||
map: undefined
|
||||
|
||||
},
|
||||
_create: function() {
|
||||
var map;
|
||||
var zoom;
|
||||
var numzoomlevels;
|
||||
var self = this;
|
||||
var element = this.element;
|
||||
|
||||
//get the mapquery object
|
||||
map = $(this.options.map).data('mapQuery');
|
||||
|
||||
$.tmpl('mqZoomSlider').appendTo(element);
|
||||
|
||||
numzoomlevels = map.options.numZoomLevels;
|
||||
$(".mq-zoomslider-slider", element).slider({
|
||||
max: numzoomlevels,
|
||||
min:2,
|
||||
orientation: 'vertical',
|
||||
step: 1,
|
||||
value: numzoomlevels - map.center().zoom,
|
||||
slide: function(event, ui) {
|
||||
map.center({zoom:numzoomlevels-ui.value});
|
||||
},
|
||||
change: function(event, ui) {
|
||||
map.center({zoom:numzoomlevels-ui.value});
|
||||
}
|
||||
});
|
||||
map.bind("zoomend",
|
||||
{widget:self,map:map,control:element},
|
||||
self._onZoomEnd);
|
||||
|
||||
},
|
||||
_destroy: function() {
|
||||
this.element.removeClass(' ui-widget ui-helper-clearfix ' +
|
||||
'ui-corner-all')
|
||||
.empty();
|
||||
},
|
||||
_zoomEnd: function (element,map) {
|
||||
var slider = element.find('.mq-zoomslider-slider');
|
||||
slider.slider('value',map.options.numZoomLevels-map.center().zoom);
|
||||
},
|
||||
_onZoomEnd: function(evt) {
|
||||
evt.data.widget._zoomEnd(evt.data.control,evt.data.map);
|
||||
}
|
||||
});
|
||||
})(jQuery);
|
84
diabook/js/jquery.mousewheel.js
Normal file
84
diabook/js/jquery.mousewheel.js
Normal file
|
@ -0,0 +1,84 @@
|
|||
/*! Copyright (c) 2011 Brandon Aaron (http://brandonaaron.net)
|
||||
* Licensed under the MIT License (LICENSE.txt).
|
||||
*
|
||||
* Thanks to: http://adomas.org/javascript-mouse-wheel/ for some pointers.
|
||||
* Thanks to: Mathias Bank(http://www.mathias-bank.de) for a scope bug fix.
|
||||
* Thanks to: Seamus Leahy for adding deltaX and deltaY
|
||||
*
|
||||
* Version: 3.0.6
|
||||
*
|
||||
* Requires: 1.2.2+
|
||||
*/
|
||||
|
||||
(function($) {
|
||||
|
||||
var types = ['DOMMouseScroll', 'mousewheel'];
|
||||
|
||||
if ($.event.fixHooks) {
|
||||
for ( var i=types.length; i; ) {
|
||||
$.event.fixHooks[ types[--i] ] = $.event.mouseHooks;
|
||||
}
|
||||
}
|
||||
|
||||
$.event.special.mousewheel = {
|
||||
setup: function() {
|
||||
if ( this.addEventListener ) {
|
||||
for ( var i=types.length; i; ) {
|
||||
this.addEventListener( types[--i], handler, false );
|
||||
}
|
||||
} else {
|
||||
this.onmousewheel = handler;
|
||||
}
|
||||
},
|
||||
|
||||
teardown: function() {
|
||||
if ( this.removeEventListener ) {
|
||||
for ( var i=types.length; i; ) {
|
||||
this.removeEventListener( types[--i], handler, false );
|
||||
}
|
||||
} else {
|
||||
this.onmousewheel = null;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
$.fn.extend({
|
||||
mousewheel: function(fn) {
|
||||
return fn ? this.bind("mousewheel", fn) : this.trigger("mousewheel");
|
||||
},
|
||||
|
||||
unmousewheel: function(fn) {
|
||||
return this.unbind("mousewheel", fn);
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
function handler(event) {
|
||||
var orgEvent = event || window.event, args = [].slice.call( arguments, 1 ), delta = 0, returnValue = true, deltaX = 0, deltaY = 0;
|
||||
event = $.event.fix(orgEvent);
|
||||
event.type = "mousewheel";
|
||||
|
||||
// Old school scrollwheel delta
|
||||
if ( orgEvent.wheelDelta ) { delta = orgEvent.wheelDelta/120; }
|
||||
if ( orgEvent.detail ) { delta = -orgEvent.detail/3; }
|
||||
|
||||
// New school multidimensional scroll (touchpads) deltas
|
||||
deltaY = delta;
|
||||
|
||||
// Gecko
|
||||
if ( orgEvent.axis !== undefined && orgEvent.axis === orgEvent.HORIZONTAL_AXIS ) {
|
||||
deltaY = 0;
|
||||
deltaX = -1*delta;
|
||||
}
|
||||
|
||||
// Webkit
|
||||
if ( orgEvent.wheelDeltaY !== undefined ) { deltaY = orgEvent.wheelDeltaY/120; }
|
||||
if ( orgEvent.wheelDeltaX !== undefined ) { deltaX = -1*orgEvent.wheelDeltaX/120; }
|
||||
|
||||
// Add event and delta to the front of the arguments
|
||||
args.unshift(event, delta, deltaX, deltaY);
|
||||
|
||||
return ($.event.dispatch || $.event.handle).apply(this, args);
|
||||
}
|
||||
|
||||
})(jQuery);
|
486
diabook/js/jquery.tmpl.js
Normal file
486
diabook/js/jquery.tmpl.js
Normal file
|
@ -0,0 +1,486 @@
|
|||
/*
|
||||
* jQuery Templating Plugin
|
||||
* Copyright 2010, John Resig
|
||||
* Dual licensed under the MIT or GPL Version 2 licenses.
|
||||
*/
|
||||
(function( jQuery, undefined ){
|
||||
var oldManip = jQuery.fn.domManip, tmplItmAtt = "_tmplitem", htmlExpr = /^[^<]*(<[\w\W]+>)[^>]*$|\{\{\! /,
|
||||
newTmplItems = {}, wrappedItems = {}, appendToTmplItems, topTmplItem = { key: 0, data: {} }, itemKey = 0, cloneIndex = 0, stack = [];
|
||||
|
||||
function newTmplItem( options, parentItem, fn, data ) {
|
||||
// Returns a template item data structure for a new rendered instance of a template (a 'template item').
|
||||
// The content field is a hierarchical array of strings and nested items (to be
|
||||
// removed and replaced by nodes field of dom elements, once inserted in DOM).
|
||||
var newItem = {
|
||||
data: data || (parentItem ? parentItem.data : {}),
|
||||
_wrap: parentItem ? parentItem._wrap : null,
|
||||
tmpl: null,
|
||||
parent: parentItem || null,
|
||||
nodes: [],
|
||||
calls: tiCalls,
|
||||
nest: tiNest,
|
||||
wrap: tiWrap,
|
||||
html: tiHtml,
|
||||
update: tiUpdate
|
||||
};
|
||||
if ( options ) {
|
||||
jQuery.extend( newItem, options, { nodes: [], parent: parentItem } );
|
||||
}
|
||||
if ( fn ) {
|
||||
// Build the hierarchical content to be used during insertion into DOM
|
||||
newItem.tmpl = fn;
|
||||
newItem._ctnt = newItem._ctnt || newItem.tmpl( jQuery, newItem );
|
||||
newItem.key = ++itemKey;
|
||||
// Keep track of new template item, until it is stored as jQuery Data on DOM element
|
||||
(stack.length ? wrappedItems : newTmplItems)[itemKey] = newItem;
|
||||
}
|
||||
return newItem;
|
||||
}
|
||||
|
||||
// Override appendTo etc., in order to provide support for targeting multiple elements. (This code would disappear if integrated in jquery core).
|
||||
jQuery.each({
|
||||
appendTo: "append",
|
||||
prependTo: "prepend",
|
||||
insertBefore: "before",
|
||||
insertAfter: "after",
|
||||
replaceAll: "replaceWith"
|
||||
}, function( name, original ) {
|
||||
jQuery.fn[ name ] = function( selector ) {
|
||||
var ret = [], insert = jQuery( selector ), elems, i, l, tmplItems,
|
||||
parent = this.length === 1 && this[0].parentNode;
|
||||
|
||||
appendToTmplItems = newTmplItems || {};
|
||||
if ( parent && parent.nodeType === 11 && parent.childNodes.length === 1 && insert.length === 1 ) {
|
||||
insert[ original ]( this[0] );
|
||||
ret = this;
|
||||
} else {
|
||||
for ( i = 0, l = insert.length; i < l; i++ ) {
|
||||
cloneIndex = i;
|
||||
elems = (i > 0 ? this.clone(true) : this).get();
|
||||
jQuery.fn[ original ].apply( jQuery(insert[i]), elems );
|
||||
ret = ret.concat( elems );
|
||||
}
|
||||
cloneIndex = 0;
|
||||
ret = this.pushStack( ret, name, insert.selector );
|
||||
}
|
||||
tmplItems = appendToTmplItems;
|
||||
appendToTmplItems = null;
|
||||
jQuery.tmpl.complete( tmplItems );
|
||||
return ret;
|
||||
};
|
||||
});
|
||||
|
||||
jQuery.fn.extend({
|
||||
// Use first wrapped element as template markup.
|
||||
// Return wrapped set of template items, obtained by rendering template against data.
|
||||
tmpl: function( data, options, parentItem ) {
|
||||
return jQuery.tmpl( this[0], data, options, parentItem );
|
||||
},
|
||||
|
||||
// Find which rendered template item the first wrapped DOM element belongs to
|
||||
tmplItem: function() {
|
||||
return jQuery.tmplItem( this[0] );
|
||||
},
|
||||
|
||||
// Consider the first wrapped element as a template declaration, and get the compiled template or store it as a named template.
|
||||
template: function( name ) {
|
||||
return jQuery.template( name, this[0] );
|
||||
},
|
||||
|
||||
domManip: function( args, table, callback, options ) {
|
||||
// This appears to be a bug in the appendTo, etc. implementation
|
||||
// it should be doing .call() instead of .apply(). See #6227
|
||||
if ( args[0] && args[0].nodeType ) {
|
||||
var dmArgs = jQuery.makeArray( arguments ), argsLength = args.length, i = 0, tmplItem;
|
||||
while ( i < argsLength && !(tmplItem = jQuery.data( args[i++], "tmplItem" ))) {}
|
||||
if ( argsLength > 1 ) {
|
||||
dmArgs[0] = [jQuery.makeArray( args )];
|
||||
}
|
||||
if ( tmplItem && cloneIndex ) {
|
||||
dmArgs[2] = function( fragClone ) {
|
||||
// Handler called by oldManip when rendered template has been inserted into DOM.
|
||||
jQuery.tmpl.afterManip( this, fragClone, callback );
|
||||
};
|
||||
}
|
||||
oldManip.apply( this, dmArgs );
|
||||
} else {
|
||||
oldManip.apply( this, arguments );
|
||||
}
|
||||
cloneIndex = 0;
|
||||
if ( !appendToTmplItems ) {
|
||||
jQuery.tmpl.complete( newTmplItems );
|
||||
}
|
||||
return this;
|
||||
}
|
||||
});
|
||||
|
||||
jQuery.extend({
|
||||
// Return wrapped set of template items, obtained by rendering template against data.
|
||||
tmpl: function( tmpl, data, options, parentItem ) {
|
||||
var ret, topLevel = !parentItem;
|
||||
if ( topLevel ) {
|
||||
// This is a top-level tmpl call (not from a nested template using {{tmpl}})
|
||||
parentItem = topTmplItem;
|
||||
tmpl = jQuery.template[tmpl] || jQuery.template( null, tmpl );
|
||||
wrappedItems = {}; // Any wrapped items will be rebuilt, since this is top level
|
||||
} else if ( !tmpl ) {
|
||||
// The template item is already associated with DOM - this is a refresh.
|
||||
// Re-evaluate rendered template for the parentItem
|
||||
tmpl = parentItem.tmpl;
|
||||
newTmplItems[parentItem.key] = parentItem;
|
||||
parentItem.nodes = [];
|
||||
if ( parentItem.wrapped ) {
|
||||
updateWrapped( parentItem, parentItem.wrapped );
|
||||
}
|
||||
// Rebuild, without creating a new template item
|
||||
return jQuery( build( parentItem, null, parentItem.tmpl( jQuery, parentItem ) ));
|
||||
}
|
||||
if ( !tmpl ) {
|
||||
return []; // Could throw...
|
||||
}
|
||||
if ( typeof data === "function" ) {
|
||||
data = data.call( parentItem || {} );
|
||||
}
|
||||
if ( options && options.wrapped ) {
|
||||
updateWrapped( options, options.wrapped );
|
||||
}
|
||||
ret = jQuery.isArray( data ) ?
|
||||
jQuery.map( data, function( dataItem ) {
|
||||
return dataItem ? newTmplItem( options, parentItem, tmpl, dataItem ) : null;
|
||||
}) :
|
||||
[ newTmplItem( options, parentItem, tmpl, data ) ];
|
||||
return topLevel ? jQuery( build( parentItem, null, ret ) ) : ret;
|
||||
},
|
||||
|
||||
// Return rendered template item for an element.
|
||||
tmplItem: function( elem ) {
|
||||
var tmplItem;
|
||||
if ( elem instanceof jQuery ) {
|
||||
elem = elem[0];
|
||||
}
|
||||
while ( elem && elem.nodeType === 1 && !(tmplItem = jQuery.data( elem, "tmplItem" )) && (elem = elem.parentNode) ) {}
|
||||
return tmplItem || topTmplItem;
|
||||
},
|
||||
|
||||
// Set:
|
||||
// Use $.template( name, tmpl ) to cache a named template,
|
||||
// where tmpl is a template string, a script element or a jQuery instance wrapping a script element, etc.
|
||||
// Use $( "selector" ).template( name ) to provide access by name to a script block template declaration.
|
||||
|
||||
// Get:
|
||||
// Use $.template( name ) to access a cached template.
|
||||
// Also $( selectorToScriptBlock ).template(), or $.template( null, templateString )
|
||||
// will return the compiled template, without adding a name reference.
|
||||
// If templateString includes at least one HTML tag, $.template( templateString ) is equivalent
|
||||
// to $.template( null, templateString )
|
||||
template: function( name, tmpl ) {
|
||||
if (tmpl) {
|
||||
// Compile template and associate with name
|
||||
if ( typeof tmpl === "string" ) {
|
||||
// This is an HTML string being passed directly in.
|
||||
tmpl = buildTmplFn( tmpl )
|
||||
} else if ( tmpl instanceof jQuery ) {
|
||||
tmpl = tmpl[0] || {};
|
||||
}
|
||||
if ( tmpl.nodeType ) {
|
||||
// If this is a template block, use cached copy, or generate tmpl function and cache.
|
||||
tmpl = jQuery.data( tmpl, "tmpl" ) || jQuery.data( tmpl, "tmpl", buildTmplFn( tmpl.innerHTML ));
|
||||
}
|
||||
return typeof name === "string" ? (jQuery.template[name] = tmpl) : tmpl;
|
||||
}
|
||||
// Return named compiled template
|
||||
return name ? (typeof name !== "string" ? jQuery.template( null, name ):
|
||||
(jQuery.template[name] ||
|
||||
// If not in map, treat as a selector. (If integrated with core, use quickExpr.exec)
|
||||
jQuery.template( null, htmlExpr.test( name ) ? name : jQuery( name )))) : null;
|
||||
},
|
||||
|
||||
encode: function( text ) {
|
||||
// Do HTML encoding replacing < > & and ' and " by corresponding entities.
|
||||
return ("" + text).split("<").join("<").split(">").join(">").split('"').join(""").split("'").join("'");
|
||||
}
|
||||
});
|
||||
|
||||
jQuery.extend( jQuery.tmpl, {
|
||||
tag: {
|
||||
"tmpl": {
|
||||
_default: { $2: "null" },
|
||||
open: "if($notnull_1){_=_.concat($item.nest($1,$2));}"
|
||||
// tmpl target parameter can be of type function, so use $1, not $1a (so not auto detection of functions)
|
||||
// This means that {{tmpl foo}} treats foo as a template (which IS a function).
|
||||
// Explicit parens can be used if foo is a function that returns a template: {{tmpl foo()}}.
|
||||
},
|
||||
"wrap": {
|
||||
_default: { $2: "null" },
|
||||
open: "$item.calls(_,$1,$2);_=[];",
|
||||
close: "call=$item.calls();_=call._.concat($item.wrap(call,_));"
|
||||
},
|
||||
"each": {
|
||||
_default: { $2: "$index, $value" },
|
||||
open: "if($notnull_1){$.each($1a,function($2){with(this){",
|
||||
close: "}});}"
|
||||
},
|
||||
"if": {
|
||||
open: "if(($notnull_1) && $1a){",
|
||||
close: "}"
|
||||
},
|
||||
"else": {
|
||||
_default: { $1: "true" },
|
||||
open: "}else if(($notnull_1) && $1a){"
|
||||
},
|
||||
"html": {
|
||||
// Unecoded expression evaluation.
|
||||
open: "if($notnull_1){_.push($1a);}"
|
||||
},
|
||||
"=": {
|
||||
// Encoded expression evaluation. Abbreviated form is ${}.
|
||||
_default: { $1: "$data" },
|
||||
open: "if($notnull_1){_.push($.encode($1a));}"
|
||||
},
|
||||
"!": {
|
||||
// Comment tag. Skipped by parser
|
||||
open: ""
|
||||
}
|
||||
},
|
||||
|
||||
// This stub can be overridden, e.g. in jquery.tmplPlus for providing rendered events
|
||||
complete: function( items ) {
|
||||
newTmplItems = {};
|
||||
},
|
||||
|
||||
// Call this from code which overrides domManip, or equivalent
|
||||
// Manage cloning/storing template items etc.
|
||||
afterManip: function afterManip( elem, fragClone, callback ) {
|
||||
// Provides cloned fragment ready for fixup prior to and after insertion into DOM
|
||||
var content = fragClone.nodeType === 11 ?
|
||||
jQuery.makeArray(fragClone.childNodes) :
|
||||
fragClone.nodeType === 1 ? [fragClone] : [];
|
||||
|
||||
// Return fragment to original caller (e.g. append) for DOM insertion
|
||||
callback.call( elem, fragClone );
|
||||
|
||||
// Fragment has been inserted:- Add inserted nodes to tmplItem data structure. Replace inserted element annotations by jQuery.data.
|
||||
storeTmplItems( content );
|
||||
cloneIndex++;
|
||||
}
|
||||
});
|
||||
|
||||
//========================== Private helper functions, used by code above ==========================
|
||||
|
||||
function build( tmplItem, nested, content ) {
|
||||
// Convert hierarchical content into flat string array
|
||||
// and finally return array of fragments ready for DOM insertion
|
||||
var frag, ret = content ? jQuery.map( content, function( item ) {
|
||||
return (typeof item === "string") ?
|
||||
// Insert template item annotations, to be converted to jQuery.data( "tmplItem" ) when elems are inserted into DOM.
|
||||
(tmplItem.key ? item.replace( /(<\w+)(?=[\s>])(?![^>]*_tmplitem)([^>]*)/g, "$1 " + tmplItmAtt + "=\"" + tmplItem.key + "\" $2" ) : item) :
|
||||
// This is a child template item. Build nested template.
|
||||
build( item, tmplItem, item._ctnt );
|
||||
}) :
|
||||
// If content is not defined, insert tmplItem directly. Not a template item. May be a string, or a string array, e.g. from {{html $item.html()}}.
|
||||
tmplItem;
|
||||
if ( nested ) {
|
||||
return ret;
|
||||
}
|
||||
|
||||
// top-level template
|
||||
ret = ret.join("");
|
||||
|
||||
// Support templates which have initial or final text nodes, or consist only of text
|
||||
// Also support HTML entities within the HTML markup.
|
||||
ret.replace( /^\s*([^<\s][^<]*)?(<[\w\W]+>)([^>]*[^>\s])?\s*$/, function( all, before, middle, after) {
|
||||
frag = jQuery( middle ).get();
|
||||
|
||||
storeTmplItems( frag );
|
||||
if ( before ) {
|
||||
frag = unencode( before ).concat(frag);
|
||||
}
|
||||
if ( after ) {
|
||||
frag = frag.concat(unencode( after ));
|
||||
}
|
||||
});
|
||||
return frag ? frag : unencode( ret );
|
||||
}
|
||||
|
||||
function unencode( text ) {
|
||||
// Use createElement, since createTextNode will not render HTML entities correctly
|
||||
var el = document.createElement( "div" );
|
||||
el.innerHTML = text;
|
||||
return jQuery.makeArray(el.childNodes);
|
||||
}
|
||||
|
||||
// Generate a reusable function that will serve to render a template against data
|
||||
function buildTmplFn( markup ) {
|
||||
return new Function("jQuery","$item",
|
||||
"var $=jQuery,call,_=[],$data=$item.data;" +
|
||||
|
||||
// Introduce the data as local variables using with(){}
|
||||
"with($data){_.push('" +
|
||||
|
||||
// Convert the template into pure JavaScript
|
||||
jQuery.trim(markup)
|
||||
.replace( /([\\'])/g, "\\$1" )
|
||||
.replace( /[\r\t\n]/g, " " )
|
||||
.replace( /\$\{([^\}]*)\}/g, "{{= $1}}" )
|
||||
.replace( /\{\{(\/?)(\w+|.)(?:\(((?:[^\}]|\}(?!\}))*?)?\))?(?:\s+(.*?)?)?(\(((?:[^\}]|\}(?!\}))*?)\))?\s*\}\}/g,
|
||||
function( all, slash, type, fnargs, target, parens, args ) {
|
||||
var tag = jQuery.tmpl.tag[ type ], def, expr, exprAutoFnDetect;
|
||||
if ( !tag ) {
|
||||
throw "Template command not found: " + type;
|
||||
}
|
||||
def = tag._default || [];
|
||||
if ( parens && !/\w$/.test(target)) {
|
||||
target += parens;
|
||||
parens = "";
|
||||
}
|
||||
if ( target ) {
|
||||
target = unescape( target );
|
||||
args = args ? ("," + unescape( args ) + ")") : (parens ? ")" : "");
|
||||
// Support for target being things like a.toLowerCase();
|
||||
// In that case don't call with template item as 'this' pointer. Just evaluate...
|
||||
expr = parens ? (target.indexOf(".") > -1 ? target + parens : ("(" + target + ").call($item" + args)) : target;
|
||||
exprAutoFnDetect = parens ? expr : "(typeof(" + target + ")==='function'?(" + target + ").call($item):(" + target + "))";
|
||||
} else {
|
||||
exprAutoFnDetect = expr = def.$1 || "null";
|
||||
}
|
||||
fnargs = unescape( fnargs );
|
||||
return "');" +
|
||||
tag[ slash ? "close" : "open" ]
|
||||
.split( "$notnull_1" ).join( target ? "typeof(" + target + ")!=='undefined' && (" + target + ")!=null" : "true" )
|
||||
.split( "$1a" ).join( exprAutoFnDetect )
|
||||
.split( "$1" ).join( expr )
|
||||
.split( "$2" ).join( fnargs ?
|
||||
fnargs.replace( /\s*([^\(]+)\s*(\((.*?)\))?/g, function( all, name, parens, params ) {
|
||||
params = params ? ("," + params + ")") : (parens ? ")" : "");
|
||||
return params ? ("(" + name + ").call($item" + params) : all;
|
||||
})
|
||||
: (def.$2||"")
|
||||
) +
|
||||
"_.push('";
|
||||
}) +
|
||||
"');}return _;"
|
||||
);
|
||||
}
|
||||
function updateWrapped( options, wrapped ) {
|
||||
// Build the wrapped content.
|
||||
options._wrap = build( options, true,
|
||||
// Suport imperative scenario in which options.wrapped can be set to a selector or an HTML string.
|
||||
jQuery.isArray( wrapped ) ? wrapped : [htmlExpr.test( wrapped ) ? wrapped : jQuery( wrapped ).html()]
|
||||
).join("");
|
||||
}
|
||||
|
||||
function unescape( args ) {
|
||||
return args ? args.replace( /\\'/g, "'").replace(/\\\\/g, "\\" ) : null;
|
||||
}
|
||||
function outerHtml( elem ) {
|
||||
var div = document.createElement("div");
|
||||
div.appendChild( elem.cloneNode(true) );
|
||||
return div.innerHTML;
|
||||
}
|
||||
|
||||
// Store template items in jQuery.data(), ensuring a unique tmplItem data data structure for each rendered template instance.
|
||||
function storeTmplItems( content ) {
|
||||
var keySuffix = "_" + cloneIndex, elem, elems, newClonedItems = {}, i, l, m;
|
||||
for ( i = 0, l = content.length; i < l; i++ ) {
|
||||
if ( (elem = content[i]).nodeType !== 1 ) {
|
||||
continue;
|
||||
}
|
||||
elems = elem.getElementsByTagName("*");
|
||||
for ( m = elems.length - 1; m >= 0; m-- ) {
|
||||
processItemKey( elems[m] );
|
||||
}
|
||||
processItemKey( elem );
|
||||
}
|
||||
function processItemKey( el ) {
|
||||
var pntKey, pntNode = el, pntItem, tmplItem, key;
|
||||
// Ensure that each rendered template inserted into the DOM has its own template item,
|
||||
if ( (key = el.getAttribute( tmplItmAtt ))) {
|
||||
while ( pntNode.parentNode && (pntNode = pntNode.parentNode).nodeType === 1 && !(pntKey = pntNode.getAttribute( tmplItmAtt ))) { }
|
||||
if ( pntKey !== key ) {
|
||||
// The next ancestor with a _tmplitem expando is on a different key than this one.
|
||||
// So this is a top-level element within this template item
|
||||
// Set pntNode to the key of the parentNode, or to 0 if pntNode.parentNode is null, or pntNode is a fragment.
|
||||
pntNode = pntNode.parentNode ? (pntNode.nodeType === 11 ? 0 : (pntNode.getAttribute( tmplItmAtt ) || 0)) : 0;
|
||||
if ( !(tmplItem = newTmplItems[key]) ) {
|
||||
// The item is for wrapped content, and was copied from the temporary parent wrappedItem.
|
||||
tmplItem = wrappedItems[key];
|
||||
tmplItem = newTmplItem( tmplItem, newTmplItems[pntNode]||wrappedItems[pntNode], null, true );
|
||||
tmplItem.key = ++itemKey;
|
||||
newTmplItems[itemKey] = tmplItem;
|
||||
}
|
||||
if ( cloneIndex ) {
|
||||
cloneTmplItem( key );
|
||||
}
|
||||
}
|
||||
el.removeAttribute( tmplItmAtt );
|
||||
} else if ( cloneIndex && (tmplItem = jQuery.data( el, "tmplItem" )) ) {
|
||||
// This was a rendered element, cloned during append or appendTo etc.
|
||||
// TmplItem stored in jQuery data has already been cloned in cloneCopyEvent. We must replace it with a fresh cloned tmplItem.
|
||||
cloneTmplItem( tmplItem.key );
|
||||
newTmplItems[tmplItem.key] = tmplItem;
|
||||
pntNode = jQuery.data( el.parentNode, "tmplItem" );
|
||||
pntNode = pntNode ? pntNode.key : 0;
|
||||
}
|
||||
if ( tmplItem ) {
|
||||
pntItem = tmplItem;
|
||||
// Find the template item of the parent element.
|
||||
// (Using !=, not !==, since pntItem.key is number, and pntNode may be a string)
|
||||
while ( pntItem && pntItem.key != pntNode ) {
|
||||
// Add this element as a top-level node for this rendered template item, as well as for any
|
||||
// ancestor items between this item and the item of its parent element
|
||||
pntItem.nodes.push( el );
|
||||
pntItem = pntItem.parent;
|
||||
}
|
||||
// Delete content built during rendering - reduce API surface area and memory use, and avoid exposing of stale data after rendering...
|
||||
delete tmplItem._ctnt;
|
||||
delete tmplItem._wrap;
|
||||
// Store template item as jQuery data on the element
|
||||
jQuery.data( el, "tmplItem", tmplItem );
|
||||
}
|
||||
function cloneTmplItem( key ) {
|
||||
key = key + keySuffix;
|
||||
tmplItem = newClonedItems[key] =
|
||||
(newClonedItems[key] || newTmplItem( tmplItem, newTmplItems[tmplItem.parent.key + keySuffix] || tmplItem.parent, null, true ));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//---- Helper functions for template item ----
|
||||
|
||||
function tiCalls( content, tmpl, data, options ) {
|
||||
if ( !content ) {
|
||||
return stack.pop();
|
||||
}
|
||||
stack.push({ _: content, tmpl: tmpl, item:this, data: data, options: options });
|
||||
}
|
||||
|
||||
function tiNest( tmpl, data, options ) {
|
||||
// nested template, using {{tmpl}} tag
|
||||
return jQuery.tmpl( jQuery.template( tmpl ), data, options, this );
|
||||
}
|
||||
|
||||
function tiWrap( call, wrapped ) {
|
||||
// nested template, using {{wrap}} tag
|
||||
var options = call.options || {};
|
||||
options.wrapped = wrapped;
|
||||
// Apply the template, which may incorporate wrapped content,
|
||||
return jQuery.tmpl( jQuery.template( call.tmpl ), call.data, options, call.item );
|
||||
}
|
||||
|
||||
function tiHtml( filter, textOnly ) {
|
||||
var wrapped = this._wrap;
|
||||
return jQuery.map(
|
||||
jQuery( jQuery.isArray( wrapped ) ? wrapped.join("") : wrapped ).filter( filter || "*" ),
|
||||
function(e) {
|
||||
return textOnly ?
|
||||
e.innerText || e.textContent :
|
||||
e.outerHTML || outerHtml(e);
|
||||
});
|
||||
}
|
||||
|
||||
function tiUpdate() {
|
||||
var coll = this.nodes;
|
||||
jQuery.tmpl( null, null, null, this).insertBefore( coll[0] );
|
||||
jQuery( coll ).remove();
|
||||
}
|
||||
})( jQuery );
|
Loading…
Add table
Add a link
Reference in a new issue