Created
January 28, 2021 21:58
-
-
Save andronex/a9fdf4294f21267f1d08dea6b6dba257 to your computer and use it in GitHub Desktop.
Различные манипуляции с ExtJS в админке MODX Revolution с помощью плагина
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$eventName = $modx->event->name; | |
switch($eventName) { | |
case 'pdoToolsOnFenomInit': | |
$fenom->addModifier('lazy', function ($html) use ($modx) { | |
libxml_use_internal_errors(true); | |
$dom = new DOMDocument(); | |
$dom->loadHTML('<?xml encoding="utf-8" ?>' . (string)$html); | |
$output = $html; | |
//img | |
$imgs = $dom->getElementsByTagName('img'); | |
foreach($imgs as $img){ | |
$attr = $img->getAttribute('class'); | |
if(stripos($attr, 'lazy') === false){ | |
$tmp = $dom->saveHTML($img); | |
$img->setAttribute('class', 'lazy ' . $img->getAttribute('class')); | |
$img->setAttribute('data-src', $img->getAttribute('src')); | |
$img->removeAttribute('src'); | |
$output = str_replace(array($tmp, str_replace('>', ' />', $tmp), str_replace('>', '/>', $tmp)), $dom->saveHTML($img), $output); | |
} | |
} | |
//iframe | |
$imgs = $dom->getElementsByTagName('iframe'); | |
foreach($imgs as $img){ | |
$attr = $img->getAttribute('class'); | |
if(stripos($attr, 'lazy') === false){ | |
$tmp = $dom->saveHTML($img); | |
$img->setAttribute('class', 'lazy ' . $img->getAttribute('class')); | |
$img->setAttribute('data-src', $img->getAttribute('src')); | |
$img->removeAttribute('src'); | |
$output = str_replace(array($tmp), $dom->saveHTML($img), $output); | |
} | |
} | |
return $output; | |
}); | |
break; | |
case 'OnDocFormPrerender': | |
$script = ' | |
let res = Ext.getCmp("modx-panel-resource"); | |
if(typeof res != "undefined" && res.record.template == 1){ | |
Ext.getCmp("modx-resource-tabs").insert(2, { | |
title: "Блоки страницы", | |
cls: "x-panel-body main-wrapper x-panel-body-noheader", | |
id: "blocks-resource-tab", | |
width: "95%", | |
listeners: { | |
render: function () { | |
MODx.moveTV(["tv2"],"blocks-resource-tab"); | |
var a = Ext.getCmp(\'blocks-resource-tab\'); | |
var myPanel = new Ext.Panel({ | |
title : \'Редактирование текстовых блоков на странице\', | |
frame : true, | |
autoWidth: true, | |
id : \'-vdv-block\', | |
cls: \'x-panel-body main-wrapper x-panel-body-noheader x-panel-body-noborder x-form-label-top\', | |
layout:\'column\', | |
autoLoad: { | |
url: "/assets/components/vdv/home.html", | |
scripts : true | |
}, | |
}) | |
a.insert(1, myPanel); | |
this.doLayout(); | |
} | |
} | |
}); | |
} | |
if(typeof res != "undefined" && res.record.template == 2){ | |
Ext.getCmp("modx-resource-tabs").insert(2, { | |
title: "Блоки страницы", | |
cls: "x-panel-body main-wrapper x-panel-body-noheader x-panel-body-noborder x-form-label-top", | |
id: "blocks-resource-tab", | |
width: "95%", | |
listeners: { | |
render: function () { | |
MODx.moveTV(["tv1"],"blocks-resource-tab"); | |
this.doLayout(); | |
} | |
} | |
}); | |
} | |
if(typeof res != "undefined" && res.record.template == 6){ | |
Ext.getCmp("modx-resource-tabs").insert(2, { | |
title: "Блоки страницы", | |
cls: "x-panel-body main-wrapper x-panel-body-noheader x-panel-body-noborder x-form-label-top", | |
id: "blocks-resource-tab", | |
width: "95%", | |
listeners: { | |
render: function () { | |
MODx.moveTV(["tv3"],"blocks-resource-tab"); | |
this.doLayout(); | |
} | |
} | |
}); | |
} | |
if(typeof res != "undefined" && (res.record.template == 8 || res.record.template == 11)){ | |
Ext.getCmp("modx-resource-tabs").insert(2, { | |
title: "Блоки страницы", | |
cls: "x-panel-body main-wrapper x-panel-body-noheader x-panel-body-noborder x-form-label-top", | |
id: "blocks-resource-tab", | |
width: "95%", | |
listeners: { | |
render: function () { | |
MODx.moveTV(["tv4"],"blocks-resource-tab"); | |
MODx.moveTV(["tv5"],"blocks-resource-tab"); | |
this.doLayout(); | |
} | |
} | |
}); | |
} | |
if(typeof res != "undefined" && (res.record.template == 9 || res.record.template == 10)){ | |
Ext.getCmp("modx-resource-tabs").insert(2, { | |
title: "Блоки страницы", | |
cls: "x-panel-body main-wrapper x-panel-body-noheader x-panel-body-noborder x-form-label-top", | |
id: "blocks-resource-tab", | |
width: "95%", | |
listeners: { | |
render: function () { | |
MODx.moveTV(["tv7"],"blocks-resource-tab"); | |
MODx.moveTV(["tv4"],"blocks-resource-tab"); | |
MODx.moveTV(["tv6"],"blocks-resource-tab"); | |
MODx.moveTV(["tv3"],"blocks-resource-tab"); | |
this.doLayout(); | |
} | |
} | |
}); | |
} | |
'; | |
$modx->controller->addHtml('<script> | |
Ext.ComponentMgr.onAvailable("modx-panel-resource", function (e) { | |
var res = Ext.getCmp("modx-panel-resource"); | |
res.on("success", function(){ | |
var current_tab = Ext.getCmp(\'modx-resource-tabs\').getActiveTab().id; | |
setTimeout(function(){ | |
current_tab_next = Ext.getCmp(\'modx-resource-tabs\').getActiveTab().id; | |
if(current_tab != current_tab_next){ | |
Ext.getCmp(\'modx-resource-tabs\').setActiveTab(current_tab); | |
} | |
}, 150); | |
}); | |
}); | |
MODx.on("ready",function() { | |
' . $script . '; | |
}); | |
</script>'); | |
break; | |
case 'OnMODXInit': | |
case 'OnManagerPageInit': | |
$modx->regClientStartupHTMLBlock("<script>var HTTP_HOST = '".$modx->getOption('http_host')."';var SUCCESS_SUMBIT_URL = '".$modx->makeUrl(4, '', '', 'full')."';</script>"); | |
break; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment