123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116 |
- * @ngdoc function
- * @name domainManagerApp.controller:AboutCtrl
- * @description
- * # AboutCtrl
- * Controller of the domainManagerApp
- */
- angular.module('codexApp.imageView', [])
- .controller('ImageViewCtrl',['$scope', '$rootScope', '$state', 'FileService', function ($scope, $rootScope, $state, FileService) {
- var filesystem = require("fs");
- console.log('-> Image View opened!')
- $scope.note = FileService.getCurrentNote();
- $scope.container = "note-container";
- $scope.image_path = $scope.note.path;
- $scope.fixRelativeURL = function(current_url, relative_url) {
- console.log("-> Fixing URL")
- console.log(" * Relative URL: " + relative_url)
- console.log(" * Note URL: " + current_url)
-
- var current_path = current_url.split('/');
- var relative_path = relative_url.split('/');
-
- current_path.pop();
-
- var count = 0;
- for (var i = 0; i < relative_path.length; i++) {
- if(relative_path[i] == ".."){
- count = count + 1;
- relative_path[i] = "";
- }
- }
-
- relative_path = relative_path.join('/');
-
- for (var i = 0; i < count; i++) {
- current_path.pop();
- }
-
- current_path = current_path.join('/');
-
- if(count == 0){
- var fixed_url = current_path + "/" + relative_path;
- } else {
- var fixed_url = current_path + relative_path;
- }
-
- console.log(" * Fixed URL: " + fixed_url)
- return fixed_url;
- }
- $scope.absoluteToRelativeURL = function(current_url, absolute_url) {
- console.log("-> Converting absolute URL to relative")
- console.log(" * Absolute URL: " + absolute_url)
- console.log(" * Note URL: " + current_url)
-
- var current_path = current_url.split('/');
- var absolute_path = $scope.getUrlParts(absolute_url).pathname.split('/');
-
- current_path.pop();
- current_path.shift();
- absolute_path.shift();
-
- var current_path_count = 0;
- for (var i = 0; i < current_path.length; i++) {
- current_path_count = current_path_count + 1;
- }
-
- var absolute_path_count = 0;
- for (var i = 0; i < absolute_path.length; i++) {
- absolute_path_count = absolute_path_count + 1;
- }
- absolute_path_count = absolute_path_count - 1;
- console.log(" * Cleaned current URL (" + current_path_count + " parts): " + current_path.join('/'))
- console.log(" * Cleaned absolute URL (" + absolute_path_count + " parts): " + absolute_path.join('/'))
- dif = current_path_count - (absolute_path_count -1);
- for (var i = 0; i < absolute_path_count; i++) {
- absolute_path.shift();
- }
- console.log(" * Modified current URL (" + current_path_count + " parts): " + current_path.join('/'))
- console.log(" * Modified absolute URL (" + absolute_path_count + " parts): " + absolute_path.join('/'))
-
- var relative_path = absolute_path.join('/');
- console.log(" * Converted relative URL: " + relative_path)
- return relative_path;
- }
- $scope.getUrlParts = function(url) {
- var a = document.createElement('a');
- a.href = url;
- return {
- href: a.href,
- host: a.host,
- hostname: a.hostname,
- port: a.port,
- pathname: a.pathname,
- protocol: a.protocol,
- hash: a.hash,
- search: a.search
- };
- }
- }]);
|