Jeg beklager jeg ikke formår at forklare mig bedre, men tak for svarende!
Det jeg har på min side, er at alle mine sider bliver dynmisk hentet. I stedet for at jeg trykker på
<a href="om-os.php">Om os</a> hvor den derefter sender mig til en ny side, bliver blot min div med <div id="load"></div> henter min side ned, men jeg har funktioner i om-os.php som jeg ikke kan bruge uden at skulle inkludere .js filen der sørger for at når jeg klikker på <a href="om-os.php">Om os</a>at diven med id="load" henter siden.
Min .js fil ser sådan ud. Jeg inkludere den i hovede siden og i de sider der dynamisk bliver hentet for at gøre brug af dens funktioner, men problemet er at den dublere alt indholdet, som fx en load_data() funktionen
- $("a").click(function(){
- if ($(this).attr( "div" )) {
- divload = ($(this).attr( "div" ));
- }else{
- divload = '#page-load';
- }
- if ($(this).attr( "element" )) {
- divload = $(this).attr( "element" );
- }
-
- var current_url = location.href.split("/").pop();
- if ($(this).attr( "load" )) {
-
-
- url = $(this).attr( "load" );
- if(url != current_url){
-
- history.pushState(null, null, url);
- urlfix = document.URL.replace(documenturl,'');
-
- if( url.indexOf('?') >= 0){
-
- str_link_url = "?" + url.substring(url.indexOf("?") + 1);
- str_link_url = str_link_url + "&"
- url = url.substring(0, url.indexOf('?'));
-
- finalurl = urlfix.substring(0, urlfix.indexOf('?'));
- }else{
- str_link_url = '?';
- finalurl = urlfix;
- }
-
- $(divload).html('<center><img src="/websites/iblogging/assets/images/load.gif"></center>');
- $(divload).load('/engine/index.php' + str_link_url + 'function=content/' + finalurl);;
- }
- }
- });
-
- jQuery(document).ready(function($) {
- if (window.history && window.history.pushState) {
- $(window).on('popstate', function() {
- if( website_url.indexOf('?') >= 0){
- str_the_url = "?" + document.URL.substring(document.URL.indexOf("?") + 1);
- str_the_url = str_the_url + "&";
- }else{
- str_the_url = '?';
- }
- //$('#page-load').html('<center><img src="/websites/iblogging/assets/images/load.gif"></center>');
- $('#page-load').load('/engine/index.php' + str_the_url + 'function=content/' + newurl);
- });
- }
- });
-
-
- /* Register form */
- $('.submit-register').click(function(e){
- var form_id = $(this).closest("form").attr("id");
- var success = $(this).closest("form").attr("success");
- var fullurl = "/engine/index.php?function=data-handler&action=register";
-
- $.ajax({
- type: "POST",
- url: fullurl,
- data: $("#" + form_id).serialize(),
- success: function(data)
- {
- $(".result").show();
- $(".result").html(data);
- $(".result").each(function () {
- if ($(this).text() == "1") { // 1 one is standard success
- window.location.replace(success);
- } });
-
- }
- });
- return false;
- });
-
-
- /* Login form */
- $('.submit-login').click(function(e){
-
- var form_id = $(this).closest("form").attr("id");
- var success = $(this).closest("form").attr("success");
- var fullurl = "/engine/index.php?function=engine/data-handler&action=login";
-
- $.ajax({
- type: "POST",
- url: fullurl,
- data: $("#" + form_id).serialize(),
- success: function(data)
- {
- $(".result").show();
- $(".result").html(data);
- $(".result").each(function () {
- if ($(this).text() == "1") { // 1 one is standard success
- window.location.replace(success);
- } });
-
- }
- });
- return false;
- });
-
- function load_new_url(divload, url){
-
-
- var current_url = location.href.split("/").pop();
-
- if(url != current_url){
-
- history.pushState(null, null, url);
- urlfix = document.URL.replace(documenturl,'');
-
- if( url.indexOf('?') >= 0){
-
- str_link_url = "?" + url.substring(url.indexOf("?") + 1);
- str_link_url = str_link_url + "&"
- url = url.substring(0, url.indexOf('?'));
-
- finalurl = urlfix.substring(0, urlfix.indexOf('?'));
- }else{
- str_link_url = '?';
- finalurl = urlfix;
- }
-
-
-
- //$(divload).html('<center><img src="/websites/iblogging/assets/images/load.gif"></center>');
- $(divload).load('/engine/index.php' + str_link_url + 'function=content/' + finalurl);
-
- }
- }
- function load_data(divload, url, action){
-
- window.website_url = document.URL;
- if( website_url.indexOf('?') >= 0){
- str_the_url = "?" + document.URL.substring(document.URL.indexOf("?") + 1);
- str_the_url = str_the_url + "&";
- }else{
- str_the_url = '?';
- }
- $(document).ready(function() {
- $(divload).load('/engine/index.php' + str_the_url + 'function=content/' + url + '&action=' + action);
- });
- }
-
- /* Form actions, when updating & insert */
-
- $('.submit').click(function(e){
-
-
- var form_id = $(this).closest("form").attr("id");
- var url = $(this).closest("form").attr("url");
- var urlid = $(this).closest("form").attr("urlid");
- var action = $(this).closest("form").attr("action");
- var website = $(this).closest("form").attr("website");
- var the_do = $(this).closest("form").attr("do");
- var result = $(this).closest(".result");
- var fullurl = "/engine/index.php?function=engine/iblogging/_actions.class&id=" + urlid + "&action=" + action;
-
-
- $.ajax({
- type: "POST",
- url: fullurl,
- data: $("#" + form_id).serialize(),
- success: function(data)
- {
- $(".result").show();
- $(".result").html(data);
- }
- });
- return false;
- });
Indlæg senest redigeret d. 02.09.2014 18:52 af Bruger #17509