Requirejs baseurl relative - plugins

I want to set the baseurl to the folder where Require js is in, which is called js. Now I have this funny/ frustrating phenomenon that when I write
require({
baseUrl: './'
});
It sets the baseUrl to the url from which the document is loaded, when I set it to
require({
baseUrl: './js'
});
It sets takes sets it the folder [MyProjectfoder]/js/js/ with the second js being "wrong" of course, since I want it to set it relative from my page... Any idea what I'm doing wrong?
The reason why I need is is, that I want to load plugins like the text or async plugin, which are taken form the baseurl, so if it is not the right director, the plugins can't be found.

Sometimes, when I write URLs, I forget which directory it is pointing to.
Try using:
require({
baseUrl: 'js'
});
I hope it helps. If not, just leave a comment.

Related

DDEV accessing wrong .css-file, different home base the productive system

I'm working on a downloaded productive TYPO3 homepage (v11.5) and set it up in DDEV.
Now during my work I recognised that the base href for inclusion of user-specified .css-files are different from the productive system.
While in the productive system, the .css-file is correctly loaded from
https://mydomain.at/fileadmin/templates/assets/css/mybootstrap2.css?1636470015
it is in the DDEV environment requested from
https://mydomain.ddev.site/sternwarte-mydomain/fileadmin/templates/assets/css/mybootstrap2.css?1674722424
Which obviously added a Typo3 page references (sternwarte-mydomain/) to the path, an therefore correctly resulted in an
net::ERR_ABORTED 404
for the GET-operation as this is the wrong location.
Any hints/suggestions where my error could be.
EDIT:
Extract of the Typoscript.
Resulting sourcecode
EDIT 2:
Site configuration:
Maybe you need to set config.absRefPrefix = / in TypoScript? Or check the entry point of your site configuration.
Update:
Try to set the link to the CSS file with a slash in front, e.g. file1 = /fileadmin/templates/assets/css/mybootstrap2.css. Or try to set config.baseURL = /.

GitHub hosted Jeykll site. Background images within css are not displaying?

I've created a settings.yml within a _data folder. This also contains my baseurl: /run-and-roll.
So I have inserted {{ site.data.settings.baseurl }} in front of my assets. The css file is loading along with images that are defined in the html. However, any background images requested in the css are not showing?
https://granttransition.github.io/run-and-roll/
Every configuration variable that appears in https://jekyllrb.com/docs/configuration/ makes sense to keep them there.
Usually templates preppend the base url when generating some urls like the ones of the assets, using {{site.baseurl}}, so if you manually sets it from another location it won't be used by default.
What you have read that is a good practice to have settings and config separate is for every other configuration not related exactly with jekyll built-in variables, that it is a good practice to put them on data files, so you keep your _conf.yml as clear as possible as the official docs suggests, that makes easier to maintain and update your Jekyll instance:
In addition to the built-in variables available from Jekyll, you can
specify your own custom data that can be accessed via the Liquid
templating system.
Jekyll supports loading data from YAML, JSON, and CSV files located in
the _data directory. Note that CSV files must contain a header row.
This powerful feature allows you to avoid repetition in your templates
and to set site specific options without changing _config.yml.
Plugins/themes can also leverage Data Files to set configuration
variables.
TL;DR
just put baseurl in _config.yml as suggested in other answers :)
b/c if you are using Jekyll with Github Page, then if site.url or site.baseurl are not specified, in a CNAME or config.yml, for the production build. then they will be set automatically by github page generator
Explanation
from github page generator code-source:
# Set `site.url` and `site.baseurl` if unset and in production mode.
def set_url_and_baseurl_fallbacks!
return unless Jekyll.env == "production"
repo = drop.send(:repository)
site.config["url"] ||= repo.url_without_path
if site.config["baseurl"].to_s.empty? && !["", "/"].include?(repo.baseurl)
site.config["baseurl"] = repo.baseurl
end
end
the default build environment for jekyll, is development. So while, working on your site locally. every thing will run just as you expect. even when putting baseurl in other location than _config.yml
but in github page side, the web site is built with this command:
JEKYLL_ENV=production jekyll build
and site.url and site.baseurl are overridden.
in your case, if you're using {{ site.data.settings.baseurl }} to access some page, and it's set to a value like ('' or '/') you may not notice a navigation issue. bat assets path for css and js will not work as expected.
So, just put baseurl in the _config.yml, refactor your layout and pages accordingly. and you'll be fine.
a side note: as mentioned in #David answer, it's the jekyll convention to put website setting. in _config.yml, but if you want to put them in other place, you can. just make sure, to declare them for the production build as will.
see also: Clearing Up Confusion Around baseurl -- Again
UPDATE
even after moving the website to a github project repo: /<user-name>.github.io/<repo-name> instead of user (or organization) repo: /<user-name>.github.io. you need to set as follows:
site.baseurl: ''
or just remove it. since you serve your website from the main repository (cf. above refence)
Use of {{ site.baseurl }} is a jekyll convention, moving it to a data file is not a good idea.
Nevertheless from your css standpoint, path to runner.jpg will always be ../assets/img/runner.jpg. No need to use baseurl.

onSubmit event is not fired in React.js form

My React based app contains a form and somewhere along the way it stopped working, the onSubmit even was no longer fired and the form was just simply submitted with a new http request. While trying to isolate the problem I stripped my whole app to the following snippet (which is actually this jsfiddle taken from another question):
import React from 'react'
var OnSubmitTest = React.createClass({
render: function () {
var doSomething = function () {
alert('it works!');
}
return <form onSubmit={doSomething}>
<button>Click me</button>
</form>;
}
});
React.render(<OnSubmitTest/>, document.body);
The script on jsfiddle works as it should: the message is alerted just before the form is actually submitted. I get no alert in my app, though.
If I add e.preventDefault() the jsfiddle form is not submitted at all, my form is.
The difference is that I build my app using webpack and babel from es6 but it's hard to believe that this could have any impact on this matter.
Any idea what might be the reason? What should I try next to debug that?
Update: JSFiddle showing the problem. The linked file is the webpack output (not uglified in any way to keep it readable, that's why it's so huge). You can find my code (compiled) starting on the line 53.
Mystery solved: I forgot to mark the node_modules directory as excluded (I use IntelliJ IDEA) so when I used refactoring to change some variable name form to something else, the IDE eagerly refactored the whole React and replaced all occurrences of form with the new value.
I fixed it by reinstalling all npm dependencies.

Fuelphp remove public from base_url

I ran in to a problem what icant really solve with fuel php.
I added the htaccess to te root, now i can acces my site like this www.mysite.com/wlecome, se the public is removed, but i cant find a way to remove the public when i use the Config::get('base_url'); and the Response::redirect();
The base_url in the config.php is set to null, if i pass the site url to it, that way the assets are not rendering correctly.
I would really appreciate if someone could give me a hint how to remove the public from these.
Thank you.
This sounds like you've installed the complete FuelPHP installation INSIDE the docroot, instead of outside, and making the public folder your docroot, which is the recommended way of installation.
If this is the case, move everything in the public directory one folder up, so it's in the docroot again, and remove the public folder, which is no longer needed.
Note that a setup like this leaves your code accessible via the browser, so you might want to add some htaccess to prevent that.
I know its not the prettiest but i usually do this way.
I open up Config.php
and pass under base url
'site_url' => 'your site url here',
and you cann call it this way Config::get('site_url');
Hope it helps you
Instead of using a .htaccess you can set a VirtualHost to go from http://project.dev/ to /var/www/project/public

zend headScript()->appendFile in IE (internet explorer)

Two lines of script
$this->headScript()->appendFile('/js/global.js', 'text/javascript');
$this->headScript()->appendFile('http://zendbase/js/global.js', 'text/javascript');
Firefox runs script by both ways(absolute, root relative)
Internet Explorer only run the Second method of append(absolute), which is with http. which is not a good way.
when I view source in browser I can see following line is added
<script type="text/javascript" src="/js/global.js"></script>
But browser is not reading. it is really beyond my understanding. It is strange. How can I make first line to work with document root path on all browsers including IE.
Is there any settings in view helper? or something else?
I can use $_Server variables to make it absolute dynamically but i don't want to use absolute path.
Any Idea. Thanks in advance :)
Relative paths for scripts will definitely work with IE - I have used it numerous times... What is the hostname you are using (e.g. www.example.com)? Your second line of code should not work, because you don't have a valid hostname - http://zendbase won't resolve to anything. Is zendbase a variable?
For relative static assets (images, JS, CSS, SWF, etc), you should always use the baseUrl helper, eg
$this->headScript()
->appendFile($this->baseUrl('/js/global.js'));
If you can see the correct <script> tag in source, then the problem is either the path is incorrect (see baseUrl helper above) or your JavaScript contains errors.
Finally I fixed the problem
I removed the baseUrl(); ?>" /> from layout.phtml
and added following line in application.ini
resources.frontController.baseUrl = ""