Skip to content
Permalink
Browse files

Plans updates

* Plans: mobile pinch-to-zoom fix, orientation update fix
* Plans: custom css, custom javascript sections
  • Loading branch information...
sergejey committed Feb 27, 2019
1 parent 4476370 commit b1b4999dce6ee171e8db5d035bb1f92cd26ec42c

Large diffs are not rendered by default.

Oops, something went wrong.
@@ -182,9 +182,11 @@ function usual(&$out)
exit;
}
if (isset($this->id)) {
$this->embedd=1;
/*
if ($this->id && !$_GET['id']) {
$this->embed=1;
}
*/
if (gr('id','int')) {
$this->id=gr('id','int');
@@ -231,12 +233,14 @@ function getPreview($id) {
$content=LoadFile(ROOT.'cms/plans/'.$rec['IMAGE']);
$out['PLAN_ID']=$rec['ID'];
$out['PLAN_NEED_ZOOM']=$rec['NEED_ZOOM'];
if ($this->width || $this->height || $this->embedd) {
if ($this->width || $this->height || $this->embed) {
$rec['AUTO_ZOOM']=0;
if ($this->width) $out['WIDTH']=$this->width;
if ($this->height) $out['HEIGHT']=$this->height;
}
$out['PLAN_AUTO_ZOOM']=$rec['AUTO_ZOOM'];
$out['PLAN_CUSTOM_JAVASCRIPT']=$rec['CUSTOM_JAVASCRIPT'];
$out['PLAN_CUSTOM_CSS']=$rec['CUSTOM_CSS'];
$dynData=$this->findDynamicText($content);
foreach($dynData as $dynItem) {
$content = str_replace($dynItem['TEMPLATE'],$dynItem['CONTENT'],$content);
@@ -466,6 +470,8 @@ function dbInstall($data)
plans: IMAGE varchar(255) NOT NULL DEFAULT ''
plans: NEED_ZOOM int(3) NOT NULL DEFAULT '0'
plans: AUTO_ZOOM int(3) NOT NULL DEFAULT '0'
plans: CUSTOM_CSS text
plans: CUSTOM_JAVASCRIPT text
plan_states: ID int(10) unsigned NOT NULL auto_increment
plan_states: TITLE varchar(255) NOT NULL DEFAULT ''
@@ -16,6 +16,20 @@
include_once(DIR_MODULES.$this->name.'/states.inc.php');
}
if ($this->mode=='update' && $this->tab=='css') {
$rec['CUSTOM_CSS']=gr('css');
SQLUpdate('plans',$rec);
$out['OK']=1;
$this->redirect("?view_mode=".$this->view_mode."&id=".$rec['ID']."&tab=preview");
}
if ($this->mode=='update' && $this->tab=='javascript') {
$rec['CUSTOM_JAVASCRIPT']=gr('javascript');
SQLUpdate('plans',$rec);
$out['OK']=1;
$this->redirect("?view_mode=".$this->view_mode."&id=".$rec['ID']."&tab=preview");
}
if ($this->mode == 'update' && $this->tab=='') {
$ok = 1;
//updating '<%LANG_TITLE%>' (varchar, required)
@@ -50,6 +64,7 @@
$out['OK'] = 1;
$this->redirect("?view_mode=".$this->view_mode."&id=".$rec['ID']."&tab=preview");
} else {
$out['ERR'] = 1;
}
@@ -62,3 +77,7 @@
}
}
outHash($rec, $out);
if ($rec['ID'] && ($this->tab=='css' || $this->tab=='javascript')) {
$out['ITEMS']=$this->getImageItems($rec['ID']);
}
@@ -16,6 +16,8 @@
<ul class="nav nav-tabs">
<li[#if TAB=""#] class="active"[#endif#]><a href="?view_mode=<#VIEW_MODE#>&id=[#ID#]&tab="><#LANG_GENERAL#></a></li>
<li[#if TAB="states"#] class="active"[#endif#]><a href="?view_mode=<#VIEW_MODE#>&id=[#ID#]&tab=states"><#LANG_STATES#></a></li>
<li[#if TAB="css"#] class="active"[#endif#]><a href="?view_mode=<#VIEW_MODE#>&id=[#ID#]&tab=css"><#LANG_USE_CSS#></a></li>
<li[#if TAB="javascript"#] class="active"[#endif#]><a href="?view_mode=<#VIEW_MODE#>&id=[#ID#]&tab=javascript"><#LANG_USE_JAVASCRIPT#></a></li>
<li[#if TAB="preview"#] class="active"[#endif#]><a href="?view_mode=<#VIEW_MODE#>&id=[#ID#]&tab=preview"><#LANG_PREVIEW#></a></li>
</ul>
<div>&nbsp;</div>
@@ -42,6 +44,14 @@
[#inc plans_preview.html#]
[#endif TAB#]

[#if TAB="css"#]
[#inc plans_css.html#]
[#endif TAB#]

[#if TAB="javascript"#]
[#inc plans_javascript.html#]
[#endif TAB#]


[#endif VIEW_MODE#]
<!-- / table plans edit -->
@@ -3,8 +3,8 @@
</div>
<#LANG_EMBED_CODE#>:
<pre>
&#091#module name="plans" id="<#ID#>"#&#093
&#091#module name="plans" id="<#ID#>" width="500" height="200"#&#093
&#091#module name="plans" id="<#ID#>" embed="1"#&#093
&#091#module name="plans" id="<#ID#>" embed="1" width="500" height="200"#&#093
</pre>
<hr/>
[#module name="plans" id="<#ID#>"#]
[#module name="plans" id="<#ID#>" embed="1"#]
@@ -1,7 +1,15 @@
<link rel="stylesheet" href="<#ROOTHTML#>templates/plans/basic.css">
[#if PLAN_NEED_ZOOM="1"#]
<script type="text/javascript" src="<#ROOTHTML#>3rdparty/hammer/hammer.min.js"></script>
<script type="text/javascript" src="<#ROOTHTML#>3rdparty/svg-pan-zoom/svg-pan-zoom.min.js"></script>
[#endif#]

[#if PLAN_CUSTOM_CSS!=""#]
<style>
[#PLAN_CUSTOM_CSS#]
</style>
[#endif#]
<div id="plan[#PLAN_ID#]" style="display:none;" class="svg_content">[#SVG_CONTENT#]</div>
<script type="application/javascript">
@@ -83,6 +91,7 @@
}
});
var panZoom=0;
$(document).ready(function(){
[#begin STATES#]
[#if SET_CLASS!=""#]
@@ -116,19 +125,87 @@
$('#plan[#PLAN_ID#]').show();
[#if PLAN_NEED_ZOOM="1"#]
eventsHandler = {
haltEventListeners: ['touchstart', 'touchend', 'touchmove', 'touchleave', 'touchcancel']
, init: function(options) {
var instance = options.instance
, initialScale = 1
, pannedX = 0
, pannedY = 0
// Init Hammer
// Listen only for pointer and touch events
this.hammer = Hammer(options.svgElement, {
inputClass: Hammer.SUPPORT_POINTER_EVENTS ? Hammer.PointerEventInput : Hammer.TouchInput
})
// Enable pinch
this.hammer.get('pinch').set({enable: true})
// Handle double tap
this.hammer.on('doubletap', function(ev){
instance.zoomIn()
})
// Handle pan
this.hammer.on('panstart panmove', function(ev){
// On pan start reset panned variables
if (ev.type === 'panstart') {
pannedX = 0
pannedY = 0
}
// Pan only the difference
instance.panBy({x: ev.deltaX - pannedX, y: ev.deltaY - pannedY})
pannedX = ev.deltaX
pannedY = ev.deltaY
})
// Handle pinch
this.hammer.on('pinchstart pinchmove', function(ev){
// On pinch start remember initial zoom
if (ev.type === 'pinchstart') {
initialScale = instance.getZoom()
instance.zoomAtPoint(initialScale * ev.scale, {x: ev.center.x, y: ev.center.y})
}
instance.zoomAtPoint(initialScale * ev.scale, {x: ev.center.x, y: ev.center.y})
})
// Prevent moving the page on some devices when panning over SVG
options.svgElement.addEventListener('touchmove', function(e){ e.preventDefault(); });
}
, destroy: function(){
this.hammer.destroy()
}
}
var options = {
zoomEnabled: true
, controlIconsEnabled: true
, customEventsHandler: eventsHandler
, fit:1
};
var svgElement = $('#plan[#PLAN_ID#] svg')[0];
var panZoomTiger = svgPanZoom(svgElement,{
zoomEnabled: true,
controlIconsEnabled: true,
});
panZoom=svgPanZoom(svgElement,options);
//var panZoom = svgPanZoom('#plan[#PLAN_ID#] svg');
[#endif#]
checkPlanTimer=setTimeout('checkAllPlanStates();', 5000);
[#if PLAN_AUTO_ZOOM="1"#]
setTimeout('planZoom();',2000);
var supportsOrientationChange = "onorientationchange" in window,
orientationEvent = supportsOrientationChange ? "orientationchange" : "resize";
window.addEventListener(orientationEvent, function() {
setTimeout('planZoom();', 1000);
}, false);
[#endif#]
[#if WIDTH!=""#]
$("#plan[#PLAN_ID#] svg").first().width('[#WIDTH#]');
$("#plan[#PLAN_ID#]").width('[#WIDTH#]');
@@ -139,4 +216,6 @@
[#endif#]
});
[#if PLAN_CUSTOM_JAVASCRIPT!=""#][#PLAN_CUSTOM_JAVASCRIPT#][#endif#]
</script>

0 comments on commit b1b4999

Please sign in to comment.
You can’t perform that action at this time.